var IsPhotoOut = false;
var IsMSIE = false;
var mouseX, mouseY;
var IsZoomOut = false;

if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
	IsMSIE = true;
}


function getMousePosInPhoto(evt){

	var ua = navigator.userAgent.toLowerCase();
	isIE = (ua.indexOf("msie") != -1);
	isFirefox = (ua.indexOf("firefox") != -1);
	isOpera = (ua.indexOf("opera") != -1);
	isGecko = (ua.indexOf("gecko") != -1);
	isSafari = (ua.indexOf("safari") != -1);
	isKonqueror = (ua.indexOf("konqueror") != -1);
	

	if (!evt){var evt = window.event||window.Event;}

	var img_x;
	var img_y;

	if('number' == typeof evt.offsetX) {
		img_x = evt.offsetX;
		img_y = evt.offsetY;
	}
	else {
		img_x = evt.clientX;
		img_y = evt.clientY;
	}
	


	if(isIE == true || isFirefox == true){
		for (var offMark = evt.target; offMark;offMark = offMark.offsetParent) {
			img_x -= offMark.offsetLeft;
		}
		for (var offMark = evt.target; offMark;offMark = offMark.offsetParent) {
			img_y -= offMark.offsetTop;
		}
	}

	img_x = img_x + document.body.scrollLeft;
	img_y = img_y + document.body.scrollTop;
	


	if(IsZoomOut == true){
		PosicionaZoom(img_x, img_y);
	}
	
}


function SubeAlpha(opacity, IDObjeto) {
	
	var object = document.getElementById(IDObjeto).style;
	var FFOpac;
	var Velocidad = 4;
	
	object.visibility = 'visible';
	opacity = opacity + Velocidad;
	


	if(opacity < (100 + Velocidad)){
		
		if (document.getElementById(IDObjeto)){
			
			FFOpac = opacity / 100;
			
			document.getElementById(IDObjeto).style.opacity = FFOpac;
			document.getElementById(IDObjeto).style.filter = 'alpha(opacity=' + opacity + ')';
			
		}
		
		setTimeout('SubeAlpha('+opacity+', "'+IDObjeto+'");',10);
	}

}


function BajaAlpha(opacity, IDObjeto) {
	
	var object = document.getElementById(IDObjeto).style;
	var FFOpac;
	var Velocidad = 8;
	
	object.visibility = 'visible';
	opacity = opacity - Velocidad;
	


	if(opacity > Velocidad){
		
		if (document.getElementById(IDObjeto)){
			
			FFOpac = opacity / 100;
			
			document.getElementById(IDObjeto).style.opacity = FFOpac;
			document.getElementById(IDObjeto).style.filter = 'alpha(opacity=' + opacity + ')';
			
		}
		
		setTimeout('BajaAlpha('+opacity+', "'+IDObjeto+'");',10);
	}
	else{
		if(opacity > 0){
			object.visibility = 'hidden';
		}
	}

}


function PosicionaZoom(Mx, My){

	var ZoomObj = document.getElementById("ZoomPhotoDiv");
	var ZoomObjImg = document.getElementById("ZoomPhoto");
	
	if(ZoomObj){
		//Saco la proporción entre la imagen grande y la pequeña

		var OrgObj = document.getElementById("ImgGall");
		var OWidth = OrgObj.width;
		var OHeight = OrgObj.height;

		var ZWidth = ZoomObjImg.width;
		var ZHeight = ZoomObjImg.height;
		
		var PorX = ZWidth / OWidth;
		var PorY = ZHeight / OHeight;
		
		var Zx = Mx * PorX;
		var Zy = My * PorY;
			
		
		var DivWidth = ZoomObj.style.width;
		DivWidth = DivWidth.substring(0, (DivWidth.length - 2));

		var DivHeight = ZoomObj.style.height;
		DivHeight = DivHeight.substring(0, (DivHeight.length - 2));
		
		ZoomObjImg.style.position = "absolute";
		ZoomObjImg.style.left = (-1* Zx) + (DivWidth / 2);
		ZoomObjImg.style.top = (-1* Zy) + (DivHeight / 2);
		
	}

}


function SacaZoom(visible, ImageSrc, evt){

	
	var ZoomObj = document.getElementById("ZoomPhotoDiv");
	
	if(visible == true){
		if(ZoomObj.style.visibility != "visible"){SubeAlpha(0,"ZoomPhotoDiv");}
		IsZoomOut = true;
		getMousePosInPhoto(evt);
	}
	else{
		if(ZoomObj.style.visibility != "hidden"){BajaAlpha(100, "ZoomPhotoDiv");}
		IsZoomOut = false;
	}
	
}

if(window.Event && document.captureEvents)
document.captureEvents(Event.MOUSEMOVE);

document.onmousemove = getMousePos;

function getMousePos(e){
	if (!e)
	var e = window.event||window.Event;

	if('undefined'!=typeof e.pageX){
		mouseX = e.pageX-20;
		mouseY = e.pageY-20;
	}
	else{
		mouseX = e.clientX + document.body.scrollLeft;
		mouseY = e.clientY + document.body.scrollTop;
	}

	if(IsPhotoOut){
		PosicionaFoto();
	}

}


if(window.Event && document.captureEvents)
document.captureEvents(Event.MOUSEMOVE);

document.onmousemove = getMousePos;

function SacaFoto(IMGFile, Texto){

	if(!IsPhotoOut){
		
		var InHTML = '<body topmargin="0" leftmargin="0"><table border="0" cellpadding="0" cellspacing="0" width="90%" align="center"><tr><td height="20"></td></tr><tr><td align="center">';
		InHTML = InHTML + '<img src="'+ IMGFile +'"></td></tr><tr><td><br><p><font face="Verdana" size="1" color="#000000"><b>';
		InHTML = InHTML + Texto +'</font></p></b></td></tr></table></body>';

		document.getElementById('photo_div').style.visibility = "visible";
		if(!IsMSIE){
			document.getElementById('photo_div').innerHTML = InHTML;
		}
		else{
			document.getElementById('frame_photo').style.visibility = "visible";
			document.frames.frame_photo.document.body.innerHTML = InHTML;
		}

		PosicionaFoto();
		IsPhotoOut = true;

	}

}


function MeteFoto(){
	document.getElementById('photo_div').style.visibility = "hidden";
	if(IsMSIE){
	document.getElementById('frame_photo').style.visibility = "hidden";
	}
	IsPhotoOut = false;
}


function PosicionaFoto(){

	var PosX;
	var PosY;
	
	var Margen = 40;
	
	if(IsMSIE){
		if(mouseY <= (screen.height / 2)){PosY = mouseY;}
		else{PosY = mouseY - 350;}

		if(mouseX <= (screen.width / 2)){PosX = mouseX + Margen + document.body.scrollLeft;}
		else{PosX = mouseX - 350 - Margen + document.body.scrollLeft;}
	}
	else{

		PosY = mouseY;
		if(mouseX <= (screen.width / 2)){PosX = mouseX + Margen + document.body.scrollLeft;}
		else{PosX = mouseX - 350 - Margen + document.body.scrollLeft;}
	}

	document.getElementById('photo_div').style.top = PosY;
	document.getElementById('photo_div').style.left = PosX;
	
}

function RedirToGall(Group){
	document.getElementById("redirect" + Group).submit();
}


function ModoProf(){
	document.getElementById("cTd").style.paddingRight="17px";
	document.getElementById("cTd").style.paddingTop="0px";
	document.getElementById("cTd").style.width="580px";



}

function ModoHome(){
	document.getElementById("cTd").style.paddingLeft="40px";
	document.getElementById("cTd").style.paddingRight="40px";
	document.getElementById("cTd").style.paddingTop="0px";
	document.getElementById("mTd").style.width="240px";

}
function ModoHome2(){
	document.getElementById("cTd").style.paddingLeft="0px";
	document.getElementById("cTd").style.paddingRight="0px";
	document.getElementById("cTd").style.paddingTop="0px";
	document.getElementById("mTd").style.width="240px";

}


function Redirect(newURL){
	
	document.location=newURL;
}

function DownloadFile(FileName, Path){
	
	var PathRoute = '';

	if(Path !=''){
		PathRoute = '&fp='+Path;
	}	
	document.location = "../inicio/?acc=home&fl="+FileName+PathRoute;
}

function DownloadFileMsg(FileName, Path){
	var PathRoute = '';
        var cMensaje = "¡ADVERTENCIA!, las imágenes descargables que "+
                       "mostramos a continuación, son propiedad de tuc tuc world S.L. usted puede "+
                       "utilizarlas bajo las siguientes premisas.\n\r"+
                       "1.- el periodo para la utilización de las imágenes es durante la temporada "+
                       "actual hasta la finalización del periodo de rebajas.\n\r"+
                       "2.- el soporte sobre el cual debe ser impreso estas imágenes son carteles "+
                       "publicitarios en el interior de su establecimiento, la utilización en "+
                       "cualquier otro soporte sin premiso expreso incurre en una ilegalidad. Si "+
                       "usted desea hacer uso de imágenes de tuctuc en cualquier otro soporte, "+
                       "póngase en contacto con la oficina comercial.\n\r\n\r"+
                       "Botón Aceptar: Acepto las condiciones de uso anteriormente descritas\n\r"+
                       "Botón Cancelar: No acepto las condiciones de uso anteriormente descritas";
	if(Path !=''){
		PathRoute = '&fp='+Path;
	}	

        var lDescargar = window.confirm(cMensaje);
        if (lDescargar) {
         document.location = "../inicio/?acc=home&fl="+FileName+PathRoute;
        }
}


