﻿var $j = jQuery.noConflict();

//Runs when document is ready to be manipulated
$j(document).ready(function() {
    //code to set last link width in main nav
    //    if ($j('.main-nav').length) {
    //        var li = $j('#mainnav').children();
    //        for (var i = 0; i < li.length; i++) {
    //            var a = $j(li[i]).children().filter('a');
    //            if ($j(a).hasClass('last')) {
    //                var ulWidth = $j('#mainnav').width();
    //                var siteWidth = $j('#Wrapper').width();
    //                var difference = (siteWidth - ulWidth) - 1;
    //                var aWidth = $j(a).width();
    //                $j(a).css("width", aWidth + difference + "px");
    //                $j(a).css("text-align", "center");
    //            }
    //        }
    //    }

    //Function to remove "Search" text from site search button
    if ($j('#Site-Search').length) {
        $j('.searchButton').val('');
        $j('.searchField').val('search site');
    }

    //Function to remove "Sign Up" text from newsletter sign up button
    if ($j('#Newsletter').length) {
        $j('.signupButton').val('Sign Up');
        $j('.signupField').val('enter email');
    }

    //Code to grab the top nav and through it into the bottom nav section
    if ($j('#Bottom-Nav').length) {
        $j('.main-nav').clone().prependTo('#Bottom-Nav');
    }

    //IE 6 browser detection
    if ($j.browser.msie) {
        var version = $j.browser.version;

        if (version == '6.0') {
            $j('#IE6').show().stop().animate({
                top: 0
            }, 1000);

            $j('.ie6close').click(function() {
                $j('#IE6').fadeOut(500);
            });

            //Gets rid of background image flicker.
            try {
                document.execCommand('BackgroundImageCache', flase, true);
            } catch (e) { }
        }
    }
});


//Runs when document is fully loaded including images.
$j(window).load(function() {
    //Set cart items to same height
    if ($j('#Store').length) {
        var items = $j('.product-list-item');
        var maxHeight = 0;

        $j.each(items, function() {
            var itemHeight = $j(this).height();

            if (itemHeight > maxHeight) {
                maxHeight = itemHeight;
            }
        });

        $j.each(items, function() {
            $j(this).height(maxHeight);
        });
    }

    //Checks if side nav is there if not hide it and slide content under it up
    if (!$j('#subnav').length) {
        $j('.side-nav').fadeOut(300);
        $j('#Column2').css('backgroundImage', 'none');
        $j('.column2-content').stop().animate({
            marginTop: '0px'
        }, 400);
    }
});