/* funciones para el menú */
var menuVinos;
var menuLicores;

function showMenu(mnu){
	switch(mnu){
		case 'vinos':
			$("#submenu_vinos").fadeIn();
			break;
		case 'licores':
			$("#submenu_licores").fadeIn();
			break;
	}	
}

function hideMenu(mnu,cond){
	switch(mnu){
		case 'vinos':
			menuVinos = setTimeout('$("#submenu_vinos").hide()',5);
			break;
		case 'licores':
			menuLicores = setTimeout('$("#submenu_licores").hide()',5);
			break;
	}	
}


/* funcion que contiene funcionamiento de drop down menu */
$.fn.droppy = function() {
  
  this.each(function() {
    
    var root = this, zIndex = 1000;
    
    function getSubnav(ele) {
      if (ele.nodeName.toLowerCase() == 'li') {
        var subnav = $('> ul', ele);
        return subnav.length ? subnav[0] : null;
      } else {
        return ele;
      }
    }
    
    function getActuator(ele) {
      if (ele.nodeName.toLowerCase() == 'ul') {
        return $(ele).parents('li')[0];
      } else {
        return ele;
      }
    }
    
    function hide() {
      var subnav = getSubnav(this);
      if (!subnav) return;
      $.data(subnav, 'cancelHide', false);
      setTimeout(function() {
        if (!$.data(subnav, 'cancelHide')) {
          $(subnav).hide();
        }
      }, 1);
    }
  
    function show() {
      var subnav = getSubnav(this);
      if (!subnav) return;
      $.data(subnav, 'cancelHide', true);
      $(subnav).css({zIndex: zIndex++}).show();
      if (this.nodeName.toLowerCase() == 'ul') {
        $(getActuator(this)).addClass('hover');
      }
    }
    
    $('ul, li', this).hover(show, hide);
    $('li', this).hover(
      function() { $(this).addClass('hover'); },
      function() { $(this).removeClass('hover'); }
    );
    
  });
  
};






/* funciones para el carousel */

function intval(v) {
	v = parseInt(v);
	return isNaN(v) ? 0 : v;
}

function carouselScrollRight(){
	clipArea = 408 + 10;
	listHeight = intval($("#productos-carousel-list").css("width"));
	pos = intval($("#productos-carousel-list").css("left"));
	if((listHeight + pos) > clipArea)
		$("#productos-carousel-list").animate({left:pos-136},'normal');
}

function carouselScrollLeft(){
	pos = intval($("#productos-carousel-list").css("left"));
	if(pos < -135)
		$("#productos-carousel-list").animate({left:pos+136},'normal');
}

currentDetalle = '';
function showProducto(e,id){
    switch(e){
		case 'show':
			if(currentDetalle != ''){
				$('#producto'+currentDetalle).hide();
				$('#sombra-producto-detalle').hide();
			}	
			$('#producto'+id).fadeIn('slow');
			$('#sombra-producto-detalle').fadeIn('slow');
			currentDetalle = id;
			break;
		case 'hide':
			$('#producto'+currentDetalle).fadeOut('slow');
			$('#sombra-producto-detalle').fadeOut('slow');
	}
}

$(document).ready( function() {
	/* se le asigna las clases a los ultimos submenu */
	$('ul#submenu_vinos li:last').addClass('last');
	$('ul#submenu_licores li:last').addClass('last');
	
	/* activa el submenu del submenu de lider */
	$('#mainNav').droppy();
							
	Productos_Array = $(".productos-carousel-item").get();
	$("#productos-carousel-list").css("width", (136 * Productos_Array.length) + 10 + "px");
} );


