
// the vars
var delay=5;
var dropDelay=400;
var dropped=false;
var dropHeight=310;

// the jquery
$(document).ready(function (){

  window.setTimeout('fadeMessages()', 5000);

  $("a[rel='colorbox']").colorbox();

  $('.basket-nav .basket').mouseover(function(e){
    $(this).addClass('over');
    $(this).stop().animate({height:'380px'},{queue:false, duration:600});
  });
  $('.basket-nav .basket').mouseout(function(e){
    $(this).stop().animate({height:'80px'},{queue:false, duration:200, complete: function(e){ $(this).removeClass('over'); } });
  });
  /*
  $('.big-nav .lingerie').mouseover(function(e){
      $(this).addClass('over');
      //$('#header .dropdown.lingerie').stop().animate({height: dropHeight+'px'},{queue:true, duration:400});
      $('#header .dropdown.lingerie').css('z-index', 600);
      $('#header .dropdown.lingerie').show();
  });
  $('.big-nav .swimwear').mouseover(function(e){
      $(this).addClass('over');
      //$('#header .dropdown.swimwear').stop().animate({height: dropHeight+'px'},{queue:true, duration:400});
      $('#header .dropdown.swimwear').css('z-index', 600);
      $('#header .dropdown.swimwear').show();
  });
  $('.big-nav .care-products').mouseover(function(e){
      $(this).addClass('over');
      //$('#header .dropdown.care-products').stop().animate({height: dropHeight+'px'},{queue:true, duration:400});
      $('#header .dropdown.care-products').css('z-index', 600);
      $('#header .dropdown.care-products').css('display', 'block');
  });
  $('.big-nav .lingerie').mouseout(function(e){
    window.setTimeout('closeDropdown("#header .dropdown.lingerie", ".big-nav .lingerie")', delay);
  });
  $('.dropdown.lingerie').mouseout(function(e){
    window.setTimeout('closeDropdown("#header .dropdown.lingerie", ".big-nav .lingerie")', delay);
  });

  $('.big-nav .swimwear').mouseout(function(e){
    window.setTimeout('closeDropdown("#header .dropdown.swimwear", ".big-nav .swimwear")', delay);
  });
  $('.dropdown.swimwear').mouseout(function(e){
    window.setTimeout('closeDropdown("#header .dropdown.swimwear", ".big-nav .swimwear")', delay);
  });

  $('.big-nav .care-products').mouseout(function(e){
    window.setTimeout('closeDropdown("#header .dropdown.care-products", ".big-nav .care-products")', delay);
  });
  $('.dropdown.care-products').mouseout(function(e){
    window.setTimeout('closeDropdown("#header .dropdown.care-products", ".big-nav .care-products")', delay);
  });

  $(".dropdown").mouseover(function(e){$(this).addClass("mouseOver");});
  $(".dropdown").mouseout(function(e){$(this).removeClass("mouseOver");});
  $(".big-nav ul li a").mouseover(function(e){$(this).addClass("mouseOver");});
  $(".big-nav ul li a").mouseout(function(e){$(this).removeClass("mouseOver");});

  */
  $('#mycarousel').jcarousel({
    auto: 3,
    wrap: 'both',
    initCallback: mycarousel_initCallback,
    scroll: 1
  });

});

// the close function
function closeDropdown(element, parent){
  if (!$(element).hasClass("mouseOver") && !$(parent).hasClass("mouseOver")) {
    $(element).css("z-index", 500);
    $(element).css("display", 'none');
    $(parent).removeClass("over");
    /*$(element).stop().hide('fast', function() {
      $(parent).removeClass("over");
      dropped=false;
    });*/
  }
}

// carousel thing
function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};


function selectVariant(id){
  // remove previous 'active' one, if any..
  if(parseInt( $('#add_to_basket_shop_product_option_id').val() )>0){
    // remove
    $('#variant-option-'+parseInt($('#add_to_basket_shop_product_option_id').val()) ).removeClass('active');
  }
  // set selected value
  $('#add_to_basket_shop_product_option_id').val(id);
  // make active
  $('#variant-option-'+id).addClass('active');
}


function fadeMessages(){
  $('.flashMessage').slideUp('normal');
}
