function stopBubble(e) {
        var e = e || window.event;
        e.cancelBubble = true;   // stops IE
      if (e.stopPropagation) { // stops others
          e.stopPropagation();
      }
    }

function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}

function popitup(url,w,h) {
	newwindow=window.open(url,'legal','height='+h+',width='+w+',menubar=no,status=yes,location=no,toolbar=no,scrollbars=yes');
	
	if (window.focus) {newwindow.focus()}
	return false;
}

$(document).ready(function()
{
	
		$(window).load(function(){$('.sel ul').slideDown("slow");})

		//control del background 
		setBackSize();
		$(window).bind("resize",setBackSize);

		// sustitucion texto sfir
		$.sifr({
			path: 'swf/',
			save: true
		});	
		$('.tit-seccion').sifr({font:'optima'});		
		$('.subcabecera h3').sifr({font:'optima'});



		
		// se usa hover aunque este vacio a medias porque controla la propagacion
		//effecto hover en los span del menu
		$("#nav > li:not(.sel) .link-nav span").hover(
			function(){	
			//permite crecer al li para mostrar ul anidado y se muestra
//				$(this).parent().parent().css("height","auto").css("borderBottom","solid 1px transparent");	
				$(this).parent().parent().css("height","auto");	
				//si tiene segndo nivel
//				var auxNavUL = $(this).parent().parent().children("ul");
//						auxNavUL.parent().children("a").attr("class","sel-selector");
//						auxNavUL.stop(true,true).slideDown("slow");
			
				//efecto mas ancho y gris sobre el titular de cada seccion del menu
				$(this).stop(true,true).animate({opacity: 1}, "fast");
				$(this).parent().parent().stop(true,true).animate({ width: 171 }, 150);
			},function(){$(this).stop();})

		//mouseout
		$("#nav > li[@id^=btn]:not(.sel)").hover(function(){$(this).stop();},function(){
			// animo opacidad a 0
//			$(this).stop(true,true).animate({ width: 171 }, 150,function(){$(this).css("borderBottom","dashed 1px #c5c5c5");});			
			$(this).stop(true,true).animate({ width: 171 }, 150);			
			$(this).find("span").stop(true,true).animate({opacity: 0}, "slow");						
			closeDesplegado();
		});	
		
	
		//funcionalidad para mostrar definiciones // pantalla de Areas - maritimo
		$("#conceptos dt").each(function(indice){
			$(this).click(function(){
				var passText = $(this).parent().find("dd").html();				   								   
				$("#definicion").fadeOut("fast",function(){
				//carga nueva definicion
				$("#definicion").html(passText);																		 
				})				
				$("#definicion").fadeIn("fast");
				// cambiamos el flash
				getFlashMovie('Berge_Player').changeImage(indice+1);
			})	   										   
		})
		
		$(".aviso-legal a").bind("click",function(){
				popitup($(this).attr('href'),400,400);
				return false;
		})
		

			
});

closeDesplegado = function(){
	var obj = $(".sel-selector").parent();
	obj.find("ul").slideUp("slow");	
	obj.animate({ width: 171 }, 150,function(){$(this).css("borderBottom","dashed 1px #c5c5c5");});			
	obj.find("span").stop().animate({opacity: 0}, "slow");		
}


setBackSize =	function(){
		var actualH = $(window).height();
		var actualW = $(window).width();						
		if(actualW<=1004 || actualH<=613){
				//control min-height ie6
				$("body").addClass("small-body");
				
				$("#backgroundLayer").removeClass("desborde").addClass("no-desborde");
				
				//para forzar a que salgan las barras de scroll - elimina accion margen negativo
				if(actualH>613){
						 var top = ( $('.no-desborde').height() - 613) / 2;
						$('.no-desborde img').css('margin-top', top);					
					}else{
						$('.no-desborde img').css('margin-top', 0);
						}
			}else{
				browserWidth = $(window).width();
				browserWidth -= 215;				
				browserHeight = $(window).height();								
				
				//ancho 742  alto 437
				scaleX = browserWidth/1100;//762;
				scaleY = browserHeight/850;//498;					
				
				$("body").removeClass("small-body");
				
				if(scaleX>scaleY){
					$("#backgroundLayer").removeClass("no-desborde").addClass("desborde");
					$("#backgroundLayer img").css("width", "auto");																			
					$("#backgroundLayer img").css("height", browserHeight+"px");															
					}else{
						$("#backgroundLayer").removeClass("no-desborde").addClass("desborde");
						$("#backgroundLayer img").css("height", "auto");																											
						$("#backgroundLayer img").css("width", browserWidth+"px");		
						}

			}
}


// buscador de noticias
function buscaNoticias(){
	// cuando se cambia un valor del combo se llama a esta función
	var f = document.forms["buscadorNoticias"];
	f.submit();
}