
// 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'); } });
  });
 
  $('#mycarousel').jcarousel({
    auto: 5,
    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", 100);
    $(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');
}
