
/********************************************************************/
//** Cargador de menus
/********************************************************************/
function loadMenu(idmenu,idsubmenu)
{
	idsubmenu =  (typeof idsubmenu=='undefined') ? 0 : idsubmenu;

	if ($("#menuContainer").html()==null)
		window.location.href = "contenidos.html?"  + idmenu +',' + idsubmenu;

	$("#menuContainer").animate({ height:'30'},{queue:false, 
												complete: function () { $("#menuContainer").css('visibility','hidden'); 
																		$("#menuContainer").load( "menus/" + idmenu + ".menu", function (){onMenuLoaded(idsubmenu)}); }     }); 
	
	return false;
}


function onMenuLoaded(idsubmenu)
{
	$("#menuContainer").animate({ height:'440'},{queue:true}); 
	$("#menuContainer").css('display','inline');
	$("#menuContainer").css('visibility','visible');
	
	slideMenu("#sliding-navigation", 25, 15, 150, .8)

	if (idsubmenu==0)
			setTimeout('$("#menuContainer a:first").click()',500);
	else
			$("#menuContainer a[href*='" + idsubmenu + "']").click();
		

	
}


/********************************************************************/
//** Efectos de menu
//* <descripcion>
/********************************************************************/

var lastselected = '';


function slideMenu(navigation_id, pad_out, pad_in, time, multiplier)
{
	// creates the target paths
	var list_elements = navigation_id + " li.sliding-element";
	var link_elements = list_elements + " a";
	
	// initiates the timer used for the sliding animation
	var timer = 0;
	
	// creates the slide animation for all list elements 
	$(list_elements).each(function(i)
	{
		// margin left = - ([width of element] + [total vertical padding of element])
		//$(this).css("margin-left","5px");
		// updates timer
		timer = (timer*multiplier + time);
		$(this).animate({ marginLeft: "-=10" }, timer);
		$(this).animate({ marginLeft: "+=15px" }, timer);
		$(this).animate({ marginLeft: "-=10" }, timer);
	});

	// creates the hover-slide effect for all link elements 		
	$(link_elements).each(function(i)
	{

		$(this).hover(
		function()
		{
			$(this).animate({ paddingLeft: pad_out }, 150);
		},		
		function()
		{
			$(this).animate({ paddingLeft: pad_in }, 150);
		});


		$(this).click(
		function()
		{
			url = $(this).attr('href');
			
			if (url=='#' || url=='') return false;
			
			$(lastselected).removeClass("selected"); 
			lastselected = $(this);
			$(this).addClass("selected"); 
			
			if ( jQuery.browser.msie)  $("#frmContenidos .titulo_pagina").css({visibility:'hidden'});
			$("#frmContenidos").animate({ opacity:0}, { duration: 500, queue: true,
										 complete : function () {
										 $("#frmContenidos").load(url);
										 if ( jQuery.browser.msie)  $("#frmContenidos .titulo_pagina").css({visibility:'hidden'});
										 $("#frmContenidos").animate({ opacity:1}, 
										 							 { queue: true, 
										 							   complete: function(){ if ( jQuery.browser.msie) $("#frmContenidos ").css({filter:'none'}); 
										 							 						 if ( jQuery.browser.msie) $("#frmContenidos .titulo_pagina").css({filter:'none',visibility:'visible'}); }   } )
										}
			});
			
			
			
			return false;
		});


	});



}




function slideClass(navigation_id, pad_out, pad_in, time, multiplier)
{
	// creates the target paths
	var list_elements = navigation_id ;
	var link_elements = navigation_id;
	
	// initiates the timer used for the sliding animation
	var timer = 0;
	
	// creates the slide animation for all list elements 
	$(list_elements).each(function(i)
	{
		// margin left = - ([width of element] + [total vertical padding of element])
		//$(this).css("margin-left","5px");
		// updates timer
		padding_step = Math.abs(pad_out-pad_in);
		timer = (timer*multiplier + time);
		$(this).animate({ right: "-=" + padding_step }, timer);
		$(this).animate({ right: "+=" + padding_step  }, timer);
		$(this).animate({ right: "-=" + padding_step  }, timer);
	});

	// creates the hover-slide effect for all link elements 		
	$(link_elements).each(function(i)
	{
		$(this).hover(
		function()
		{
			$(this).animate({ right: pad_out }, 150);
		},		
		function()
		{
			$(this).animate({ right: pad_in }, 150);
		});

	});

}


function slideInfo(navigation_id, pad_out, pad_in, time, multiplier)
{
	// creates the target paths
	var list_elements = navigation_id + "";
	var link_elements = list_elements + "";
	
	// initiates the timer used for the sliding animation
	var timer = 0;
	
	// creates the slide animation for all list elements 
	$(list_elements).each(function(i)
	{
		// updates timer
		timer = (timer*multiplier + time);
		$(this).animate({ marginTop: "-=10px" }, timer);
		$(this).animate({ marginTop: "+=10px" }, timer);
	});

	// creates the hover-slide effect for all link elements 		
	$(link_elements).each(function(i)
	{
		$(this).hover(
		function()
		{
			$(this).animate({ marginLeft: pad_out}, {duration:550, queue: false, easing:'easeInOutElastic'});
		},		
		function()
		{
			$(this).stop().animate({ marginLeft: pad_in },{duration:150, queue: false, easing:'linear'});
		});


		$(this).click(
		function()
		{
			
			return false;
		});


	});



}




function slideScroll(navigation_id, scrolltype, spause, sduration, stostart)
{

	stostart= typeof stostart=='undefined' ? 5000 : stostart;	
	sduration= typeof sduration=='undefined' ? 5000 : sduration;	
	spause= typeof spause=='undefined' ? 2000 : spause;	
	// initiates the timer used for the sliding animation
	var timer = 0;
	navW = $(navigation_id).parent().css('width').replace('px','');
	navH = $(navigation_id).parent().css('height').replace('px','');

//alert('' + $(navigation_id).parent().css('width') + ',' + $(navigation_id).parent().css('height') + ',' + $(navigation_id).parent().css('top') + ',' + $(navigation_id).parent().css('left') + '');

	opfrom = 1; opto= 1; 
	
	switch (scrolltype)
	{
		case 'scrollupIn': 
				dfrom = {top:0, left:0}; dto = {top:-navH, left:0};
		break;
		case 'scrollupOut': 
				dfrom = {top:-navH, left:0}; dto = {top:-2*navH, left:0};
		break;


		case 'scrolldownIn': 
				dfrom = {top:-2*navH, left:0}; dto = {top:-navH, left:0};
		break;
		case 'scrolldownOut': 
				dfrom = {top:-navH, left:0}; dto = {top:0, left:0};
		break;

		case 'scrollleftIn': 
				dfrom = {top:-navH, left:2*navW}; dto = {top:-navH, left:0};
		break;
		case 'scrollleftOut': 
				dfrom = {top:-navH, left:0}; dto = {top:-navH, left:-2*navW};
		break;


		case 'scrollrightIn': 
				dfrom = {top:-navH, left:-navW}; dto = {top:-navH, left:0};
		break;
		case 'scrollrightOut': 
				dfrom = {top:-navH, left:0}; dto = {top:-navH, left:navW};
		break;

		case 'fadeIn': 
				dfrom = {top:-navH, left:0}; dto = {top:-navH, left:0};
				opfrom = 0; opto=1;
		break;
		case 'fadeOut': 
				dfrom = {top:-navH, left:0}; dto = {top:-navH, left:0};
				opfrom=1; opto=0;
		break;
	}
	
	scrollMove();
	
	
	function scrollMove ()
	{
		$(navigation_id).css({top:dfrom.top, left:dfrom.left, opacity:opfrom});
		$(navigation_id).animate(
						 { top:dto.top, left:dto.left, opacity:opto}, 
						 { duration: sduration, 
						   queue: true,
						   easing:'linear',
						   complete: function () {
							   			scrolltype =  scrolltype.indexOf('In')!=-1 ? scrolltype.replace('In','Out') : scrolltype.replace('Out','In');
										sdelay = scrolltype.indexOf('In')!=-1 ? stostart : spause;
										
										setTimeout(function() {slideScroll(navigation_id, scrolltype, spause, sduration)  }, sdelay);
									  } 
						 });
	
	
	}

}
