var EE_GALLERY_TOP=0;
var EE_GALLERY_LEFT=0;
var EE_GALLERY_WIDTH=500;
var EE_GALLERY_HEIGHT=86;
var EE_GALLERY_PIC_HEIGHT=50;
var EE_GALLERY_MENULINE_HEIGHT=60;

var IE=(navigator.appName=="Microsoft Internet Explorer")?true:false;

function setupGallery() {
	galleryContainer=document.createElement('div');
	galleryContainer.setAttribute('id','ee_gallery_container');
	galleryContainer.style.left=(document.body.clientWidth/2-EE_GALLERY_WIDTH/2)+"px";
	galleryContainer.style.top=(EE_GALLERY_TOP+10)+"px";
	galleryContainer.style.width=EE_GALLERY_WIDTH+"px";
	galleryContainer.style.height=EE_GALLERY_HEIGHT+"px";
	document.body.appendChild(galleryContainer);
	
	galleryTable=document.createElement('table');
	galleryTable.setAttribute('id','ee_gallery_table');
	galleryTable.setAttribute('height',EE_GALLERY_HEIGHT);
	galleryContainer.appendChild(galleryTable);
	
	gBody=document.createElement('tbody');
	galleryTable.appendChild(gBody);
	
	tr=document.createElement('tr');
	tr.setAttribute('valign','middle');
	gBody.appendChild(tr);
	
	galleryTable.style.width=0;
	for(i=0;i<boxElements.length;i++) {
		td=document.createElement('td');
		tr.appendChild(td);
		imgdiv=document.createElement('div');
		imgdiv.innerHTML="<a href='"+boxElements[i]+"'><img border='0' src='"+boxElements[i]+"'></a>";
		imgdiv.childNodes[0].onclick=show;
		imgdiv.childNodes[0].childNodes[0].height=EE_GALLERY_PIC_HEIGHT;
		galleryTable.rows[0].cells[i].appendChild(imgdiv);
		imgdiv.style.width=(imgdiv.childNodes[0].childNodes[0].width+5)+"px";
		td.style.left=parseInt(galleryTable.style.width)+"px";
		galleryTable.style.width=(parseInt(galleryTable.style.width)+parseInt(imgdiv.style.width)+6)+"px";
	}
	
	if(parseInt(galleryContainer.style.width)<parseInt(galleryTable.style.width)) {
		galleryContainer.onmousemove=mouseMoved;
		galleryContainer.onmouseenter=mouseEntered;
	}
	else
		autoUpdateSmallGallery();

	galleryTable.style.left=(parseInt(galleryContainer.style.width)/2-parseInt(galleryTable.style.width)/2)+"px";
	setTimeout(function() { 
		updateGallery(0);
		fade=new FadeEvent(JSA,document.getElementById("ee_gallery_container"),0,1.0,400); 
		JSA.addAnimation(fade);
	},1000);
}

function mouseMoved(e) {
	if(!e) e=window.event;
	if(IE)
		e.source=e.srcElement;
	else
		e.source=e.target;
	
	updateGallery(e.clientX);
}

function mouseEntered(e) {
	if(!e) e=window.event;
	if(IE)
		e.source=e.srcElement;
	else
		e.source=e.target;
		
	updateGallery(e.clientX);
}

function updateGallery(clientX) {
	galleryContainer=document.getElementById('ee_gallery_container');
	galleryTable=document.getElementById('ee_gallery_table');
	
	posPercent=(clientX-parseInt(galleryContainer.style.left))/parseInt(galleryContainer.style.width);
	offset=parseInt(galleryTable.style.width)*posPercent;
	
	galleryLeft=parseInt(galleryContainer.style.width)/2-offset;
	galleryLeft=galleryLeft>0?0:galleryLeft;
	galleryCenter=parseInt(galleryContainer.style.width);
	galleryLeft=(galleryLeft<galleryCenter-parseInt(galleryTable.style.width))?galleryCenter-parseInt(galleryTable.style.width):galleryLeft;
	galleryTable.style.left=parseInt(galleryLeft)+"px";
	
	enlargeWidth=parseInt(galleryContainer.style.width)/2;
	enlargeCenter=clientX-parseInt(galleryContainer.style.left);
	enlargeStart=enlargeCenter-parseInt(galleryContainer.style.width)/2;
	enlargeEnd=enlargeCenter+parseInt(galleryContainer.style.width)/2;
	
	galleryWidth=0;
	
	for(i=0;i<galleryTable.rows[0].cells.length;i++) {
		imgLeft=parseInt(galleryTable.rows[0].cells[i].style.left)+parseInt(galleryTable.rows[0].cells[i].childNodes[0].style.width)/2+parseInt(galleryTable.style.left);
		if(imgLeft>enlargeStart && imgLeft<enlargeEnd) {
			amountPercent=1-Math.abs(imgLeft-enlargeCenter)/enlargeCenter;
			if(amountPercent<0)
				amountPercent=0;
			maxAmount=30;
			img=galleryTable.rows[0].cells[i].childNodes[0].childNodes[0].childNodes[0];
			imgdiv=galleryTable.rows[0].cells[i].childNodes[0].childNodes[0];
			img.height=EE_GALLERY_PIC_HEIGHT+amountPercent*maxAmount;
			galleryTable.rows[0].cells[i].childNodes[0].style.width=(img.width+6)+"px";
			galleryTable.rows[0].cells[i].style.left=(i==0?0:parseInt(galleryTable.rows[0].cells[i-1].style.left)+parseInt(galleryTable.rows[0].cells[i-1].childNodes[0].style.width))+"px";
		}
		else {
			img=galleryTable.rows[0].cells[i].childNodes[0].childNodes[0].childNodes[0];
			img.height=EE_GALLERY_PIC_HEIGHT;
			galleryTable.rows[0].cells[i].childNodes[0].style.width=(img.width+6)+"px";
			galleryTable.rows[0].cells[i].style.left=(i==0?0:parseInt(galleryTable.rows[0].cells[i-1].style.left)+parseInt(galleryTable.rows[0].cells[i-1].childNodes[0].style.width))+"px";
		}
		img=galleryTable.rows[0].cells[i].childNodes[0].childNodes[0].childNodes[0];
		galleryWidth+=img.width+12;
	}
	galleryTable.style.width=galleryWidth+"px"; 
}

function autoUpdateSmallGallery() {
	galleryContainer=document.getElementById('ee_gallery_container');
	galleryTable=document.getElementById('ee_gallery_table');
	if(galleryTable) {
		galleryTable.style.width=0;
		for(i=0;i<boxElements.length;i++) {
			td=galleryTable.rows[0].cells[i];
			imgdiv=td.childNodes[0];
			imgdiv.style.width=imgdiv.childNodes[0].childNodes[0].width+5;
			td.style.left=parseInt(galleryTable.style.width);
			galleryTable.style.width=parseInt(galleryTable.style.width)+parseInt(imgdiv.style.width)+6;
		}
		galleryTable.style.left=parseInt(galleryContainer.style.width)/2-parseInt(galleryTable.style.width)/2;
	}
	JSA.setTimeout(autoUpdateSmallGallery,20);
}




