﻿
// JScript File

function openLW(LWHref, LWWidth, LWHeight, Title) {

    $('a#FancyBoxClick').remove();
    $('body').prepend("<a id='FancyBoxClick' class='iframe2' title='" + Title + "' href='" + LWHref + "'></a> ");
    //LWWidth, LWHeight can be used as passed if required
    LWWidth = parseInt(stripAlphaChars(LWWidth));
    LWHeight = parseInt(stripAlphaChars(LWHeight));
    $(".iframe2").fancybox({
        'hideOnContentClick': false,
        'overlayColor': '#000',
        'overlayOpacity': '.8',
        'frameHeight': LWHeight,
        'frameWidth': LWWidth
    });
    $('a#FancyBoxClick').click();
    $('#fancy_overlay').css('opacity', .5);
}

function fancyClosed(){
    alert('im closed');
}

function stripAlphaChars(str) {
    str = str.replace(/\D/g, '');
    return str;
}
   
function closeLW() {
   $.fn.fancybox.close()
}

// call back from from display legacy adding to cart
function UpdateSideCarts() {
    $find($('#SideCart .radPanel').attr('id')).ajaxRequest("");

}

function sideCartCallBack() { // gets called by the ajax request on sidecart
    cartUpdatedCallback();
    $("#SlideCart").height(0);
    $('#SlideCartLiner').css('top', -1000);
    itemsInCart = $('#SlideCart div.item').size();
    
}

/*side cart code*/
var moveBy, mouseInHeader, mouseInSlider, itemsInCart;
//on dom ready
$(function () {
    if (!$("#SideCart").hasClass("stayDown")) {
        setPositionOfSlider();
        cartAnimation();
    }
    itemsInCart = $('#SlideCart div.item').size();
});

//called when the ajax request is complete
function cartUpdatedCallback() {

    if (itemsInCart != $('#SlideCart div.item').size()) {
        setPositionOfSlider();
        $("#SideCartItemAdded").fadeIn('slow', function () {
            setTimeout(function () { $("#SideCartItemAdded").fadeOut('slow') }, 1500);
            cartAnimation(); //restart the animation of the cart slider
        });
    } else {
        cartAnimation(); //restart the animation of the cart slider
    }
}

//move the sidecart drop down up the value of it's new height
function setPositionOfSlider() {
    $('#SlideCart').show();
    moveBy = $('#SlideCart').height();
    sliderUp();
    $('#SlideCartLiner').css('top', moveBy * -1).css('display', 'block');
   
}

//determines when to call slideup and slidedown  
function cartAnimation() {
    mouseInHeader = mouseInSlider = false;
    $('#SideCart').mouseenter(function () { mouseInHeader = true; sliderDown(); }).mouseleave(function () { mouseInHeader = false; sliderUp(); });
    $('#SlideCartLiner').mouseenter(function () { mouseInSlider = true; sliderDown(); }).mouseleave(function () { mouseInSlider = false; setTimeout(function () { if (mouseInHeader == false) { sliderUp(); } }, 1); });
}

//slides the cart up
function sliderUp() {
    setTimeout(function () {
        if (mouseInSlider == false) {

            $("#SlideCart").animate({ 'height': '0px' }, { duration: 1000, queue: false, complete: function () {  } });
            $('#SlideCartLiner').animate({ 'top': moveBy * -1 }, { duration: 1000, queue: false, complete: function () {  } });
        }
    }, 1);
}

//slides the cart down
function sliderDown() {
    if (!$("#SideCart > div").hasClass('emptyCart')) {
        $('.home .area6').hide();
        $("#SlideCart").css('width', $('#SideCart').width()).animate({ 'height': moveBy + 'px' }, { duration: 1000, queue: false }); $('#SlideCartLiner').animate({ 'top': 0 }, { duration: 1000, queue: false, complete: function () { } });
    }
}
/* end side cart code*/
RestartZoom = function () { };
validationHelpers = function () { };


//will clear text of textbox on focus and reset value to original if left empty
function resetTextValue(selector) {
    var txtVal = $(selector).val();
    $(selector).focus(function() {
        if ($(this).val() == txtVal) { $(this).val(''); }
    }).blur(function() {
        if ($(this).val() == '') { $(this).val(txtVal); }
    });
}



//DOM ready
$(function() {


    resetTextValue('#SearchBox input[type=text]');
    //DD_roundies.addRule('.validationSummary, #AddToCart, *', '5px', true);

    //add title attribute to match text to drop lists
    $('select option').each(function() {
        $(this).attr('title', $(this).text());
    });

    //Change Breadcrumb html
    var breadCrumbText = $('#BreadCrumb a.breadcrumb:last').text();
    $('#BreadCrumb a.breadcrumb:last').replaceWith('<span class="breadcrumb last">' + breadCrumbText + '</span>');



    //make the enter key hit the submit button in the right place
    $('.form input').live('keypress', function(e) {
        var code = (e.keyCode ? e.keyCode : e.which);
        if (code == 13) { //Enter keycode
            $(this).closest('.form').find('input.submit').click();
            e.preventDefault();
        }
    });

    $('input[type=text]').addClass('text');
    $('input[type=password]').addClass('password text');
    //    $('tr').filter(':odd').addClass('odd');
    //    $('tr').filter(':even').addClass('even');
    $('.items .item').filter(':even').addClass('even');
    $('.items .item:first').addClass('first');
    helpFAQ();

    $('.skuSelection a.addToCart').click(function(e) {
        e.preventDefault();

    });


    siteCustom();
    setUpTabs();

});

function addRowClasses() {
    $('tr').filter(':odd').addClass('odd');
    $('tr').filter(':even').addClass('even');
}

//called by on product display page on update
function swatchHelper() {
    $('.swatchItem img').siblings().addClass('sibling');
    $('.swatch img').siblings('span').addClass('sibling');
}

/* faq type expanding list*/
function helpFAQ() {
    $('div.faq div.wrap').hide();
    $('div.faq a').click(function(e) {
        e.preventDefault();
        $(this).parents('div.faq').find('div.wrap').slideUp();
        if ($(this).siblings().hasClass('down')) {
            $(this).css('background-position', '-279px 3px').siblings().slideUp().removeClass('down');
        } else {
            $(this).parents('div.faq').find('div.wrap').removeClass('down').siblings().css('background-position', '-279px 3px');
            $(this).css('background-position', '0px 3px').siblings().slideDown().addClass('down');
        }
    });
}

//Custom Stuff
function siteCustom() {
    //remove copyright text from footer
    var CopyInfo = $.trim($('#SiteCopy').html().toString());
    $('#SiteCopy').html(CopyInfo.substr(10, CopyInfo.length));
    $('body').removeClass('contentTitle');
}

function setUpTabs() {
    //Setup the client side tab menu control
    $("#TabSystem #Menu a").live('click',  function() { var index = $("#TabSystem #Menu a").removeClass("active").index($(this).addClass('active'));  $("#TabSystem .tab").hide().eq(index).show();
        return false; 
    });  
    $("#TabSystem a:first").click();
}



function selectTab() {
    setTimeout(function() { $("#TabSystem a.active").click(); }, 1);    
}






