//  JavaScript Document @Coretomic 2008 max@coretomic.com

function ApeerImage(curent_img, old_img, op){
		op+=2;
		curent_img.style.opacity = op/100;
		curent_img.style.filter = 'alpha(opacity='+op+')';
		if(op == 100){
				if(old_img){
					try{
						old_img.removeNode(true);
					}catch(e){
						if (old_img.parentNode)
							old_img.parentNode.removeChild(old_img);			
					}
					
				}
				Gallery.lock = false;
		}else 
			window.setTimeout(function(){ApeerImage(curent_img, old_img, op)},10);
}


Gallery = {
	template : '<table width="250" border="0" cellpadding="0" cellspacing="0">'+
 ' <tr>'+
 '   <td width="250" valign="top" class="picture"><div id="big_picture" class="show-picture"></div></td>'+
 ' </tr>'+
 ' <tr>'+
 '   <td valign="middle" class="move"><div style="position: relative; overflow:hidden; white-space: nowrap; width:250px; height:100px; "><div id="move" style="position:absolute"></div></div></td>'+
 ' </tr>'+
'</table>',
	move_obj : null,
	target_obj: null,
	gal_debug: null,
	active_pics: [],
	current_activ_index : 0,
	next_left: 0,
	next_right: 0,
	lock: false,

CreateImageObject : function(src,thumb){
		var img = document.createElement('IMG');

		img.src = thumb;
		img.width = 76;
		img.height = 56;
		img.style.opacity = 0.5;
		img.style.filter = 'alpha(opacity=50)';
		var big_img = document.createElement('IMG');
		big_img.src = src;
		img.big_img = big_img;
		img.index = this.next_right;
		img.onclick = function(){Gallery.ShowBigPicture(img);};
		return img;
	},

init : function (objname){
		document.getElementById(objname).innerHTML = this.template;
		this.next_left = pics.length - 1;
		this.next_right = 0;
		this.move_obj = document.getElementById('move');
		this.target_obj = document.getElementById('big_picture');
		this.gal_debug = document.getElementById('gal_debug');
		for(var i = 0; i < Math.min(3, pics.length); i++){
			this.active_pics[i] = this.CreateImageObject(pics[i],thumbs[i]);	
			this.next_right++;
			this.move_obj.appendChild(this.active_pics[i]); 
		}
		this.active_pics[Math.min(2, pics.length-1)].style.marginRight = '0px';
		this.ShowBigPicture(this.active_pics[0]);
	},

ShowBigPicture : function (img){
		if(Gallery.lock)return;
		Gallery.lock = true;
		this.current_activ_index = img.index;
		this.BlinkActivePicture(img);
		var n_img = img.big_img.cloneNode(true);
		var old_img = this.target_obj.firstChild;
		n_img.width = 248;
		n_img.height = 183;
		n_img.hspace = 0;
		n_img.onclick = '';
		n_img.style.position = 'absolute';
		n_img.style.opacity = 0.01;
		n_img.style.filter = 'alpha(opacity=1)';
		this.target_obj.appendChild(n_img,this.target_obj.firstChild);
		ApeerImage(n_img,old_img,0);
	},

BlinkActivePicture : function (img){
		img.style.opacity = 1;
		img.style.filter = 'alpha(opacity=100)';
		for(var i = 0; i< Math.min(3, pics.length); i++)
			if(this.active_pics[i] != img){
				this.active_pics[i].style.opacity = 0.5;
				this.active_pics[i].style.filter = 'alpha(opacity=50)';
			}
	}

};
