/* http://cherne.net/brian/resources/jquery.hoverIntent.html */

function hideMega() {
    $(this).children(".mega-box").hide();
    $(this).removeClass("hover-nav");
}

function showMega() {
    var tabposition = $(this).position();
    if (tabposition.left > 429) {
        $(this).addClass("right-menu");
    }
    $(this).addClass("hover-nav");
    $(this).children(".mega-box").show();
}

var configHover = {
  //  interval: 300,
 //   sensitivity: 4,
    over: showMega,
    timeout: 200,
    out: hideMega
};



$(document).ready(function () {

    $("ul.dropdown > li").hoverIntent(configHover)
    $(".mega-subcats").easyListSplitter({
        colNumber: 3,
        direction: 'vertical'
    });

   $("#page-default #grid-wrap ul li.grid-prod-wrap:nth-child(3n)").addClass("grid-last-item-row");
   $("#page-category #grid-wrap ul li.grid-prod-wrap:lt(4)").addClass("grid-first-row");
   $("#page-category #grid-wrap ul li.grid-prod-wrap:nth-child(4n)").addClass("grid-last-item-row");
   $("#page-search #grid-wrap ul li.grid-prod-wrap:lt(4)").addClass("grid-first-row");
   $("#page-search #grid-wrap ul li.grid-prod-wrap:nth-child(4n)").addClass("grid-last-item-row");
   $("#page-nosearchresults #grid-wrap ul li.grid-prod-wrap:lt(4)").addClass("grid-first-row");
   $("#page-nosearchresults #grid-wrap ul li.grid-prod-wrap:nth-child(4n)").addClass("grid-last-item-row");

    setDefaultInputText();

    $( "#page-product .col1 .alt-image-carousel .scrollable" ).scrollable( { circular: true } );
    $( "#page-product #product-accordion" ).accordion( { autoHeight: false } );

    // create tabs
    var $tabs = $('#product-tabs').tabs()
    $('a.gotoreviews').click(function () {
        $tabs.tabs('select', 2);
        return false;
    });

    // lightbox dialogs
    $("a.zoom").fancybox({
        'titleShow': false,
        'transitionIn': 'fade',
        'transitionOut': 'fade'
    });

    $("a.dialog").fancybox({
        'width': 750,
        'height': 550
    });

    $("a.dialog-med").fancybox({
        'width': 550,
        'height': 450
    });

    $("a.dialog-small").fancybox({
        'width': 400,
        'height': 325
    });

    $("a.dialog-feedback").fancybox({
        'width': 640,
        'height': 525,
        margin:0,
        padding:0,
        'scrolling':'no'
    });

    // alternating colored rows
    $('table.cart-grid tr:even').addClass('alt');

    $("form#QuickOrderShoppingCartAdd").validate();

    // quick order
    $('a.back-link').click( function () {
        history.go(-1)
    });

});
