var xhrDatos	= "false";

//... Para hacer referencia al <div> que recibirá la informacion
var divDatos	= "false";

function ajax(archivo,variables,div){
	var div		= div;
	divDatos	= document.getElementById(div);
	//divDatos.innerHTML="Cargando pagina siguiente...";
	// Evaluamos que tipo de objeto reconoce el navegador
	if( window.XMLHttpRequest ){
		xhrDatos	= new XMLHttpRequest();
	}else if( window.ActiveXObject ){
		xhrDatos	= new ActiveXObject("Microsoft.XMLHTTP");	
	}else{
		divDatos.innerHTML = "Su navegador no soporta XHMHttpRequest";	
	}
	
	// Evaluamos si se ha podido generar el objeto
	if( xhrDatos ){
	xhrDatos.onreadystatechange = JDCDatosCargados;
	xhrDatos.open("GET", archivo+"?"+variables , true);
	xhrDatos.send( null );
	}
	
}

function JDCDatosCargados(){
	// Evaluamos si ha terminado de cargar
	if( xhrDatos.readyState == 4 ){
	// Si el estado es 200, OK
		if( xhrDatos.status == 200 ){ 
			
			datos_obtenidos		= xhrDatos.responseText.split('--///xxYxx\\\--');
			divDatos.innerHTML	= datos_obtenidos[0];
			
		}else{
			divDatos.innerHTML="Ocurrió un error al cargar los datos";
		}
	}
	
}

var sumar	= false;
var no		= false;
	
function cargar_flash(){
	
	flash	 = '  <object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="350" height="350">';
	flash	+= '    <param name="movie" value="images/estructura/preloader-mac.swf" />';
	flash	+= '    <param name="quality" value="high" />';
	flash	+= '    <param name="wmode" value="opaque" />';
	flash	+= '    <param name="swfversion" value="8.0.35.0" />';
	flash	+= '    <param name="expressinstall" value="Scripts/expressInstall.swf" />';
	flash	+= '    <!--[if !IE]>-->';
	flash	+= '    <object type="application/x-shockwave-flash" data="images/estructura/preloader-mac.swf" width="350" height="350">';
	flash	+= '      <!--<![endif]-->';
	flash	+= '      <param name="quality" value="high" />';
	flash	+= '      <param name="wmode" value="opaque" />';
	flash	+= '      <param name="swfversion" value="8.0.35.0" />';
	flash	+= '      <param name="expressinstall" value="Scripts/expressInstall.swf" />';
	flash	+= '      <div>';
	flash	+= '        <h4>El contenido de esta página requiere una versión más reciente de Adobe Flash Player.</h4>';
	flash	+= '        <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Obtener Adobe Flash Player" width="112" height="33" /></a></p>';
	flash	+= '      </div>';
	flash	+= '    <!--[if !IE]>-->';
	flash	+= '    </object>';
	flash	+= '    <!--<![endif]-->';
	flash	+= '  </object>	';
	return	flash;
	swfobject.registerObject("FlashID");
}
	
function cargar(img,id){
div_img			= document.getElementById("grande");
div_fondo		= document.getElementById("fondo");
div_miniaturas	= document.getElementById("barra_inf");
sumar++;
if ( no != 1 ){
	
		div_img.style.visibility		="visible";
		div_fondo.style.visibility		="visible";
		div_miniaturas.style.visibility	="visible";
		
		div_img.style.width				= "350px";
		div_img.style.height			= "350px";
		div_img.innerHTML				= cargar_flash();
		var data=getWindowData();
		window.$('fondo').style.width		= data[0]+'px';
		window.$('fondo').style.height		= data[1]+'px';
		div_img.style.left=data[0]/2+data[2]-parseInt($('grande').style.width)/2+'px';
		div_img.style.top=data[1]/2+data[3]-parseInt($('grande').style.height)/2+'px';
		
		div_miniaturas.style.left	= div_img.offsetLeft+"px";
		div_miniaturas.style.top	= div_img.offsetTop + div_img.offsetHeight + 5+"px";
		div_miniaturas.style.width	= div_img.offsetWidth+"px";
		
		ajax("jdc/miniaturas.php","tam=30&id="+id,"barra_inf");
}
var imagen		= new Image();
	imagen.src	= img;
	
	no = 1;

	if( imagen.complete ){
		var data=getWindowData();
		if( imagen.width > imagen.height ){
		ancho	= 450;
		alto	= (ancho / imagen.width) * imagen.height;
		}else{
		alto	= 450;
		ancho	= (alto / imagen.height) * imagen.width;
		}
		

		
		div_img.style.width		= ancho+"px";
		div_img.style.height	= alto+"px";

		window.$('grande').style.left=data[0]/2+data[2]-parseInt($('grande').style.width)/2+'px';
		window.$('grande').style.top=data[1]/2+data[3]-parseInt($('grande').style.height)/2+'px';
		
		div_miniaturas.style.left	= data[0]/2+data[2]-parseInt($('grande').style.width)/2+'px';
		div_miniaturas.style.top	= div_img.offsetTop + div_img.offsetHeight + 5+"px";
		div_miniaturas.style.width	= data[0]-400+"px";
		
		html_imagen				= "<a href=\"javascript:ocultar();\"><img src=\""+imagen.src+"\" height='"+alto+"' width='"+ancho+"' border=\"0\"></a>";
		div_img.innerHTML	= html_imagen;
		no	= 0;
	}else{
		setTimeout("cargar('"+img+"','"+id+"')",1000);
	}
}
function ocultar(){
document.getElementById('grande').style.visibility="hidden";
document.getElementById("fondo").style.visibility="hidden";
document.getElementById("barra_inf").style.visibility="hidden";
document.getElementById('grande').style.width=2+"px";
document.getElementById('grande').style.height=2+"px";
document.getElementById('fondo').style.width=2+"px";
document.getElementById('fondo').style.height=2+"px";
document.getElementById('barra_inf').style.width=2+"px";
document.getElementById('barra_inf').style.height=2+"px";
}

function getWindowData(){
    var widthViewport,heightViewport,xScroll,yScroll,widthTotal,heightTotal;
    if (typeof window.innerWidth != 'undefined'){
        widthViewport= window.innerWidth;
        heightViewport= window.innerHeight;
    }else if(typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0){
        widthViewport=document.documentElement.clientWidth;
        heightViewport=document.documentElement.clientHeight;
    }else{
        widthViewport= document.getElementsByTagName('body')[0].clientWidth;
        heightViewport=document.getElementsByTagName('body')[0].clientHeight;
    }
    xScroll=self.pageXOffset || (document.documentElement.scrollLeft+document.body.scrollLeft);
    yScroll=self.pageYOffset || (document.documentElement.scrollTop+document.body.scrollTop);
    widthTotal=Math.max(document.documentElement.scrollWidth,document.body.scrollWidth,widthViewport);
    heightTotal=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,heightViewport);
    return [widthViewport,heightViewport,xScroll,yScroll,widthTotal,heightTotal];
}
function $(id){
return document.getElementById(id);
}

window.onload=function(){
var data=getWindowData();
$('grande').style.left		= data[0]/2+data[2]-parseInt($('grande').style.width)/2+'px';
$('grande').style.top		= data[1]/2+data[3]-parseInt($('grande').style.height)/2+'px';
$('fondo').style.width		= data[0]+'px';
$('fondo').style.height		= data[1]+'px';
$('fondo').style.left		= data[0]/2+data[2]-parseInt($('fondo').offsetWidth)/2+'px';
$('fondo').style.top		= data[1]/2+data[3]-parseInt($('fondo').offsetHeight)/2+'px';
$('barra_inf').style.left	= $('grande').offsetLeft+"px";
$('barra_inf').style.top	= $('grande').offsetTop + $('grande').offsetHeight + 20+"px";
$('barra_inf').style.width	= $('grande').offsetWidth+"px";
}

window.onresize=window.onscroll=function(){
var data=getWindowData();
$('fondo').style.width		= data[0]+'px';
$('fondo').style.height		= data[1]+'px';
$('fondo').style.left		= data[0]/2+data[2]-parseInt($('fondo').offsetWidth)/2+'px';
$('fondo').style.top		= data[1]/2+data[3]-parseInt($('fondo').offsetHeight)/2+'px';
}