// panel de menu inicio

var _autoclose;
var _t =0;
var _t2=0;
var block_width =885;
var _current_slider='';
$(document).ready(function(){
	//alert($(".contBloques").children().length);
	
	
	$(".menuInicio").mouseleave(function(){
		autoclose();	
	})
	
	$(".menuInicio").mouseover(function(){
		clearTimeout(_autoclose);
	})
	
	$(".btn_izq").click(function(){
				var sp= $(this).attr('rel');
				_current_slider =sp;
			
			_t2=0;
			
				if(_t+block_width== 0){
					$(this).fadeOut(); 
				}
				
				if( _t !=0 ){
					_t +=block_width; 
				 $("."+sp).animate({left:(_t) +'px'}, 500 );
				  $(".btn_der").fadeIn();
					
			}else{
					$(this).fadeOut();
				}
	})
	
	$(".btn_der").click(function(){
			var sp= $(this).attr('rel');
			_current_slider =sp;
		
	var n= cantidad_bloque( String( $("."+sp).children().length /5));

	$('.'+sp).css("width", (n*block_width) +'px' )

		if(_t2+2>= n){
			$(this).fadeOut(); 
		}
				if(_t2 < n-1){
			
					_t -=block_width; 		
					_t2++;
					  
					 $("."+sp).animate({left:_t+'px'}, 500 );
					  $(".btn_izq").fadeIn();
				}else{
				}		
		})
})


function closemenu(){
	$('.panelMenu').slideUp();	
}

function autoclose(){
	
_autoclose = setTimeout(function(){

	$(".panelMenu").slideUp('medium');
			 	  $(".btn_izq").fadeOut();
},100);

	
}
function change_menu(pos,e){
sreset()
 $(".contBloques").clearQueue();
	 var n= cantidad_bloque( String( $("."+e).children().length /5));
	
		 if(n > 1)  $(".btn_der").fadeIn();
		 
if($(".panelMenu").css("display") =='none'){
		$(".panelMenu").slideDown('medium')
	$(".contBloques").css("left",pos+'px');
}else{
	 $(".contBloques").animate({left: pos +'px'}, 200 );
}
}


function sreset(){
	try{
		 $("."+_current_slider).animate({left:0 +'px'}, 200 );

		 _t=0;
		 _t2=0;
	}catch(e){
			
	}
}


function cantidad_bloque(n){
	var s  = n.split(".");
	var c=0;

	if(s.length >1 ){
		c =parseInt(s[0])+1;		
	}else{
		c =s[0];
	}
	return c
}
