﻿$m.core.register('.searchPanel', function (hub) {
    var searchButton,
        searchField,
        self = {};

    self.construct = function () {
        searchButton = hub.find('.searchButton');
        searchField = hub.find('.searchField');

        $m.jQuery(searchButton).val('');
        $m.jQuery(searchField).val('search site');
    };

    self.destruct = function () {

    };

    return self;
});
//Calls the construct function of the above module.  We will be able to chain
//this to the end after the next train deploy.
//ex: $m.core.register('.searchPanel', function (hub) {}).construct();
if ($m.core.modules['.searchPanel']) {
    $m.core.modules['.searchPanel'].construct();
}


$m.core.register('.signupPanel', function (hub) {
    var signupButton,
        signupField,
        self = {};

    self.construct = function () {
        signupButton = hub.find('.signupButton');
        signupField = hub.find('.signupField');

        $m.jQuery(signupButton).val('Enroll');
        $m.jQuery(signupField).val('sign up now...');
    };

    self.destruct = function () {

    };

    return self;
});
//Calls the construct function of the above module.  We will be able to chain
//this to the end after the next train deploy.
//ex: $m.core.register('.signupPanel', function (hub) {}).construct();
if ($m.core.modules['.signupPanel']) {
    $m.core.modules['.signupPanel'].construct();
}


$m.core.register('#Store', function (hub) {
    var self = {};

    self.construct = function () {
        //Set cart items to same height
        $m.jQuery(window).load(function () {
            var storeItems = hub.find('.product-list-item');
            var maxHeight = 0;

            $m.jQuery.each(storeItems, function () {
                var itemHeight = $(this).height();

                if (itemHeight > maxHeight) {
                    maxHeight = itemHeight;
                }
            });

            $m.jQuery.each(storeItems, function () {
                $(this).height(maxHeight);
            });
        });
    };

    self.destruct = function () {

    };

    return self;
});
//Calls the construct function of the above module.  We will be able to chain
//this to the end after the next train deploy.
//ex: $m.core.register('#Store', function (hub) {}).construct();
if ($m.core.modules['#Store']) {
    $m.core.modules['#Store'].construct();
}


$m.core.register('body', function (hub) {
    var $window,
        self = {};

    self.construct = function () {
        $m.jQuery(hub.container).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 ($m.jQuery.browser.msie) {
            var version = $m.jQuery.browser.version;

            if (version == '6.0') {
                var cookie = $m.jQuery.cookie('IE6');

                if (cookie != 'set') {
                    $m.jQuery.cookie('IE6', 'set');
                    $m.jQuery('#IE6').show().stop().animate({
                        top: 0
                    }, 1000);
                }

                $m.jQuery('.ie6close').click(function () {
                    $m.jQuery('#IE6').fadeOut(500);
                });
            }
        }
    };

    self.destruct = function () {

    };

    return self;
});
//Calls the construct function of the above module.  We will be able to chain
//this to the end after the next train deploy.
//ex: $m.core.register('#Store', function (hub) {}).construct();
if ($m.core.modules['body']) {
    $m.core.modules['body'].construct();
}


$m.core.register('#Navigation', function (hub) {
    var self = {};

    self.construct = function () {
        //code to set last link width in main nav
        if ($m.jQuery('.main-nav').length) {
            var li = $m.jQuery('#mainnav').children();
            for (var i = 0; i < li.length; i++) {
                var a = $m.jQuery(li[i]).children().filter('a');
                if ($m.jQuery(a).hasClass('last')) {
                    var ulWidth = $m.jQuery('#mainnav').width();
                    var siteWidth = $m.jQuery('#Wrapper').width();
                    var difference = (siteWidth - ulWidth) - 1;
                    var aWidth = $m.jQuery(a).width();
                    $m.jQuery(a).css("width", aWidth + difference + "px");
                    $m.jQuery(a).css("text-align", "center");
                }
            }
        }

        //Code to add plus image to nav items with flyouts
        if ($m.jQuery('.main-nav').length) {
            $m.jQuery('#mainnav').children().filter('li').addClass('top-level');
            var topLevel = $m.jQuery('#mainnav').find('li');

            $m.jQuery.each(topLevel, function() {
                var ul = $m.jQuery(this).children().filter('ul');

                if ($m.jQuery(ul).length > 0) {
                    $m.jQuery(this).prepend('<img src="SiteFiles/501174/Images/SubNavPlus.png" />');
                }
            });
        }

        //Main nav flyout and hover code
        $m.jQuery('#mainnav li.top-level').hover(
            function() {
                $m.jQuery(this).animate({ backgroundColor: '#efefef' }, 200);
                $m.jQuery(this).children().filter('a').animate({ color: '#ee2e24' }, 200);
                $m.jQuery(this).children().filter('ul').slideDown(300);
            },
            function() {
                $m.jQuery(this).animate({ backgroundColor: '#d5d6d7' }, 200);
                $m.jQuery(this).children().filter('a').animate({ color: '#000000' }, 200);
                $m.jQuery(this).children().filter('a.current').animate({ color: '#ffffff' }, 200);
                $m.jQuery(this).children().filter('ul').fadeOut(300);
            }
        )

        //Sub nav flyout
        $m.jQuery('#mainnav li li').hover(
            function() {
                $m.jQuery(this).children().filter('ul').slideDown(300);
            },
            function() {
                $m.jQuery(this).children().filter('ul').fadeOut(300);
            }
        )
    };

    self.destruct = function () {

    };

    return self;
});
//Calls the construct function of the above module.  We will be able to chain
//this to the end after the next train deploy.
//ex: $m.core.register('.searchPanel', function (hub) {}).construct();
if ($m.core.modules['#Navigation']) {
    $m.core.modules['#Navigation'].construct();
}

$m.core.register('#Bottom-Nav', function (hub) {
    var self = {};

    self.construct = function () {
        //Code to grab the top nav and through it into the bottom nav section
        if ($m.jQuery('#Bottom-Nav').length) {
            $m.jQuery('.main-nav').clone().appendTo('#Bottom-Nav');
        }
    };

    self.destruct = function () {

    };

    return self;
});
//Calls the construct function of the above module.  We will be able to chain
//this to the end after the next train deploy.
//ex: $m.core.register('#Bottom-Nav', function (hub) {}).construct();
if ($m.core.modules['#Bottom-Nav']) {
    $m.core.modules['#Bottom-Nav'].construct();
}



$m.core.register('#tabs', function (hub) {
    var self = {};

    self.construct = function () {
        //Hover code for banner section.
        $m.jQuery('#tabs li').hover(
            function() {
                $m.jQuery('#tabs li img').stop().animate({
                    left: '-320px'
                }, 500);
                $m.jQuery('#tabs li a').children().filter('span.large-text').animate({ color: '#383838' }, 300);
                $m.jQuery('#tabs li a').children().filter('span.small-text').animate({ color: '#666666' }, 300);

                $m.jQuery('img', this).stop().animate({
                    left: '0px'
                }, 500);

                $m.jQuery('a', this).children().filter('span').animate({ color: '#ffffff' }, 300);
            },
            function() {
                //nop
            }
        )

        //Intialize tabs UI widget
        if ($m.jQuery('#Home').length) {
            $m.jQuery('#tabs').tabs({ selected: 0, event: 'mouseover',
                show: function(event, ui) {
                    $m.jQuery('#tabs div').fadeOut(500);
                    $m.jQuery('#' + ui.panel.id).fadeIn(500);
                    $m.jQuery('#' + ui.panel.id + ' .info').fadeIn(500);
                }
            });

            $m.jQuery('#LI-1 img').stop().animate({
                left: '0px'
            }, 500);
            $m.jQuery('#LI-1 a').children().filter('span').animate({ color: '#ffffff' }, 300);
        }
    };

    self.destruct = function () {

    };

    return self;
});
//Calls the construct function of the above module.  We will be able to chain
//this to the end after the next train deploy.
//ex: $m.core.register('.searchPanel', function (hub) {}).construct();
if ($m.core.modules['#tabs']) {
    $m.core.modules['#tabs'].construct();
}

$m.core.register('', function (hub) {
    var self = {};

    self.construct = function () {
        //Sets the content header section text to that of the current 
        //page section title.
        if ($m.jQuery('#Default').length) {
            var links = $m.jQuery('#mainnav').children().find('a.current');

            if ($m.jQuery(links).length > 0) {
                $m.jQuery('#Section-Header').text($m.jQuery(links[0]).text());
            }
        }

        var calendarItem = $m.jQuery('td.weekday');
        if ($m.jQuery('#Events-Calendar').length) {
            var cssObj = {
                'height': '100px !important'
            }
            $m.jQuery(calendarItem).each(function () {
                $m.jQuery(this).removeAttr('style');
                //$m.jQuery(this).css(cssObj);
            });
        }
    };

    self.destruct = function () {

    };

    return self;
});
//Calls the construct function of the above module.  We will be able to chain
//this to the end after the next train deploy.
//ex: $m.core.register('.searchPanel', function (hub) {}).construct();
if ($m.core.modules['']) {
    $m.core.modules[''].construct();
}


$m.core.register('', function (hub) {
    var self = {};

    self.construct = function () {
        
    };

    self.destruct = function () {

    };

    return self;
});
//Calls the construct function of the above module.  We will be able to chain
//this to the end after the next train deploy.
//ex: $m.core.register('.searchPanel', function (hub) {}).construct();
if ($m.core.modules['']) {
    $m.core.modules[''].construct();
}


$m.core.register('', function (hub) {
    var self = {};

    self.construct = function () {
        
    };

    self.destruct = function () {

    };

    return self;
});
//Calls the construct function of the above module.  We will be able to chain
//this to the end after the next train deploy.
//ex: $m.core.register('.searchPanel', function (hub) {}).construct();
if ($m.core.modules['']) {
    $m.core.modules[''].construct();
}
