var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);

$(document).ready(function(){
	$('#nav > ul > li').mouseover(function(){
		$(this).find('ul').css('display','block');
		$(this).children('a').addClass('nav-selected');
	});
	$('#nav > ul > li').mouseout(function(){
		$(this).find('ul').css('display','none');
		$(this).children('a').removeClass('nav-selected');
	});

});

function boxbuscar(){
	var boxbuscar=document.getElementById("boxbuscar");
	if(boxbuscar.style.display=="none"){
		//Effect.BlindDown(boxbuscar,{duration:0.5, queue: 'end'});
		$(boxbuscar).slideDown();
	}else{
		//Effect.BlindUp(boxbuscar,{duration:0.5, queue: 'end'});
		$(boxbuscar).slideUp();
	}

}

function boxasociados(){
	var boxasociados=document.getElementById("boxasociados");
	if(boxasociados.style.display=="none"){
		//Effect.BlindDown(boxasociados,{duration:0.5, queue: 'end'});
		$(boxasociados).slideDown();
	}else{
		//Effect.BlindUp(boxasociados,{duration:0.5, queue: 'end'});
		$(boxasociados).slideUp();
	}

}



/* Funciones para slideshow del home */

/* Funciones para slideshow  */


var start_frame=0;
var frame=0;
var t;

function start_slideshow() {
		var span_botones=document.getElementById("slideshow_titulos")
		for(var i=0;i<=end_frame;i++){
			span_botones.innerHTML=span_botones.innerHTML+"<a href='#' id='slideshow-titulo-"+i+"' class='slideshow-titulo' onclick='slideshow_goto("+i+"); return false;'>"+slide_titulos[i]+"</a>";
		}
		insert_slide();
		document.getElementById("slideshow-titulo-"+frame+"").className="slideshow-titulo-activo";

}

function insert_slide(){
	var delay=slide_delay[frame]*1000;
	var imgcode= '<div id="slideshow_frame" style="display:none;" >'+slide[frame]+'</div>';
	document.getElementById("slideshow").innerHTML=imgcode;
	$('#slideshow_frame').fadeIn(400);
	t=setTimeout(switch_slides(), delay);
}
 
function switch_slides() {
	frame=frame;
	return (function() {
	$('#slideshow_frame').fadeOut(400);
	document.getElementById("slideshow-titulo-"+frame+"").className="slideshow-titulo";
	if (frame == end_frame) { frame = start_frame; } else { frame = frame + 1; }
	document.getElementById("slideshow-titulo-"+frame+"").className="slideshow-titulo-activo";
	t=setTimeout("insert_slide();", 400);
		
	})
}

function slideshow_pause(){
	document.getElementById("slideshow_pause").style.display="none";
	document.getElementById("slideshow_play").style.display="block";
	clearTimeout(t);
}
function slideshow_play(){
	document.getElementById("slideshow_pause").style.display="block";
	document.getElementById("slideshow_play").style.display="none";
	document.getElementById("slideshow-titulo-"+frame+"").className="slideshow-titulo";
	if (frame == end_frame) { frame = start_frame; } else { frame = frame + 1; }
	document.getElementById("slideshow-titulo-"+frame+"").className="slideshow-titulo-activo";
	insert_slide();
}
function slideshow_goto(goto){
	document.getElementById("slideshow-titulo-"+frame+"").className="slideshow-titulo";
	frame = goto;
	document.getElementById("slideshow-titulo-"+frame+"").className="slideshow-titulo-activo";
	clearTimeout(t);
	insert_slide();
}
function slideshow_next(){
	clearTimeout(t);
	document.getElementById("slideshow-titulo-"+frame+"").className="slideshow-titulo";
	if (frame == end_frame) { frame = start_frame; } else { frame = frame + 1; }
	document.getElementById("slideshow-titulo-"+frame+"").className="slideshow-titulo-activo";
	t=setTimeout("insert_slide();", 400);
}
function slideshow_prev(){
	clearTimeout(t);
	document.getElementById("slideshow-titulo-"+frame+"").className="slideshow-titulo";
	if (frame == start_frame) { frame =end_frame; } else { frame = frame - 1; }
	document.getElementById("slideshow-titulo-"+frame+"").className="slideshow-titulo-activo";
	t=setTimeout("insert_slide();", 400);
}
/* Funciones para slideshow  */


//  ********************   funciones de uso general  ************************************

function toggle_slide(id){
	var elemento=document.getElementById(id);
	$(elemento).slideToggle();
}




function fauxpopup(ancho,alto){
	if(document.getElementById("capa").style.display=="block"){
		document.getElementById("capa").style.display="none";
		document.getElementById("fauxpp").style.display="none";
		document.getElementById("fauxpp").innerHTML="";
	}else{
		var arr_pagesize=getPageSize();
		var arr_pagescroll=getPageScroll();
		var top=arr_pagescroll[1]+150;
		var left=(arr_pagesize[0]-ancho)/2;
		document.getElementById("fauxpp").style.top=top+"px";
		document.getElementById("fauxpp").style.left=left+"px";
		document.getElementById("fauxpp").style.width=ancho+"px";
		document.getElementById("fauxpp").style.height=alto+"px";
		document.getElementById("capa").style.height=arr_pagesize[1]+"px";
		
		document.getElementById("capa").style.display="block";
		document.getElementById("fauxpp").style.display="block";
		
	}
}


var divid="";
function ajax_load(caja,url) {
	divid=caja;
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	  alert ("Su navegador no soporta AJAX!");
	  return;
	 } 
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
	
function GetXmlHttpObject() {
  var xmlHttp=null;
  try{// Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
   }
  catch (e){ // Internet Explorer
    try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
    catch (e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
   }
  return xmlHttp;
}

function stateChanged() {
/*
	if (xmlHttp.readyState==1){//request seteado
		document.getElementById(divid).innerHTML="<p>seteando</p>";
	}
	if (xmlHttp.readyState==2){//request enviado
		document.getElementById(divid).innerHTML="<p>enviado</p>";
	}
	if (xmlHttp.readyState==3){//requesten proceso
		document.getElementById(divid).innerHTML="<p>en proceso</p>";
	}
*/
	if (xmlHttp.readyState==4){//request completo
		document.getElementById(divid).innerHTML=xmlHttp.responseText;
	}
}

function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

