// JavaScript Document
//Cambia la posicion del menu que selecciona la galería a ver en el gallery.hp
var IE = document.all?true:false;
if (!IE) {
	document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = moveGalleryMenu;
var tempX = 0;
var tempY = 0;
var overBottomDiv = 0;
function moveGalleryMenu(e) {
	if (IE) {
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	} else {
		tempX = e.pageX;
		tempY = e.pageY;
	}  
	if (tempX < 0){
		tempX = 0;
	}
	if (tempY < 0){
		tempY = 0;
	}  
	
	//Averigua el tamaño de la pantalla
	if(overBottomDiv==1){
		var userScreen = document.getElementById('backDiv');
		var userWidth = Math.floor(parseFloat(userScreen.clientWidth));
		var userHeight = Math.floor(parseFloat(userScreen.clientHeight));
		var currentUniteWidth = userWidth/1440;
		var currentUniteHeight = userHeight/800;
		if(currentUniteWidth > currentUniteHeight){
			var currentUnite = currentUniteHeight;
		}else{
			var currentUnite = currentUniteWidth;
		}
		
		var widthScreen = parseFloat(document.getElementById('galleryPreview').clientWidth)-30;
		var widthMenu = parseFloat(document.getElementById('galleryPreviewContainer').clientWidth);
		if(widthMenu>widthScreen){
			var newWidth = Math.floor(350 * currentUnite);
			if(newWidth<250){newWidth=250;}
			var currentClientLeft = newWidth + 40;
			var widthExtra = widthMenu - widthScreen;
			var widthPercent = Math.floor(parseFloat((tempX - currentClientLeft) * 100 / widthScreen));
			var currentAdd = Math.floor(parseFloat(widthPercent / 100));
			var currentLeftPosition = Math.floor(parseFloat(widthExtra * widthPercent / 100)) + currentAdd;
			if(currentLeftPosition>widthExtra){currentLeftPosition=widthExtra;}
			currentLeftPosition = (currentLeftPosition * -1) +"px";
			document.getElementById("galleryPreviewTable").style.left = currentLeftPosition;
		}
	}
	if(overBottomDiv==2){
		var userScreen = document.getElementById('backDiv');
		var userWidth = Math.floor(parseFloat(userScreen.clientWidth));
		var userHeight = Math.floor(parseFloat(userScreen.clientHeight));
		var currentUniteWidth = userWidth/1440;
		var currentUniteHeight = userHeight/800;
		if(currentUniteWidth > currentUniteHeight){
			var currentUnite = currentUniteHeight;
		}else{
			var currentUnite = currentUniteWidth;
		}
		
		var widthScreen = parseFloat(document.getElementById('galleryPreview').clientWidth);
		var widthMenu = parseFloat(document.getElementById('thumbImage').clientWidth);
		if(widthMenu>widthScreen+30){
			var newWidth = Math.floor(350 * currentUnite);
			if(newWidth<250){newWidth=250;}
			var currentClientLeft = newWidth + 40;
			var widthExtra = widthMenu - widthScreen;
			var widthPercent = Math.floor(parseFloat((tempX - currentClientLeft) * 100 / widthScreen));
			var currentAdd = Math.floor(parseFloat(widthPercent / 100));
			var currentLeftPosition = Math.floor(parseFloat(widthExtra * widthPercent / 100)) + currentAdd;
			if(currentLeftPosition>widthExtra){currentLeftPosition=widthExtra;}
			currentLeftPosition = (currentLeftPosition * -1) +"px";
			document.getElementById("thumbDivContainer").style.left = currentLeftPosition;
			
		}
	}
	return true
}
