﻿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');
    }

    //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('.side-nav').css('backgroundImage', 'none');
        $j('.column2-content').stop().animate({
            marginTop: '0px'
        }, 400);
    }
});


//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);
        });
    }

    //Addes IE6 popup to site.
    $j('body').append("<div id='IE6'><a href='#' class='ie6close'></a><span class='warning'></span> <span>Wow, you're using IE6!</span><br /><p>The browser you're using is very out of date. We beg you to consider upgrading. This website will work for you, but some things may not work as intended because, well, your browser is really old. Upgrade now and be a happier web surfer.</p><a href='http://www.microsoft.com/nz/windows/internet-explorer/default.aspx' class='ie6'></a><a href='http://www.google.com/chrome' class='chrome'></a><a href='http://www.mozilla.com/en-US/firefox/upgrade.html' class='firefox'></a></div>");

    //IE 6 browser detection
    if ($j.browser.msie) {
        var version = $j.browser.version;

        if (version == '6.0') {
            var cookie = $j.cookie('IE6');

            if (cookie != 'set') {
                $j.cookie('IE6', 'set');
                $j('#IE6').show().stop().animate({
                    top: 0
                }, 1000);
            }

            $j('.ie6close').click(function() {
                $j('#IE6').fadeOut(500);
            });
        }
    }
});