d=document;
w = window.innerWidth;
cen = w / 2;
//function noError(){return true;}
//window.onerror = noError;
var xmlHttp = new XMLHttpRequest();
function E(x){return d.getElementById(x);}
function T(x){return d.getElementsByTagName(x)}
function C(x){var t=new Array();var t=T('*');var tn=new Array();for(i=0;i<t.length;i++){if(t[i].className==x){tn=tn.concat(t[i]);}}return tn}
function I(){
	fls = C('false');
	for( i=0 ; i < fls.length ; i++ ){
		fls[i].onclick = FLS;
	}
	thumbnail = C('thumbnail');
	for( i=0 ; i < thumbnail.length ; i++ ){
		thumbnail[i].onclick = lightBox;
		thumbnail[i].onmouseover = AgrandaImagen;
	}
	return false;
}
function lightBox(){
	var url = '/detalles_ajax.php?p=' + this.id;
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = loadLightBox;
	xmlHttp.send(null);
}
function loadLightBox(){
	if(xmlHttp.readyState == 4){
		var fondo = document.createElement("div");
		fondo.setAttribute('id' , 'fondo' );
		fondo.id = 'fondo';
		E('body').appendChild( fondo );
		var response = xmlHttp.responseText;
		var LB = document.createElement("div");
		LB.setAttribute('id' , 'detalles' );
		//LB.id = 'detalles';
		LB.innerHTML = response;
		E('body').appendChild( LB );
		cerr = C('cerrar');
		for( i=0 ; i < cerr.length ; i++ ){
			cerr[i].onclick = cerrar;
		}
		document.onclick = cerrar;
		thDet = C('th-det');
		for( i=0 ; i < thDet.length ; i++ ){
			thDet[i].onmouseover = AgrandaImagen;
		}
	}
}
function cerrar(){
	E('body').removeChild( E('fondo') );
	E('body').removeChild( E('detalles') );
}
function AgrandaImagen( event ){
	x = this.src;
	x = x.match(/\d+\..+/);
	var grnd = document.createElement("img");
	grnd.setAttribute('id' , 'grnd' );
	grnd.setAttribute('src' , '/large/' + x );
	grnd.style.border = 'solid';
	grnd.style.position = 'fixed';
	grnd.style.zIndex = '999';
	if(IE()){
		this.attachEvent("onmouseout", imgDes);
		document.attachEvent("onmousemove", imgPos);
	}else{
		this.addEventListener("mouseout", imgDes , true);
		document.addEventListener("mousemove", imgPos , true);
	}
	E('body').appendChild( grnd );
}
function imgDes(){
	if(IE()){
		document.detachEvent("onmousemove", imgPos);
	}else{
		document.removeEventListener("mousemove", imgPos, true);
	}
	E('body').removeChild( E('grnd') );
}
function imgPos( event ){
	E('grnd').style.top = event.clientY - 70 + 'px';
	E('grnd').style.left = event.clientX + 25 + 'px';
}
function IE(){
	if( navigator.appName == 'Microsoft Internet Explorer'){
		return true;
	}else{
		return false;
	}
}
function VOLVER(){
window.history.go(-1);
return false;
}
function FLS(){
return false;
}

velocidadA= 300;
tiempoEsperaA = 1500;
verificarA = 1;
difA=0;
timerA=0;
function moverSlider() {
//		alert( 'difA' );
	sliderAltura = $(".bloque-slider").height();
	moduloAltura = $(".destacado").height() + parseFloat($(".destacado").css("padding-top")) + parseFloat($(".destacado").css("padding-bottom"));
	sliderTop = parseFloat($(".bloque-slider").css("top"));
	difA = sliderAltura + sliderTop;
	if (verificarA==1) {
//		alert( difA );
		if( difA>(moduloAltura*3) ) {			
			$(".bloque-slider").animate({top: "-="+moduloAltura } , velocidadA);
			timerA = setTimeout('moverSlider()',tiempoEsperaA);
		}else{
			clearTimeout(timerA);
			$(".bloque-slider").css({ top: 0});			
			timerA = setTimeout('moverSlider()',0);				
		}
	}else {	
		timerA = setTimeout('moverSlider()',1000);
	}
}	
function bajarSlider() {
	if(difA>=moduloAltura*2) {
		$(".bloque-slider").animate({top: "-="+moduloAltura }, velocidadA);
	}else{
		$(".bloque-slider").css({ top: 0});
		$(".bloque-slider").animate({top: "-="+moduloAltura }, velocidadA);		
	} 
}
function subirSlider() {
	if(sliderTop<=-moduloAltura) {
		$(".bloque-slider").animate({top: "+="+moduloAltura }, velocidadA);	
	}else{
		$(".bloque-slider").css({ top: -sliderAltura+moduloAltura});
		$(".bloque-slider").animate({top: "+="+moduloAltura }, velocidadA);						
	} 
}

$(document).ready(function(){
	(function(){ moverSlider()})();			
//	$(".bajar-slider").click(function(){
//		bajarSlider();
//	});
//	$(".subir-slider").click(function(){
//		subirSlider();
//	});
	$(".bloque-slider").mouseover(function(){
		verificarA = 0;
	});
	$(".bloque-slider").mouseout(function(){
		verificarA = 1;
	});
});

window.onload = I;






