﻿(function ($, undifined) {
    //Runs when document is ready to be manipulated
    $(document).ready(function () {

        //Function to remove "Search" text from site search button
        if ($('#Site-Search').length) {
            $('.searchButton').val('');
            $('.searchField').val('search site');
        }

        //Function to remove "Sign Up" text from newsletter sign up button
        if ($('#Newsletter').length) {
            $('.signupButton').val('Sign Up');
            $('.signupField').val('enter email');
        }

        //Code to grab the top nav and through it into the bottom nav section
        if ($('#Bottom-Nav').length) {
            $('.main-nav').clone().prependTo('#Bottom-Nav');
        }
    });


    //Runs when document is fully loaded including images.
    $(window).load(function () {
        //Set cart items to same height
        if ($('#Store').length) {
            var items = $('.product-list-item');
            var maxHeight = 0;

            $.each(items, function () {
                var itemHeight = $(this).height();

                if (itemHeight > maxHeight) {
                    maxHeight = itemHeight;
                }
            });

            $.each(items, function () {
                $(this).height(maxHeight);
            });
        }

        //Checks if side nav is there if not hide it and slide content under it up
        if (!$('#subnav').length) {
            $('.side-nav').css('display', 'none');
        }

        //Addes IE6 popup to site.
        $('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 ($.browser.msie) {
            var version = $.browser.version;

            if (version == '6.0') {
                var cookie = $.cookie('IE6');

                if (cookie != 'set') {
                    $.cookie('IE6', 'set');
                    $('#IE6').show().stop().animate({
                        top: 0
                    }, 1000);
                }

                $('.ie6close').click(function () {
                    $('#IE6').fadeOut(500);
                });
            }
        }
    });
})(jQuery);
