var menuhelper = {};

$(document).ready(function () {
	//$('a[id*="_sub"]').css('width','none');
	/*$('a[id*="_inicio"]').click(function(e) {
	    e.preventDefault();	  //return false		
	});*/

	$("#sidebarmenu1").children("li").hover(function(){
		
		$(this).parent().find('ul').css('display','none');
		$(this).parent().find('a').removeClass('encima');
				
		$(this).children("a").addClass('encima');
		
		var ul_h = $('ul', this).height();
		var ul_p = $('ul', this).position();
		var li_p = $(this).position();		
    	var tope =Math.floor(li_p.top)-(ul_h/2);
		
		/*-------* LIMITS *--------*/
		if ( tope < -10.5 ) { tope = -10.5;}
		if ( tope + ul_h > 428 ) { tope = tope - (  (tope + ul_h) - 428);}   	
		/*-----* END LIMITS *------*/
		
    	$('ul', this).css('top',tope);    	
		$('ul', this).css('display','block');
		
		menuhelper.over = true;	

	},function(){
		menuhelper.over = false;
		menuhelper.obj = this;
		setTimeout(function (){
			if (!menuhelper.over)
			{	
				$(menuhelper.obj).find('ul').css('display','none');
				$(menuhelper.obj).children("a").removeClass('encima');
			}
		},400);
		
	});
	$('#slides').slides({
		preload: true,
		generateNextPrev: false,
		play: 5000
	});
		
	
	//---------------------------------------------------
	
	$(".box-title").click(function(){
		if($(this).children('ul').css('display')=='none'){
			$(".box-title").each(function(){
				$(this).children('ul').slideUp(700);
			});
			$(this).children('ul').slideDown();
		}
	});
	
	//---------------------------------------------------
	/*$(".principal > li:has(ul)").bind('click',function(evt){
		console.log( $( this ).has('ul').length );
		$(this).find('> a').attr('href',"javascript:void(0);");
		if ( $(this).has('ul:visible').length > 0 )
		{
			$(this).find('ul:visible').slideUp();
		}
		else
		{
			$(".principal > li:has(ul:visible) ul:visible")
				.slideUp();
			$(this).find('ul:hidden').slideDown();
		}
	}).find('li:not(:has(ul)) a').bind('click',function(evt){
		evt.stopPropagation();
	});*/
	//---------------------------------------------------
	var hashes = window.location.href.slice(1,window.location.href.indexOf('.html') ).split('/').pop();
	$("#"+hashes).parent().css('display','block');
	// patch marc
	//$('.principal > li:has(ul:visible)').addClass('unfolded');
	//$('.principal > li:has(ul:hidden)').addClass('folded');
	$("#"+hashes+ " a").css('color','#004496');
	if(hashes == 'presentacion'){
		$(".box-mapa").css('display','block');
	}
});


