var current_ul;
var menuEffect = 'fade';

$.fn.scrollableAddClones = function(addItems, sdiv) {
  // grab scrollable plugin
  var scrollable;
  if (!(scrollable = $(this).data('scrollable')) || !scrollable.getConf().circular)
      return;
  
  //scrollable = $("#home-carousel-ship .scroll1185").data('scrollable');
  //scrollable = $(sdiv).data('scrollable');
  
  // grab scrollable elements and remember it's count
  var nodes = scrollable.getItems();
  var length = nodes.length;
  // grab class for the nodes
  var clonedClass = scrollable.getConf().clonedClass;
  // get wrap object to append the clones to
  var wrap = scrollable.getItemWrap();
  // fill as much nodes as needed for 500 pixels
  if (!addItems) addItems = Math.ceil(500 / nodes.eq(1).width());
  // create fake container to add the clones to (max 15 clones)
  var newNodesAppend = $('<span />');
  for (var i = 1; i <= (addItems < 15 ? addItems : 15); i++)
    nodes.eq(i % length).clone().addClass(clonedClass).appendTo(newNodesAppend);
  // insert HTML
  newNodesAppend.children().appendTo(wrap);
}


function mainmenu(){

  $('.top-nav li.hasChildren').hover(function() {
    $(this).find('ul:first').stop().show();
}, function() {
  $(this).find('ul:first').stop().css({ display: "none" });
  });
}

function initsearch(){
  $('.search-submit').hover(function() {
    $(this).addClass('hover'); }, function() {
    $(this).removeClass('hover'); });
 
  $('.search-submit').click(function() {
    doSearch();
    e.preventDefault();
    });
  $(".search-text").keyup(function(e){
    if(e.keyCode == 13){
      doSearch();
      e.preventDefault();}
    });
  $('.search-text').val(urlParams['search']);
}

function doSearch(){
  var url = '/search.aspx?search=' + $('.search-text').val();
  window.location=url;
}


function initializeRequest(sender, args) {
  if (prm.get_isInAsyncPostBack())
   args.set_cancel(true);
  $('.ajax-form').block({ overlayCSS: { backgroundColor: '#fff'} });
}

function endRequest(sender, args) {
  $('.ajax-form').unblock();
}   

function fancyStart(){
  Cufon.replace('.fancybox-title-inside');
  Cufon.now();
}
$(document).ready(function(){

  mainmenu();
  initsearch();
  
  $(".fancybox").fancybox({
    //'titlePosition' : 'inside',
    'onStart': fancyStart
  });
  
  
    $("input.money").keypress(function (e) {
      if(e.which !=8 && e.which !=0 && (e.which < 48 || e.which > 57) ){
      return false;
      }
    });
 
  prm = Sys.WebForms.PageRequestManager.getInstance();
  prm.add_initializeRequest(initializeRequest);
  prm.add_endRequest(endRequest);
  Sys.Application.add_init(function() {
     $.blockUI.defaults.css = {};
  });
  
});


var urlParams = {};
(function () {
    var e,
        a = /\+/g,  // Regex for replacing addition symbol with a space
        r = /([^&=]+)=?([^&]*)/g,
        d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
        q = window.location.search.substring(1);

    while (e = r.exec(q))
       urlParams[d(e[1])] = d(e[2]);
})();

  
$(document).ready(function(){
  $("#ctl00_ctl00_ctl00_ContentPlaceHolderDefault_homeContent_ctrlHomePageProductsCarousel_dlCatalog").addClass('items');
      
  //Product Slide
  $(".product-slide").scrollable({ circular: false });
      $("a.product-next").click(function() {
        $('.product-slide').data("scrollable").next();    
        $('.product-slide').data("scrollable").next();
        $('.product-slide').data("scrollable").next();
        $('.product-slide').data("scrollable").next();
        $('.product-slide').data("scrollable").next();
        $('.product-slide').data("scrollable").next();
       // $('.product-slide').data("scrollable").next();
  });
        $("a.product-prev").click(function() {
          $('.product-slide').data("scrollable").prev();    
          $('.product-slide').data("scrollable").prev();    
          $('.product-slide').data("scrollable").prev();    
          $('.product-slide').data("scrollable").prev();    
          $('.product-slide').data("scrollable").prev();    
          $('.product-slide').data("scrollable").prev();    
          //$('.product-slide').data("scrollable").prev();    
  });
});
  

//Food News Slide
  function slideSwitch() {
    var $active = $('#food-news li.active');

    if ( $active.length == 0 ) $active = $('#food-news li:last');

    var $next =  $active.next().length ? $active.next()
        : $('#food-news li:first');

    $active.addClass('last-active').css({opacity: 0.0});

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1500, function() {
            $active.removeClass('active last-active');
        });
  }

  $(document).ready(function() {
    setInterval( "slideSwitch()", 3500 );
    $("#nav li a:first").css('padding-left', '0');
  });


  

