$(document).ready(function(){
	// cargaDocumento ();
	menuDesplegableEd();	
	iconoSocial();
	appsMovil();
	configurarDemonstration();
	configurarGallery();
	configurarSlide();
	configurarDownload();
	configurarScrollTexto();	
});

/*----------------------menu desplegable------------------*/
function menuDesplegableEd(){
	$("nav.menuPpal ul li.lista_desplegable" ).mouseover(
		function() {						
			$("nav.menuPpal ul li.lista_desplegable").addClass("ov");			
			$("ul", this).fadeIn();
			}
		)
	
	$("nav.menuPpal ul li.lista_desplegable" ).mouseleave(
		function() {		
			$("nav.menuPpal ul li.lista_desplegable").removeClass("ov");
			$("ul", this).fadeOut();			
			}
		)
		
	/*$("nav.menuPpal ul li.lista_desplegable > a" ).click(
		function() {
			return false;
			}
		)*/
	$("nav.menuPpal ul li.lista_item_no" ).hide();	
}
/*---------------------/menu desplegable------------------*/

/*----------------------TRANSPARENCIAS ICONOS--------------------*/
function iconoSocial(){
$("#socialRed li").each(function() {
		$("a strong", this).css("opacity", "0");
	});
	
	$("#socialRed li").hover(function() { // Mouse over
		$(this).stop().fadeTo(500, 1).siblings().stop().fadeTo(500, 0.2);
		$("a strong", this).stop().animate({opacity: 1,top: "-10px"}, 300);
	}, function() { // Mouse out
		$(this).stop().fadeTo(500, 1).siblings().stop().fadeTo(500, 1);
		$("a strong", this).stop().animate({opacity: 0,top: "-1px"}, 300);
	});
}

function appsMovil(){
$("#movilApps li").each(function() {
		/*$("a strong", this).css("opacity", "0");*/
	});
	
	$("#movilApps li").hover(function() { // Mouse over
		$(this).stop().fadeTo(500, 1).siblings().stop().fadeTo(500, 0.2);
		/*$("a strong", this).stop().animate({opacity: 1,top: "-10px"}, 300);*/
	}, function() { // Mouse out
		$(this).stop().fadeTo(500, 1).siblings().stop().fadeTo(500, 1);
		/*$("a strong", this).stop().animate({opacity: 0,top: "-1px"}, 300);*/
	});
}


/*----------------------TRANSPARENCIAS ICONOS--------------------*/



/*----------------------visor demostration------------------*/

	var quienSoy;	
	function configurarDemonstration () {
		//		
		$(".texto_over article a, .img_thumbs_galeria a, .texto_over div.no-html5 a" ).live("click" , evDemonstrationButtonClick);
		$(".texto_over article a.ov, .texto_over div.no-html5 a.ov" ).click ( function() { return false});
		
	}
	
	function evDemonstrationButtonClick () {
		//
		quienSoy = this;
		$('#visor_video').fadeOut('slow', evVisorFadeOut);
		return false;
	}
	
	function evVisorFadeOut () {
		//
		$('#visor_video').load(quienSoy.href + " #visor_video", evVisorLoadListo);
	}
	
	function evVisorLoadListo () {
		//
		$('#visor_video').fadeIn('slow', evVisorFadeIn);
	}
	
	function evVisorFadeIn () {
		//
		$('#visor_video').show ();
		
			
	}
	
	function loadjscssfile(filename, filetype){
	 if (filetype=="js"){ //if filename is a external JavaScript file
	  var fileref=document.createElement('script')
	  fileref.setAttribute("type","text/javascript")
	  fileref.setAttribute("src", filename)
	 }
	 else if (filetype=="css"){ //if filename is an external CSS file
	  var fileref=document.createElement("link")
	  fileref.setAttribute("rel", "stylesheet")
	  fileref.setAttribute("type", "text/css")
	  fileref.setAttribute("href", filename)
	 }
	 if (typeof fileref!="undefined")
	  document.getElementsByTagName("head")[0].appendChild(fileref)
	}
	
	//loadjscssfile("js/html5.js", "js") //dynamically load and add this .js file
	//loadjscssfile("js/IE9.js", "js") //dynamically load "javascript.php" as a JavaScript file


/*---------------------/visor demostration------------------*/


/*---------------------SLIDE GALLERY---------------------------*/

var indice = 0;
var espera;
function configurarGallery () {
	//
	$("#imagen_grande_gallery").load ( function () {
		$("#imagen_grande_gallery").fadeIn ('slow');
		espera = setTimeout (galleryCargarImagen, 1000 * 5);
	});
	galleryCargarImagen();
	
	$("#playImageGallery a").click(autoPlayGallery);
	$("#stopImageGallery a").click(stopGallery);
	
	
	
	$("#prevImageGallery a").click(evPrevPlayGallery);
	
	$("#nextImageGallery a").click(autoPlayGallery);
	
	$(".gallery_tn").click (evGalleryButtonClick);
}

function evPrevPlayGallery () {
	indice -= 2;
	if ( indice < 0 ) {
		indice = 0;
	}
	galleryCargarImagen ();
	return false;
}

function evGalleryButtonClick () {
	//	
	indice = Number(this.rel);
	galleryCargarImagen ();
	
	return false;
}

function autoPlayGallery(){
	galleryCargarImagen(); 
	return false;
	}
	
function stopGallery(){
	if ( espera ) {
		clearTimeout ( espera );
	}
	return false;
}
	

function galleryCargarImagen () {
	//
	stopGallery();
	var blabla = "";	
	var cantidadImagenes = 0;
	$(".gallery_tn").each (function(i, val) {
		
		if ( indice == Number ($(this).attr("rel")) ) {
      		blabla = $(this).attr("href");			
		}		
		cantidadImagenes = i + 1;
    });
	$("#imagen_grande_gallery").hide ();
	$("#imagen_grande_gallery").attr ("src", blabla );
	indice ++;
	// alert("cantidadImagenes: " + cantidadImagenes + " - indice:" + indice);
	if ( indice == cantidadImagenes) {
		
		indice = 0;
	}
}



// SLIDE DE IMÁGENES/VIDEOS.
var estaAnimando = false;
function configurarSlide () {
	//slideBotonPrev
	//slideBotonNext
	
	$("#slideBotonNext").click(
		function(){
			slideNext();	
			return false;
			}
	)
	
	$("#slideBotonPrev").click(
		function(){
			slidePrev();
			return false;
			}
	)
	/*--*/
	seteaSlide();
}

function seteaSlide(){
	//alert("armaBotoneraSlide")
	// Contamos cuantas imagenes hay------------------------------------------------------------------------
	
	var anchoVisorString = $(".contenedor_thumbs_galeria").css("width");	
	var arrayDivs = $(".thumbs_galeria_total >div");	
	if (anchoVisorString == undefined) {
		//
		return;
	}
	var anchoVisor = Number( anchoVisorString.replace("px","") ); // pasamos el ancho a formato numero	
	var cantidadImagenes = arrayDivs.length;
	cantidadImagenes = cantidadImagenes -1 ;
	
//	$(arrayDivs[1])
	
	var largoSlide2 = 0/*( $(arrayDivs[0]).outerWidth())*/ ;
	//alert(largoSlide2);
	
	var largoSlide = cantidadImagenes * ( $(arrayDivs[1]).outerWidth(true));	
	//alert(largoSlide);
	

	
	var largoSlide3 = largoSlide + largoSlide2
	//alert(largoSlide3);
	
	
	window.anchoVisor = anchoVisor ;// seteo esta var global
	window.largoSlide = largoSlide3;// seteo esta var global
	
    $(".thumbs_galeria_total").css("width",largoSlide)// setea el largo
	
	$(".thumbs_galeria_total").css("left",0)// setea posicion a 0
	
}

function slideNext()
	{
		if (estaAnimando) {
			//		
			return;		
		}
	
		var posicionActualString = $(".thumbs_galeria_total").css("left");
		var posicionActual =  Number( posicionActualString.replace("px","") );
	
	
		if(posicionActual> -1*(window.largoSlide-window.anchoVisor) )
		{
			//$j(".slide_ancho").css("left", posicionActual-window.anchoVisor);
			estaAnimando = true;
			$('.thumbs_galeria_total').animate({ left : "-="+window.anchoVisor }, 800 , function() { estaAnimando = false; });		
			
		}

	}
	
function slidePrev(){	
	if (estaAnimando) {
		//
		return;
	}
	
	var posicionActualString = $(".thumbs_galeria_total").css("left");
	var posicionActual =  Number( posicionActualString.replace("px","") );
	
	if(posicionActual<0)
	{
		//$j(".slide_ancho").css("left", posicionActual+window.anchoVisor);
		estaAnimando = true;
		$('.thumbs_galeria_total').animate({ left : "+="+window.anchoVisor }, 800 , function() { estaAnimando = false; });
		
	}
	
}	

/*---------------------SLIDE GALLERY---------------------------/*




/*---FUNCION DE PRODUCTS--*/
function configurarDownload () {
	//
	$("#imagen_grande_download").hide ();
	$("#imagen_grande_link").click (openPopUp);
	$(".download_view").click (evDownloadButtonClick);
	$(".download_view_link").click (evDownloadLinkButtonClick);
}

function openPopUp(){
	open(this.href ,'popup','width=1000,height=700,toolbar=no,location=no,scrollbars=no,status=no,resizable=no,fullscreen=no');
	return false;
}	

function evDownloadButtonClick () {
	//
	$("#frase_download").text(this.rel);
	$("#imagen_grande_link").hide ();
	$("#imagen_grande_download").hide ();
	$("#imagen_grande_download").attr ("src", this.href).load ( function () {
		$("#imagen_grande_download").fadeIn ('slow');
	});
	open(this.href ,'popup','width=1000,height=700,toolbar=no,location=no,scrollbars=no,status=no,resizable=no,fullscreen=no');
	return false;
}

function evDownloadLinkButtonClick () {
	//
	$("#imagen_grande_download").hide ();
	$("#imagen_grande_link").show ();
	
	$("#imagen_grande_link").attr ("href", this.href);
	$("#imagen_grande_link img").hide ();
	$("#imagen_grande_link img").attr ("src", this.rel).load ( function () {
		$("#imagen_grande_link img").fadeIn ('slow');
	});
	
	open(this.href ,'popup','width=1000,height=700,toolbar=no,location=no,scrollbars=no,status=no,resizable=no,fullscreen=no');
	
	return false;
}

/*- / FUNCION DE PRODUCTOS-----*/


/*-----------EVENTS-----------------------------------------------*/
// Scroll de un Div.
var paso = 3;
var tiempo = 0;
function scrollUp (_id) {
	//
	
	var siguientePaso = $("#" + _id).attr("scrollTop") - paso;
	$("#" + _id).attr("scrollTop", siguientePaso);
	if (tiempo) {
		clearTimeout (tiempo);
	}
	tiempo = setTimeout("scrollUp('"+_id+"')", 20);
}

function scrollDown (_id) {
	
	var siguientePaso = $("#" + _id).attr("scrollTop") + paso;
	$("#" + _id).attr("scrollTop", siguientePaso);
	if (tiempo) {
		clearTimeout (tiempo);
	}
	tiempo = setTimeout("scrollDown('"+_id+"')", 20);
}

//
function scrollStop () {
	//
	clearTimeout (tiempo);
}

//
function configurarScrollTexto () {
	//
	$('#scrollUpButton').mousedown ( function (e) {
		//		
		scrollUp ("scrollText");
	}).mouseup ( function (e) {
		//
		scrollStop ();
	});
	
	$('#scrollDownButton').mousedown ( function (e) {
		//		
		scrollDown ("scrollText");
	}).mouseup ( function (e) {
		//
		scrollStop ();
	});
	
	$('#scrollUpButton').click ( function (e) {
		//
		return false;
	});
	
	$('#scrollDownButton').click ( function (e) {
		//
		return false;
	});
}
/*----------/EVENTS-----------------------------------------------*/


