/*Funciones de Menus*/

$(document).ready(inicializarJquery);



function inicializarJquery()
{
		rules_menus.init();
		$(".redo1").corner("1px");
		$(".redo2").corner("2px");
		$(".redo3").corner("3px");
		$(".redo4").corner("4px");
		$(".redo5").corner("5px");


		$('.lstpais').selectbox();
		$('#lstorden').selectbox();
		
		$(".carrouselGalerias").jCarouselLite({
        btnNext: ".carButtonG.next",
        btnPrev: ".carButtonG.prev",
		visible: 5,
		circular: false
    });

		inicializarEfectosAjax();
}



function inicializarEfectosAjax()
{
		
		//$(".encNoticia1").sifr({path:"/flash/fonts/",font:"bentonsanscondbold",version:3,preventWrap:true});
		//$(".encNoticia420").sifr({path:"/flash/fonts/",font:"bentonsanscondbold",version:3,width:420});
		//$(".encNoticia360").sifr({path:"/flash/fonts/",font:"bentonsanscondbold",version:3,width:360});
		//$(".encNoticia198").sifr({path:"/flash/fonts/",font:"bentonsanscondbold",version:3,width:198});
		$("a.singleImage").fancybox(); 
		$("a.fcVideo").fancybox({frameWidth:600,frameHeight:400,callbackOnClose:fcVideoOnClose}); 
		$("a.fcFlash").fancybox({frameWidth:640,frameHeight:480,callbackOnClose:fcVideoOnClose});
		$("a.fcGaleria").fancybox({frameWidth:700,frameHeight:700}); 
		$("a.fcImagen").fancybox();
		$("#tablatar").jScrollPane();
		$("a.fcEnlace").attr("target","_blank");
		$("a.fcPagina").fancybox({frameWidth:700});
		$(".desa a").click(function() {
				
				if($(this).attr("href").indexOf("//")>=0)
					$(this).attr("target","_blank");
				return true;
		});
		
}

function fcVideoOnClose()
{
	$("#fancy_frame").attr('src','blank.htm');
}

rules_menus = {
	
	currentSel:"1",
	current:0,
	init : function()
	{
		
		$("#Menu li a").mouseenter(rules_menus.entradaMenu);
		$("#Menu li a").click(rules_menus.clickMenu);
		$("#Menu ul.menuItemUl li a[submenu='" +rules_menus.currentSel+ "']").addClass("current");
		rules_menus.current=$("#Menu ul.menuItemUl li a[submenu='" +rules_menus.currentSel+ "']").eq(0);
		$("#subMenu_"+rules_menus.currentSel).show();

	},
	entradaMenu : function()
	{

		var nsubmenu=$(this).attr("submenu");
		if(rules_menus.currentSel!=nsubmenu)
		{

			$("#subMenu_"+rules_menus.currentSel).stop().css("opacity", 1).hide();
			if(rules_menus.current) $(rules_menus.current).removeClass("current");		
			$(this).addClass("current");
			$("#subMenu_"+nsubmenu).fadeIn(300);
			rules_menus.currentSel=nsubmenu;
			
			
			rules_menus.current=this;

		}
		

	},
	clickMenu: function()
	{
		$(this).addClass("current");
		return true;
	}
	
}


rules_rotatorHome = {
	seleccion:function(){
		if(rules_rotatorHome.locked==0)
		{
			

			var numero=parseInt($(this).text())-1;
			rules_rotatorHome.ocultar(rules_rotatorHome.current);
			rules_rotatorHome.current=numero;
			rules_rotatorHome.selector(numero);

			clearTimeout(rules_rotatorHome.timer);
			rules_rotatorHome.timer=setTimeout(rules_rotatorHome.rotate,15000);
		}
			return false;
	},
	init : function(){
		var numero=$(".Xrotator").length;
		rules_rotatorHome.cantidad=numero;
		var i;
		for(i=1;i<=numero;i++)
		{
		var cadena="<li class=btnRotator> |&nbsp;&nbsp;<a href='javascript:void();' class=btnSel>" + i + "</a>" + (i==numero?"&nbsp;&nbsp;| ":"&nbsp;&nbsp;") + "</li>";
		$("#rotatore").append(cadena);
		}
		$(".btnSel").click(rules_rotatorHome.seleccion);
		$(".btnSel").eq(0).addClass("RSelected");
		$(".Xrotator").eq(0).show();
		rules_rotatorHome.timer=setTimeout(rules_rotatorHome.rotate,5000);

	},
	rotate:function()
	{
		rules_rotatorHome.ocultar(rules_rotatorHome.current);
		rules_rotatorHome.current++;
		if(!(rules_rotatorHome.current<rules_rotatorHome.cantidad))
			rules_rotatorHome.current=0;

		rules_rotatorHome.selector(rules_rotatorHome.current);
		rules_rotatorHome.timer=setTimeout(rules_rotatorHome.rotate,5000);
	},
	ocultar: function(num)
	{
		//var obs=$(".Xrotator").eq(num);
		//obs.css("zIndex","-1");
		//obs.hide();
		$(".Xrotator").eq(num).hide().css("zIndex","-1").css("position","relative").css("left","595px").css("top","0px").css("width","0px");
	},

	selector: function(num)
	{
			var obs;
			$(".btnSel").removeClass("RSelected");
			//$(".Xrotator").hide();
			$(".btnSel").eq(num).addClass("RSelected");

			//Debemos iniciar (play) si hay un object en el rotator
			obs=$(".Xrotator").eq(num).find("object");
			if(obs.length==1)
			{
				var rot=$(".Xrotator").eq(num);
				var tx=rot.html();
				rot.html("");
				rot.html(tx);
			}
			rules_rotatorHome.locked=1;
			$(".Xrotator").eq(num).hide().css("zIndex","1").css("position","relative").css("left","595px").css("top","0px").css("width","0px");
			$(".Xrotator").eq(num).show().animate({left:"0px",width:"595px"},1000,function() {rules_rotatorHome.locked=0;} );
			
			//$(".Xrotator").eq(num).find("object").each(function() { this.play();});
			//$(".Xrotator").eq(num).find("embed").each(function() { this.play();});
			
	},
	current:0,
	cantidad:0,
	locked:0
};

$(document).ready(rules_rotatorHome.init);

//Fix FancyBox:

  var zmax = 0 ;
   
   function buildZMax() {
     $('*').each(function() {
       var cur = parseInt($(this).css('zIndex'));
       zmax = cur > zmax ? $(this).css('zIndex') : zmax; 
     });
   }

   function goFancy() {
     buildZMax();

     // Get all the outermost fancy_wrap id'ed objects built by the FancyBox calls
     // ...then bump the z-index to whatever the highest we found, plus 1
		 $('#fancy_wrap').each(function() {
		   zmax = zmax + 1 ;
		   $(this).css("z-index", zmax);

		   // Get the overlay children in each iteration of the outer 
		   // ...fancy_wrap, bump it's z-index up.
			   $(this).children("div#fancy_overlay").each(function() {
				 zmax = zmax + 1 ;
				 $(this).css("z-index", zmax);
			   });

		   // And again for another major child div
		   zmax = zmax + 1 ;
			   $(this).children("div#fancy_outer").each(function() {
				 zmax = zmax + 1 ;
				 $(this).css("z-index", zmax);
			   });
		 });
	 };