var opts = { align: 'bottom' //default
		   , size:  98       //default
		   , distance:     160       //default
		   , coefficient :  1.6    //default
		   , labels: false    //default
		   , duration: 200 //default
			 //for menu1 and menu7, set a function to use the 'alt' attribute if present, else construct a PNG path from the 'src'...
		   , source: false
		   };

var GLBflipbooks_front;
var GLBflipbooks_back;
var GLBflipadelante;
var GLBflipatras;
var inicial=new Image();
var alto=204;
var ancho=288;
var altoInicial=204;
var anchoInicial=288;
var GLBFlipbooks;

var listaImgs;//para lista imagenes de giro

var esCargaNormal = 1;
var tira_front;
var tira_back;
var deg;


/*agregado*/
var numflips = GLBestructura.length;

var anchobanner = 939;
/**/

var durante=new Image();
durante.src="repositorio/dock/hands-2.png";

var preImages2 = new Array();
var preImages3 = new Array();
var preImages4 = new Array();
var fps = 100;



var currCount = 0;
var currCount2 = 0;
var loaded2 = new Array(),i,covered,timerID;
var actual=0;

scrollStep=40;

timerLeft="";
timerRight="";

var lengthOfPreloadBar = 240 // Length of preload bar (in pixels)
var heightOfPreloadBar = 10 // Height of preload bar (in pixels)
var preImages = new Array(),coverage=0,currCount = 0;
var loaded = new Array(),i,covered,timerID;
var leftOverWidth=0;


var despder =0;

var GLBinicio=0;
var GLBfinal=14;
var GLBestructuratemp=new Array();

function scrollDivLeft(){
	//if(parseInt(new String(document.getElementById("menu2").style.left).replace("px"))<=-100){
		//clearTimeout(timerLeft);
		//document.getElementById("menu2").style.left=(parseInt(new String(document.getElementById("menu2").style.left).replace("px"))+scrollStep)+"px";
		//timerLeft=setTimeout("scrollDivLeft()",100);
	//}
	//el -32 se agrega para darle espacio al primer flipbook a la izquierda
	if(parseInt($j(pic[0].childNodes[0]).css("left").replace("px"))<-12){
		clearTimeout(timerLeft);
		for (i=0;i<numImgs;i++){
			$j(pic[i].childNodes[0]).css("left",parseInt($j(pic[i].childNodes[0]).css("left"))+40);
		}
		timerLeft=setTimeout("scrollDivLeft()",100);
	}
	
	//GLBinicio=GLBinicio-14;
	//GLBfinal=GLBfinal-14;
	//if(GLBinicio<=0){
		//GLBinicio=0;
		//GLBfinal=14;
	//}
	//readXML(GLBinicio,GLBfinal);
}

var entreAS=false;
var last=-1;
function scrollDivRight(){
	/*modificar despl derecha*/	
	//if(parseInt(new String(document.getElementById("menu2").style.left).replace("px"))>=-despder){
		//clearTimeout(timerRight);
		//document.getElementById("menu2").style.left=(parseInt(new String(document.getElementById("menu2").style.left).replace("px"))-scrollStep)+"px";
		//timerRight=setTimeout("scrollDivRight()",100);
	//}
			
	//if(parseInt(new String(document.getElementById("menu2").style.left).replace("px"))>=-despder){
		//clearTimeout(timerRight);
		//document.getElementById("menu2").style.left=(parseInt(new String(document.getElementById("menu2").style.left).replace("px"))-scrollStep)+"px";
		//timerRight=setTimeout("scrollDivRight()",100);
	//}
	if(parseInt($j(pic[numImgs-1].childNodes[0]).css("left").replace("px"))>(despder*2 + 50)){
		clearTimeout(timerRight);
		for (i=0;i<numImgs;i++){
			$j(pic[i].childNodes[0]).css("left",parseInt($j(pic[i].childNodes[0]).css("left"))-40);
		}
		timerRight=setTimeout("scrollDivRight()",100);
	}
	//GLBinicio=GLBinicio+14;
	//GLBfinal=GLBfinal+14;
	//if(GLBinicio>=GLBestructura.length){
		//GLBinicio=0;
		//GLBfinal=14;
	//}
	//readXML(GLBinicio,GLBfinal);
	

}
function detener(){
  clearTimeout(timerRight);
  clearTimeout(timerLeft);
}
function mainmenuMenu(){
	document.getElementById("detail").style.display="none";
	document.getElementById("holder").style.display="";
}

function showDetail(id){
	var httpString="";
	var imagen_adelante=GLBestructuratemp[id][0];
	var imagen_atras=GLBestructuratemp[id][1];
	
	var caption=GLBestructuratemp[id][4];
	var descripcion_corta_ing=GLBestructuratemp[id][5];
	var descripcion_ing=GLBestructuratemp[id][6];
	
	GLBflipadelante=GLBestructuratemp[id][2];
	GLBflipatras=GLBestructuratemp[id][3];
	
	GLBflipbooks_front=GLBestructuratemp[id][7];
	GLBflipbooks_back=GLBestructuratemp[id][8];
	
	fps=GLBestructuratemp[id][9];
	
	/*BOOL 	tipo tira (video) -------------------------*/
	tira_front = GLBestructuratemp[id][10];
	/*alert('tira_front='+tira_front);
	alert(GLBestructuratemp[id][8]); ojo el fps es el glbestructura 8
	alert(GLBflipbooks_back);*/
	tira_back = GLBestructuratemp[id][11];
	/*-----------------------------------------*/
	
	inicial.src=GLBflipadelante;
	
	httpString+='<table cellpadding="0" cellspacing="0" border="0" >';
		httpString+='<tr valign="top">';
			httpString+= '<td style="text-align:left; font-family:Helvetica;">';
				httpString+= '<table width="238px" align="left" cellpadding="0" cellspacing="0" border="0">';
				httpString+=	'<tr>';
				httpString+=		'<td style="border-bottom:1px solid #000000; padding-top:39px">';
				httpString+=			'<span style="padding-left:17px;font-family:Helvetica;font-size:16px;font-weight:bold;color:#393A3C">'+caption+'</span>';
				//httpString+=			'<span style="padding-left:17px;font-family:Helvetica,font-size:18px,font-weight:bold">Proflix Football Edition</span>';
				httpString+=		'</td>';
				httpString+=	'</tr>';
				httpString+=	'<tr>';
				httpString+=		'<td >';
				httpString+=			'<span style="padding-left:17px;font-family:Helvetica;font-size:14px;color:#393A3C;font-style:italic">'+descripcion_corta_ing+'</span>';
				//httpString+=			'<span style="padding-left:17px;font-family:Helvetica,font-size:16px">Arsenal/ Cess Frabregas</span>';
				httpString+=		'</td>';
				httpString+=	'</tr>';
				httpString+=	'<tr>';
				httpString+=	  '<td>';
				httpString+=     	'<div  style="position:relative;font-family:Helvetica;font-size:12px; padding-left:23px;padding-right:23px;padding-top:15px;text-align:justify;color:#393A3C">'+descripcion_ing+'</div>';
				//httpString+=     	'<div  style="position:relative;font-family:Helvetica,font-size:10px; padding-left:23px;padding-right:18px;padding-top:15px;text-align:justify">Over 140 years after its invention, the Flipbook has its comeback in a new style. In the year 2003, with a complete new concept Proflix put Flipbooks to the next level. In a next generation form, rivet bound are Proflix Flipbooks brought ... Learn more about it! </div>';
				httpString+= 	  '</td>';
				httpString+=   '</tr>';
				httpString+=  '</table>';
				
		  /*flip adelante y flip atras*/
			httpString+=  '</td>';
			httpString+='<td style="vertical-align:top; padding:18px 0px 0 5px">';
				httpString+='<a href=\'javascript:readXMLfront()\'  title=""> <img style="border:0 " src="'+imagen_adelante+'"  title="" ></a>';
			httpString+='</td>';
			httpString+='<td style="vertical-align:top;padding:18px 10px 0 25px ">';
				httpString+='<a href=\'javascript:readXMLback()\'  title=""> <img style="border:0 " src="'+imagen_atras+'"  title="" ></a>';				
			httpString+='</td>';
			
			
			/*click cover*/
			httpString+='<td valign="top">';
			httpString+= 	'<table cellpadding="0" cellspacing="0" border="0">';
			httpString+=		'<tr valign="top" style="padding-top:42px">';
			httpString+=           '<td style="height:46px"></td>';
			httpString+=		'</tr>';					
			httpString+=		'<tr valign="top">';
			httpString+=           '<td><img src="Proflix/images/click_cover2.jpg" width="122px" height="80px"></img></td>';
			httpString+=		'</tr>';			
			httpString+=		'<tr valign="top">';
			httpString+=			'<td style="vertical-align:top;height:20px; padding:57px 0 0 0" align="center">';
			httpString+=				'<a class="back" href=\'javascript:mainmenuMenu();\'  title="">back&nbsp;to&nbsp;main</a>';
			httpString+=			'</td>';
			httpString+=		'</tr>';
			httpString+= 	'</table>';
			httpString+='</td>';
			
			/*divs para animar flipbook normal*/
			
			httpString+='<td id="td_animacion" style="vertical-align:top;width:288px; padding-top:0">';
			httpString+= '<div id="imagenes" style="background-repeat:no-repeat; text-align:center; " align="center" >';
			httpString+= '<div id="flipper" style="background-repeat:no-repeat;background-color:transparent;background-image:url('+GLBflipadelante+'); height:'+altoInicial+'px; width:'+anchoInicial+'px"></div>';
			httpString+= '</div>';
			httpString+='</td>';
			
			
		httpString+='</tr>';
	httpString+='</table>';
	
	document.getElementById("detail").innerHTML=httpString;
	document.getElementById("holder").style.display="none";
	document.getElementById("detail").style.display="";
	GLBFlipbooks=GLBflipbooks_front;
	loadImagespre1();
	GLBFlipbooks=GLBflipbooks_back;
	loadImagespre2();
	
	
	Inicial();
}

/*function readxml -------------------------------------*/
function readXML(inicio,final){
	
	var httpString="";
	httpString+='<center>';
	httpString+='<font size="4" style="color:#FFFFFF; font-size:10px; font-style:italic; font-weight:normal"><div style="padding:0 0 4px 0 " id="porcAv">0%</div></font>';
	var t=0;
	//for (i = 0; i < GLBestructura.length-1; i++) {error 
	for (i = 0; i < GLBestructura.length; i++) {
		GLBestructuratemp[t]=GLBestructura[i];
		t++;
	}
	//despder = (GLBestructuratemp.length - 16)*63+100;alert(despder);
	despder = (GLBestructuratemp.length)*63+100;
	
	coverage = Math.floor(lengthOfPreloadBar/GLBestructuratemp.length);
	leftOverWidth = lengthOfPreloadBar%coverage;
	
	if (document.images) {
		httpString += '<img src="images/loading/leftScrollbar.png" width="7px" height="10px" name="imgLeft" id="imgLeft" align="absmiddle">'
		//for (i = 0; i < GLBestructuratemp.length-1; i++) {error
		for (i = 0; i < GLBestructuratemp.length; i++) {
			httpString += '<img src="' + dots[0].src + '" width="' + coverage + '" height="' + heightOfPreloadBar + '" name="img' + i + '" id="img' + i + '" align="absmiddle">'
		}
		httpString += '<img src="' + dots[0].src + '" width="' + (leftOverWidth+coverage) + '" height="' + heightOfPreloadBar + '" name="img' + (GLBestructuratemp.length-1) + '" id="img' + (GLBestructuratemp.length-1) + '" align="absmiddle">'
		httpString += '<img src="images/loading/rightScrollbarB.png" width="7px" height="10px" name="imgRight" id="imgRight" align="absmiddle">'
	}
									
	httpString+='</center>';
	
	document.getElementById("menu2").innerHTML=httpString;
	//document.getElementById("menu2").style.left="340px";
	
	
	//document.getElementById("menu2").style.right="40px";
	loadImages(inicio,final);	
}


function loadImages(inicio,final) {
	var t=0;
	for (i = 0; i < GLBestructuratemp.length; i++) {
		preImages[i] = new Image();
		preImages[i].src = GLBestructuratemp[i][0];
	}
	
	for (i = 0; i < preImages.length; i++) {
		loaded[i] = false;
	}
	currCount = 0; //agregado
	checkLoad();
}

function checkLoad() {
	
	if (currCount == preImages.length) {
		eval("document.imgRight.src=dots[2].src");
		
		timerID = setTimeout("LoadDock()",100);
		return;
	}
	var ultimaImgCargada=0;
	var por=0;
	for (i = 0; i <= preImages.length; i++) {
		if (loaded[i] == false && preImages[i].complete) {
			loaded[i] = true;
			eval("document.img" + currCount + ".src=dots[1].src");
			for (j = 0; j<= currCount; j++) {
				por=(currCount*100/preImages.length);		
			}
			currCount++;
		}
	}
	document.getElementById("porcAv").innerHTML=Math.round((currCount*100/preImages.length),0)+"%";
	timerID = setTimeout("checkLoad()",10)
}

function LoadDock(){
	var ancho=0;
	var httpString="";
	var porc=0;
	var t=0;
	var inicio=0;
	if(GLBestructuratemp.length>0){
		if(GLBestructuratemp.length%2==0){
			inicio=(GLBestructuratemp.length/2);
		}
		else{
			inicio=(GLBestructuratemp.length+1)/2-1;					
		}
	}
	var GLBestructuratemp2=new Array(GLBestructuratemp.length);
		
	
	
	
	for (i=0;i<GLBestructuratemp.length;i++)
	{
		if(i%2==0){
			inicio=inicio+i;
		}
		else{
			inicio=inicio-i;
		}
		
		GLBestructuratemp2[inicio]=GLBestructuratemp[i];
	}
	
	GLBestructuratemp=GLBestructuratemp2;
	for (i=0;i<GLBestructuratemp.length;i++)
	{
		httpString+='<a  href="javascript:showDetail('+i+')" title=""><img  class="jqDockMouse0_'+i+'" src="'+GLBestructuratemp[i][0]+'"  alt="" title=""></a>';  
		porc=Math.round(Math.floor((98*100)/preImages[i].height));
		ancho+=Math.floor(preImages[i].width*(porc/100));
	}
	//despder=(anchobanner-(ancho+170))/2;
	despder=(anchobanner-(ancho+170))/2-25;
	
	//document.getElementById("menu2").style.left=-240+"px";
	//document.getElementById("menu2").style.display="none";
	
	document.getElementById("menu2").innerHTML=httpString;
	
	//despder= (((GLBestructuratemp.length) * 63) / 2) -28;
	//document.getElementById("menu2").style.left = despder + "px";
	
	pic = $j("#menu2 a");
	numImgs = pic.length;
	arrLeft = new Array(numImgs);
	
	for (i=0;i<numImgs;i++){
		
		totalWidth=despder;
		arrLeft[i] = totalWidth;
		$j(pic[i].childNodes[0]).css("left",totalWidth);
	}
	jQuery('#menu2').jqDock(opts);
}

function Inicial(){
	/*alert(document.getElementById("td_animacion").innerHTML);
	*/
	var hstring;
	hstring='<td id="td_animacion" style="vertical-align:top;width:288px; padding-top:15px">';
	hstring+= '<div id="imagenes" style="background-repeat:no-repeat; text-align:center; " align="center" >';
	hstring+= '<div id="flipper" style="background-repeat:no-repeat;background-color:transparent;background-image:url('+GLBflipadelante+'); height:'+altoInicial+'px; width:'+anchoInicial+'px"></div>';
	hstring+= '</div>';
	hstring+='</td>';
	
	
	document.getElementById("td_animacion").innerHTML=hstring;
	document.getElementById("flipper").style.height=altoInicial+"px";
	document.getElementById("flipper").style.width=anchoInicial+"px";
	document.getElementById("flipper").style.background="url("+inicial.src+") no-repeat";
}

function readXMLfront(){
	
	//determina los flipbooks a cargar y si es carga normal
	GLBFlipbooks=GLBflipbooks_front;	
	
	//------------------------------	
	if(tira_front == 0){
		esCargaNormal = 1;
		//alert('tira_front'+tira_front);
	}else{
		esCargaNormal = 0;
		//alert('tira_front'+tira_front);
		//alert('carga no normal');
	}
	//------------------------------
	
	inicial.src=GLBflipadelante;
	clearTimeout(timerID);
	
	Inicial(); //que es
	document.getElementById("imagenes").style.background = "";
	actual=0;
	currCount=0;
	if(GLBflipbooks_front.length>0){
		var httpString="";
		httpString+='<font size="4" style="color:#0000; font-size:10px; font-style:italic; font-weight:normal; vertical-align:top" align="right" ><div style="padding:0 0 4px 0 " id="porcAv2">0%</div></font>';
		document.getElementById("flipper").innerHTML=httpString; //agregar despues
		loadImages2();
	}
	
	
}


function readXMLback(){
	GLBFlipbooks=GLBflipbooks_back;
	
	if(tira_back == 0){
		esCargaNormal = 1;
		//alert('tira_front'+tira_front);
	}else{
		esCargaNormal = 0;
		//alert('carga no normal');
	}
	
	inicial.src=GLBflipatras;
	clearTimeout(timerID);
	Inicial();
	document.getElementById("imagenes").style.background = "";
	actual=0;
	currCount=0;
	if(GLBFlipbooks.length>0){
		var httpString="";
		httpString+='<font size="4" style="color:#0000; font-size:10px; font-style:italic; font-weight:normal; vertical-align:top" align="right" ><div style="padding:0 0 4px 0 " id="porcAv2">0%</div></font>';
		document.getElementById("flipper").innerHTML=httpString;
		loadImages2();
	}
}

function loadImages2() {
	for (i = 0; i < GLBFlipbooks.length; i++) {
		preImages2[i] = new Image();
		preImages2[i].src = GLBFlipbooks[i];
	}
	for (i = 0; i < preImages2.length; i++) {
		loaded2[i] = false;
	}
	
	checkLoad2();
}

function loadImagespre1() {
	for (i = 0; i < GLBFlipbooks.length; i++) {
		preImages4[i] = new Image();
		preImages4[i].src = GLBFlipbooks[i];
	}
}
function loadImagespre2() {
	for (i = 0; i < GLBFlipbooks.length; i++) {
		preImages3[i] = new Image();
		preImages3[i].src = GLBFlipbooks[i];
	}
}


//funcion de animacion
function checkLoad2() {
	if (currCount == preImages2.length) {
		actual=0;
		/*----------------    carga normal flipbook  --------------------*/
		
		
		if(esCargaNormal == 1){
			document.getElementById("flipper").style.background="url("+durante.src+") no-repeat";
			document.getElementById("flipper").style.height=alto+"px";
			document.getElementById("flipper").style.width=ancho+"px";
			document.getElementById("flipper").innerHTML="";
			timerID = setTimeout("LoadFlipbook()",fps);				
		}else{
			timerID = setTimeout("LoadFlipbook_giro()",100);
			//LoadFlipbook_giro();
			//alert('here');
			
		}
		
		return;
	}
	
	//alert(esCargaNormal+"check");
	var ultimaImgCargada=0;
	var por=0;
	for (i = 0; i <= preImages2.length; i++) {
		if (loaded2[i] == false && preImages2[i].complete) {
			loaded2[i] = true;
			for (j = 0; j<= currCount; j++) {
				por=(currCount*100/preImages2.length);
			}
			currCount++;
		}
	}
	document.getElementById("porcAv2").innerHTML=Math.round((currCount*100/preImages2.length),0)+"%";
	
	timerID = setTimeout("checkLoad2()",10)
}

function LoadFlipbook_giro(){

//alert('rotate');
			deg=-180;  
			var myimg = new Image;
			//myimg.src = "../../images/rotate/imagen1.png";
			
			
			//myimg.src = "images/rotate/imagen1.png";
			//alert(GLBFlipbooks[0]);
			
			myimg.src =  GLBFlipbooks[0];
			listaImgs=GLBFlipbooks;
			
			
			document.getElementById("td_animacion").innerHTML = '<div id="imagenes"></div>';
			var divImgs =document.getElementById("imagenes");
			divImgs.appendChild(myimg);
			
			var rot = $(myimg).rotate({maxAngle:180, minAngle:-180});
			rot.rotateAnimation(deg);
			clearTimeout(timerID);
			/*vuelve a poner la primera imagen*/
			
			
			/*----------------------------------------------------------*/
			//  funcion con el click
			/*----------------------------------------------------------*/
			/*var rot = $(myimg).rotate({maxAngle:180, minAngle:-180,
  			bind:
  				[
  					{"click":function(){rot.rotateAnimation(180);}},
  					//{"mouseleave":function(){rot.rotateAnimation(-180);}}
  				] 
			}); */
			/*----------------------------------------------------------*/
			

}

function LoadFlipbook(){
	if(actual==GLBFlipbooks.length){		
		actual=0;
		clearTimeout(timerID);
		document.getElementById("imagenes").style.background = "";
		document.getElementById("flipper").style.background="url("+inicial.src+") no-repeat";
	}
	else{
		document.getElementById("imagenes").style.height=alto+"px";
		document.getElementById("imagenes").style.width=ancho+"px";
		document.getElementById("imagenes").style.background="url("+preImages2[actual].src+") 115px 33px no-repeat";
		
		actual++;
		timerID = setTimeout("LoadFlipbook()",fps);
	}
}