$(document).ready(function () {
    showMiniCart();
    //news ticker initialization
    $("#scroller").simplyScroll({
        autoMode: 'loop'
    });
    $('.secondaryBG').css({ opacity: 0.90 });
    $('.headerRight .searchBox .searchSubmit, .footer .searchBox .searchSubmit').hover(function () {
        $(this).toggleClass('hover');
    });
    //This line is important to make the undelrine decoration possible on primary Navigation.
    $('.primaryNav > li > a').attr('rel', 'immediate');

    //Search input dissapearing & re-appearing script
    $(".headerRight .searchBox .searchInput").focus(function () {
        if ($(this).attr("value") == "Product Search")
        { $(this).attr("value", ""); }
    }); $(".headerRight .searchBox .searchInput").click(function () {
        if ($(this).attr("value") == "Product Search")
        { $(this).attr("value", ""); }
    }); $(".headerRight .searchBox .searchInput").blur(function () {
        if ($(this).attr("value") == "")
        { $(this).attr("value", "Product Search"); }
    });

    //Search input dissapearing & re-appearing script
    $("#footerSearchInput").focus(function () {
        if ($(this).attr("value") == "ENTER YOUR EMAIL FOR SPECIAL OFFERS")
        { $(this).attr("value", ""); }
    }); $("#footerSearchInput").click(function () {
        if ($(this).attr("value") == "ENTER YOUR EMAIL FOR SPECIAL OFFERS")
        { $(this).attr("value", ""); }
    }); $("#footerSearchInput").blur(function () {
        if ($(this).attr("value") == "")
        { $(this).attr("value", "ENTER YOUR EMAIL FOR SPECIAL OFFERS"); }
    });

    //Dynamically specifying height to seconbdaryBG element
    var womenHeight = $('.primaryNav > li#WOMEN').find('.secondaryNav').height();
    var menHeight = $('.primaryNav > li#MEN').find('.secondaryNav').height();
    var yourfitHeight = $('.primaryNav > li#yourFit').find('.secondaryNav').height();
    var inTheMediaHeight = $('.primaryNav > li#inTheMedia').find('.secondaryNav').height();
    var whoWeAreHeight = $('.primaryNav > li#whoWeAre').find('.secondaryNav').height();
    //alert(Math.max(womenHeight,menHeight);
    var secondaryBGHeight = (Math.max(womenHeight, menHeight, yourfitHeight, inTheMediaHeight, whoWeAreHeight));
    $('.secondaryBG').css({ height: secondaryBGHeight + 'px' });
    //$('.primaryNav > li:last-child').css({marginRight: '0'});

    $('.primaryNav > li#WOMEN,.primaryNav > li#MEN,.primaryNav > li#yourFit,.primaryNav > li#inTheMedia, .primaryNav > li#whoWeAre').hover(
		function () {
		    $('.secondaryBG').addClass('showBG');
		},
		function () {
		    $('.secondaryBG').removeClass('showBG');
		}
	);

    //Primary Nav Hover Interaction
    var myBagHeight = $('#myBag').height();
    //alert(myBagHeight);
    $('#myBag').css({ height: myBagHeight + 'px', top: '-' + myBagHeight + 'px', cursor: 'default' });

    $('#ContentPlaceHolder1_zipcode').bind('keypress', function (e) {
        if (e.keyCode == "13") {
            SearchStores();
            return false;
        }
    });

    $('.topNav li#bag').hover(function () {
        $(this).find('#myBag').stop(true, false).animate({ top: '37px' }, function () { $(this).slideDown(300) });
    }, function () {
        $(this).find('#myBag').stop(true, false).animate({}, function () { $(this).slideUp(300) });
    });
});  //document ready function

function showMiniCart() {
    $.ajax({
        url: '/store/minicart.aspx',
        cache: false,
        success: function (html) {
            $('.shoppingbag').html(html);
        },
        error: function (err) {
            //alert(err.responseText);
        }
    });
}

if(Sys != 'undefined') {
    Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(PageLoaded);
}



function RefreshCart() {
    $.ajax({
        url: '/store/minicart.aspx',
        cache: false,
        success: function (html) {
            $('.shoppingbag').html(html);
        }
    });
}

function SearchStoresByCountry() {
    var country = document.getElementById("ContentPlaceHolder1_country_ddl");
    var base = "/store/storelocator.aspx";
    window.location.href = base + "?country=" + country.options[country.selectedIndex].value;
}

function SearchStores() {
    var zipcode = document.getElementById("ContentPlaceHolder1_zipcode");
    var radius = document.getElementById("ContentPlaceHolder1_radius");
    var base = "/store/storelocator.aspx";
    window.location.href = base + "?radius=" + radius.options[radius.selectedIndex].value + "&zip=" + zipcode.value;
}

function PageLoaded(sender, args) {
    showMiniCart();
    render_cart_header("CartItemsLBGet", "CartTotalLBGet");
    
}

