// JavaScript Document

//mostrar error de idioma
function cambiaFondo(capa,estado){
	if(estado==1){ //encima
		$("div#"+capa).css("background-color","#000000");
		$("div#"+capa+" a").css("color","#ffcc00");
	}else{
		$("div#"+capa).css("background-color","#333399");
		$("div#"+capa+" a").css("color","#FFFFFF");
	}
	
}
function abreSubseccion(url){
			document.location.href=url;
}

$(document).ready(function(){
						$("div#error_idioma").css("visibility","hidden");
					   
	if(seccion==0){
		//MOVER CAPA DE INICIO
		if($("div#contenidos_inicio").height()<$("div#foto_inicio_derecha").height()){
			$("div#noticias_inicio").css("top","320px");
			$("div#pie").appendTo("div#noticias_inicio"); //CONTROL DEL PIE
			$("div#pie").css("top","540px");//CONTROL DEL PIE
			$("div#pie").css("left","0px");//CONTROL DEL PIE

		}else{
			$("div#noticias_inicio").appendTo("div#contenidos_inicio");
			$("div#pie").appendTo("div#contenidos_inicio"); //CONTROL DEL PIE
			$("div#pie").css("top","-170px");//CONTROL DEL PIE
			$("div#noticias_inicio").css("left","-15px");
		}
			
		// MENU CABECERA
		
		$("div#menu_cabecera div").mouseover(
			function(){
				if (!$(this).is("div#bt_blog") && !$(this).is("div#fondo_blog") && !$(this).is(capa_menu)) {
					$(this).css("background","#333399");
					$(this).find("span.texto_menu").css("background","#333399");
				}
			}
		);
		$("div#menu_cabecera div").mouseout(
			function(){
				
				if (!$(this).is("div#bt_blog") && !$(this).is("div#fondo_blog") && !$(this).is(capa_menu)) {
					$(this).css("background","#ffcc00");
					$(this).find("span.texto_menu").css("background","#ffcc00");
				}
			}
		);
		//MENU ARRIBA
			$("div#menu_arriba div").mouseover(
				function(){
						$(this).find("a").css("color","#ffcc00");
				}
			);
			$("div#menu_arriba div").mouseout(
				function(){
						$(this).find("a").css("color","#333399");
				}
			);			
	}else{
		//CONTROL DEL PIE
		if($("div#menu_derecho").height()<$("div#contenidos_secciones").height()){
			$("div#pie").appendTo("div#contenidos_secciones");
			$("div#pie").css("top","30px");
			$("div#pie").css("left","0px");
		}else{
			$("div#pie").appendTo("div#menu_derecho");
			$("div#pie").css("top","30px");
			$("div#pie").css("left","-560px");
		}
		switch(seccion){
		
			case 1:
			var capa_menu="div#bt_nosotros";
			break;
			
			case 2:
			var capa_menu="div#bt_servicios";
			break;
			
			case 3:
			var capa_menu="div#bt_referencias";
			break;
			
			case 4:
			var capa_menu="div#bt_actualidad";
			break;
			
			case 5:
			var capa_menu="div#bt_descargas";
			break;
			
			case 6:
			var capa_menu="div#bt_enlaces";
			break;			
		
		}
		// MENU CABECERA
		$("div#menu_cabecera div").mouseover(
			function(){
				if (!$(this).is("div#bt_blog") && !$(this).is("div#fondo_blog") && !$(this).is(capa_menu)) {
					$(this).css("background","#333399");
					$(this).find("span.texto_menu").css("background","#333399");
				}
			}
		);
		$("div#menu_cabecera div").mouseout(
			function(){
				
				if (!$(this).is("div#bt_blog") && !$(this).is("div#fondo_blog") && !$(this).is(capa_menu)) {
					$(this).css("background","#ffcc00");
					$(this).find("span.texto_menu").css("background","#ffcc00");
				}
			}
		);
		//MENU ARRIBA
			$("div#menu_arriba div").mouseover(
				function(){
					if (!$(this).is(capa_menu)) {
						$(this).find("a").css("color","#ffcc00");
					}
				}
			);
			$("div#menu_arriba div").mouseout(
				function(){
					if (!$(this).is(capa_menu)) {
						$(this).find("a").css("color","#333399");
					}
				}
			);			
	}
	
	//ENLACES DE MENU CABECERA
	$("div#bt_nosotros").click(
		function(){
			var url = $('div#bt_nosotros a').attr('href'); 
			document.location.href=url;
		}
	);
	$("div#bt_servicios").click(
		function(){
			var url = $('div#bt_servicios a').attr('href'); 
			document.location.href=url;
		}
	);
	$("div#bt_referencias").click(
		function(){
			var url = $('div#bt_referencias a').attr('href'); 
			document.location.href=url;
		}
	);
	$("div#bt_blog").click(
		function(){
			var url = $('div#bt_blog a').attr('href'); 
			window.open(url);
		}
	);
	
	
	//ENLACES MENU ARRIBA
	$("div#bt_actualidad").click(
		function(){
			var url = $('div#bt_actualidad a').attr('href'); 
			document.location.href=url;
		}
	);
	$("div#bt_descargas").click(
		function(){
			var url = $('div#bt_descargas a').attr('href');
			document.location.href=url;
		}
	);
	$("div#bt_enlaces").click(
		function(){
			var url = $('div#bt_enlaces a').attr('href');
			document.location.href=url;
		}
	);
	$("div#bt_clientes").click(
		function(){
			var url = $('div#bt_clientes a').attr('href');
			window.open(url);
		}
	);
	
	//CONTROL DE ESTILOS EN SECCIONES
	
	switch(seccion){
		
		case 1:
		//NOSOTROS
		$("div#bt_nosotros").css("background","#333399");
		$("div#bt_nosotros span").css("background","#333399");
		$("div#cabecera").css("background-image","url(../imgs/nosotros/cabecera_nosotros1.jpg)");
		break;
		
		case 2:
		//SERVICIOS
		$("div#bt_servicios").css("background","#333399");
		$("div#bt_servicios span").css("background","#333399");
		$("div#cabecera").css("background-image","url(../imgs/servicios/cabecera_nosotros1.jpg)");
		break;
		
		case 3:
		//REFERENCIAS
		$("div#bt_referencias").css("background","#333399");
		$("div#bt_referencias span").css("background","#333399");
		$("div#cabecera").css("background-image","url(../imgs/referencias/cabecera_nosotros1.jpg)");

		break;
		
		case 4:
		//ACTUALIDAD
		$("div#bt_actualidad a").css("color","#ffcc00");
		break;
		
		case 5:
		//DESCARGAS
		$("div#bt_descargas a").css("color","#ffcc00");
		break;
		
		case 6:
		//ENLACES
		$("div#bt_enlaces a").css("color","#ffcc00");
		break;
		
	}
	
	//ajuste de posición de menu_derecho
	$(window).bind('scroll',AdjustPosition);



	function AdjustPosition(){
		if(typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			alto_pg = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			alto_pg = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			alto_pg = document.body.clientHeight;
		}
		var arriba = $("div#menu_derecho").css("top");
		var alto = $("div#menu_derecho")[0].offsetHeight;
		var alto2 = $("div#contenidos_secciones")[0].offsetHeight;
		var arriba_scroll = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
		var resta=alto_pg;
		if(alto2>alto_pg){ 
			var resta=(alto_pg-alto)-460;
			scroll_permitido= (alto2-alto)+(alto_pg/2);
		}else{ scroll_permitido= alto_pg-150;}
		
		if(arriba_scroll> 310 && arriba_scroll< scroll_permitido){
			$("div#menu_derecho").css("top",30+arriba_scroll + 'px');
		}else{
			if(!alto2>alto_pg){
			
				if(arriba_scroll< (310+alto)){
					$("div#menu_derecho").css("top",'310px');
				}
			}else{
				if(arriba_scroll< 310){
					$("div#menu_derecho").css("top",'310px');
				}
			}
		}
		
	}	
	
	
});
