window.onload = cargaEventos;
window.onload = prepareTargetBlank;

function  cargaEventos(){
	cambiarOpacidad("tUno","90")
	cambiarOpacidad("tDos","90")
	cambiarOpacidad("tTres","90")
	
	var menu = document.getElementById("menuLateral");
//	menuLateral.onmouseover = function () { mueveMenu(720); };
//	menuLateral.onmouseout = function () { mueveMenu(855); };
}


function cambiaBorde(colorTipo, colorBord, id){
	var border = document.getElementById("contenido");
	border.style.borderColor = colorBord;
	var botonMenu = document.getElementById(id)
	botonMenu.style.color = colorTipo;
	botonMenu.style.borderColor = colorTipo;
}

var opacidad = 50;
function cambiarOpacidad(cual,cuanto){
	opacidad = cuanto;
	var image = document.getElementById(cual);
	image.style.opacity = opacidad/100;
	image.style.filter = "alpha(opacity = "+opacidad+")";
}

var posX = 855;
var finalX;
var inercia = 9;
var intervalo;

// FUNCION PÚBLICA MOVIMIENTO MENU
function mueveMenu(donde){
	finalX = donde;
	clearInterval(intervalo);
	intervalo = setInterval(__mueveMenu,0);
}

// FUNCION PRIVADA MOVIMIENTO MENU
function __mueveMenu(){
	var menuLateral = document.getElementById("menuLateral");
	posX+= (finalX-posX)/inercia;
	menuLateral.style.left = posX+"px";
	if (Math.round(posX) == finalX){
		clearInterval(intervalo);
	}
}

// FUNCTION MOVIMIENTO PACKAGING
var positionX = 0
var intervalo;
var finalX;
function desplazaCarrusel(dondeIr){
	finalX=dondeIr;
	
	//posX = document.getElementById("panorama").style.left; ???
	clearInterval(intervalo);
	intervalo = setInterval(__desplazaCarrusel, 30);
	
}
 
function __desplazaCarrusel(){
	positionX+=(finalX-positionX)/6
	document.getElementById("imagepacks").style.left = positionX+"px";
	if(Math.round(positionX) == finalX){
	positionX=finalX;
	document.getElementById("imagepacks").style.left = positionX+"px";
	clearInterval(intervalo);	
	}
}

// FUNCTION NAVAGACION PACKAGING
	function pintarMiniaturas (){
		for(var i=1; i<24; i++){
			document.write('<a href="javascript:verFoto('+i+')"><img src="img/illus/mini'+i+'.jpg" /></a>')
		}
	}
	function verFoto(cual){
	document.getElementById("grande").src = "img/illus/grande"+cual+".jpg"
	}


//ABRIR EN NUEVA VENTANA


function prepareTargetBlank(){
   var className = 'external';
   var as = document.getElementsByTagName('a');
   for(i=0;i<as.length;i++){
      var a = as[i];
      r=new RegExp("(^| )"+className+"($| )");
      if(r.test(a.className)){
         a.onclick = function(){
            window.open(this.href);
            return false;
         }
      }
    }
}







