/*
 * autor : NGAMEZ
 * fecha : 03/08/2011
 * descripción: Comportamiento del menú vertical desplegable * 
 * 
 * MODIFICACIÓN: 16/01/2012 AUTOR: CORTIZ
 * DESCRIPCIÓN : Creación de función browserVersionControl
 *
 * */

 $(document).ready(function(){ 
	$("a.menuVertical").toggle(
		function() {
			/*si empiezan visibles para ocultar*/
			$(this).parent().parent().next("ul.menuVertical").slideUp('slow'); 
		},
		function() {
			/*si empiezan visibles para mostrar*/
			$(this).parent().parent().next("ul.menuVertical").slideDown('slow'); 
		}
		
	);
	
	// POSICION DEL FOOTER (BARRA INFORMATIVA LABEL)
	posicionarBarraInferior();
	redimContentCentral();
	posicionarColumnasLaterales();
});
 
 function redimContentCentral(){
	var heightCabeceraYPie = 102; 
	var height = ($(window).height() - heightCabeceraYPie); // 420; //
	var heightFinal = (height < 350) ? 350 : height;
	$("#bodys").css("min-height", heightFinal + "px").css("height", "auto !important")
}

function posicionarBarraInferior(){
	//$(".botombodys").css("top", ($(window).height() + $(window).scrollTop()) - 22);
}

var blnTrabajando = false;
function posicionarColumnasLaterales(){
	var initialTop = 93;
	var scrollTop = $(window).scrollTop();
	var els = $("#menuRight, #menuLeft, #recommendedProduct");
	if(blnTrabajando){
		els.stop();
		blnTrabajando = false;
	}
	
	blnTrabajando = true;
	var finalTop = (scrollTop < initialTop) ? initialTop : (scrollTop + 15);
	els.animate({"top": finalTop }, 600, function(){
		blnTrabajando = false;
	});
}

$(window).resize(function(){redimContentCentral();posicionarBarraInferior()});
$(window).scroll(function(){posicionarBarraInferior();posicionarColumnasLaterales();}); 

/*abrir ventana con iframe para imagenes , videos , url externas , mapas , etc.*/
function abrirVentanaIframe(urlDestino, anchoVentana, altoVentana, anchoIframe, altoIframe)
{		
	anchoVentana = (typeof anchoVentana == "undefined" || anchoVentana == null)? "800px" : anchoVentana;
	altoVentana  = (typeof altoVentana  == "undefined" || altoVentana  == null)? "600px" : altoVentana;
	anchoIframe  = (typeof anchoIframe  == "undefined" || anchoIframe  == null)? "800px" : anchoIframe;
	altoIframe   = (typeof altoIframe   == "undefined" || altoIframe   == null)? "580px" : altoIframe;
	
	var numAnchoVentana = parseInt(anchoVentana.replace("px", ""));
	var leftVentana   =  "-" + Math.round((numAnchoVentana/2)).toString() + "px";
	var leftBtnCerrar = Math.round((numAnchoVentana-20)).toString() + "px";
		
	//urlDestino = (urlDestino.indexOf(".jpg") == -1)? urlDestino : urlDestino.replace("index.php/","");
	
	document.getElementById('capaVentanaPrincipal').style.visibility="visible";
	document.getElementById('capaVentanaInterna').style.visibility="visible";
	posicionUltimoPunto=urlDestino.lastIndexOf(".");
	
	parent.document.getElementById("iframeVentana").style.width		  = anchoVentana;
	parent.document.getElementById("iframeVentana").style.height	  = altoIframe;
	parent.document.getElementById("capaVentanaInterna").style.width  = anchoIframe;
	parent.document.getElementById("capaVentanaInterna").style.height = altoVentana;
	parent.document.getElementById("iframe").style.width			  = anchoIframe;
	parent.document.getElementById("iframe").style.height			  = altoIframe;
	parent.document.getElementById("closer").style.left				  = leftBtnCerrar;
	parent.document.getElementById("capaVentanaInterna").style.left=leftVentana;
	document.getElementById('iframeVentana').src = urlDestino;
	
	/*if(posicionUltimoPunto!=-1)
	{
		extension=urlDestino.slice(posicionUltimoPunto - urlDestino.length);
		extension=extension.toLowerCase();
		
		//para controlar tipo de destino
		if((extension==".png")||(extension==".jpg")||(extension==".gif")||(extension==".jpeg"))
			{						
				aray=urlDestino.split("public");
				
				//document.getElementById('iframeVentana').src = aray[0] + "index.php/" + "es/imagengrande/url/" + urlvideo;
				document.getElementById('iframeVentana').src = aray[0] + "index.php/" + "es/imagengrande/url/" + urlDestino;
			}
		else
			{		
			
				parent.document.getElementById("iframeVentana").style.width		  = anchoVentana;
				parent.document.getElementById("iframeVentana").style.height	  = altoIframe;
				parent.document.getElementById("capaVentanaInterna").style.width  = anchoIframe;
				parent.document.getElementById("capaVentanaInterna").style.height = altoVentana;
				parent.document.getElementById("iframe").style.width			  = anchoIframe;
				parent.document.getElementById("iframe").style.height			  = altoIframe;
				parent.document.getElementById("closer").style.left				  = leftBtnCerrar;
				parent.document.getElementById("capaVentanaInterna").style.left=leftVentana;
				document.getElementById('iframeVentana').src = urlDestino;
			}
		
	}
	else
	{
		document.getElementById('iframeVentana').src = urlDestino;
	}*/
	
}
/*cerrar ventana con iframe*/
function cerrarVentanaIframe()
{
	document.getElementById('capaVentanaInterna').style.visibility="hidden";
	document.getElementById('capaVentanaPrincipal').style.visibility="hidden";
	document.getElementById('iframeVentana').src = "";
}

function verificarCondiciones()
{		
	if(document.getElementById('aceptarCondiciones').checked==true)
	{
		document.getElementById('submitEnviar').disabled=false;
		$('#submitEnviar').removeClass('disabledButton');
	}
	else
	{
		document.getElementById('submitEnviar').disabled=true;
		$('#submitEnviar').addClass('disabledButton');
	}		
}

//Returns the version of Windows Internet Explorer or a -1
//(indicating the use of another browser).
function getInternetExplorerVersion()
{
	var rv = -1; // Return value assumes failure.
	if (navigator.appName == 'Microsoft Internet Explorer')
	{
	   var ua = navigator.userAgent;
	   var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
	   if (re.exec(ua) != null)
	      rv = parseFloat( RegExp.$1 );
	}
	return rv;
}


function browserVersionControl(explorador,version){
	if(explorador == "Internet Explorer"){	    				
		if(version == "6.0"){
			alert("La Web esta optimizada para versiones posteriores a " + explorador + " " + version);    				
		}
		if(version == "8.0" || version == "7.0"){
			alert("Usted está utilizando " + explorador + " " + version + ",esta versión es antigua, actualice su navegador a la versión más reciente posible para una mejor experiencia y más seguridad");			
			
		}
	} 
}

