﻿$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('Sign Up');
        $m.jQuery(signupField).val('enter email');
    };

    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('.main-nav', function (hub) {
    var self = {};

    self.construct = function () {
        var navHoverConfig = {
            over: showNavHover,
            timeout: 30,
            out: hideNavHover
        };
        
        //Add images to main nav and position them
        var li = $m.jQuery('.main-nav > ul > li');

        $m.jQuery.each(li, function () {
            var liWidth = $m.jQuery(this).width();
            var xPos = (liWidth - 15) / 2;

            $m.jQuery(this).append('<img src="SiteFiles/501213/images/MainNavHover.png" class="nav-hover"/>');
            $m.jQuery(this).append('<img src="SiteFiles/501213/images/NavPointer.png" class="nav-pointer" />');

            $m.jQuery('> .nav-pointer', this).css('left', +xPos + 'px');
            $m.jQuery('> .nav-hover', this).width(liWidth);
            $m.jQuery('> .nav-hover', this).height(47);

            $m.jQuery(this).addClass('hidden');
        });

        $m.jQuery('.main-nav > ul > li').hoverIntent(navHoverConfig);

        function showNavHover() {
            var self = $m.jQuery(this);
            var navHover = self.find(' > .nav-hover');
            var navPointer = self.find(' > .nav-pointer');

            //console.log(navHover);
            navHover.animate({
                top: '0px'
            }, 200, function () {
                self.addClass('visible');
                self.find(' > ul').slideDown(250);
            });

            navPointer.delay(300).animate({
                bottom: '0px'
            }, 300);
        }

        function hideNavHover() {
            var self = $m.jQuery(this);
            var navHover = self.find(' > .nav-hover');
            var navPointer = self.find(' > .nav-pointer');

            navHover.fadeOut(250);
            self.find(' > ul').fadeOut(250);
            navHover.animate({
                top: '-47px'
            }, 200, function () {
                self.removeClass('visible');
                navHover.fadeIn(250);
            });

            navPointer.animate({
                bottom: '-8px'
            }, 250);
        }

        if ($m.jQuery('.recent-news-full-news').length) {
            $m.jQuery('.recent-news-full-news a').text('More News');
        }
    };

    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('.main-nav', function (hub) {}).construct();
if ($m.core.modules['.main-nav']) {
    $m.core.modules['.main-nav'].construct();
}



$m.core.register('.side-nav', function (hub) {
    var self = {};

    self.construct = function () {
        //Checks if side nav is there if not hide it and slide content under it up
        if (!$m.jQuery('#subnav').length) {
            $m.jQuery('.side-nav').fadeOut(300);
            $m.jQuery('#Column2').css('backgroundImage', 'none');
            $m.jQuery('.column2-content').stop().animate({
                marginTop: '0px'
            }, 400);
        }
    };

    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['.side-nav']) {
    $m.core.modules['.side-nav'].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 (index, item) {
                var itemHeight = $m.jQuery(item).height();

                if (itemHeight > maxHeight) {
                    maxHeight = itemHeight;
                }
            });

            $m.jQuery.each(storeItems, function (index, item) {
                $m.jQuery(item).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('body', function (hub) {
    var self = {};

    self.construct = function () {
        //Loads up background image
        $m.jQuery.backstretch('SiteFiles/501213/Images/RAAWM_bg2.gif', { speed: 300, centeredX: false, centeredY: false });
    };

    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('#SlideShow', function (hub) {
    var self = {};

    self.construct = function () {
        //code to add cycle slide show to top of home page
        $m.jQuery('#SlideShow').before('<ul id="Nav">').cycle({
            fx: 'fade',
            timeout: 7000,
            speed: 1000,
            pager: '#Nav',
            pagerAnchorBuilder: function (i, slide) {
                return '<li><a href="#">' + (i + 1) + '</a></li>';
            }
        });

        /*$m.jQuery('.banner-badges').hover(
        function () {
        var self = $(this);
        var img = self.find('img');
        var parent = self.attr('id');

        img.fadeIn(300);
        $m.jQuery('#SlideShow').cycle('pause');
        showToolTip(parent);
        },
        function () {
        var self = $(this);
        var img = self.find('img');

        img.fadeOut(300);
        $m.jQuery('#SlideShow').cycle('resume');
        }
        );*/

        //Code to add PopUp box when hovering over one of the banner symbols
        /* function showToolTip(parent) {
        if (parent == 'Passenger') {
        var str = '<h3>Passengers</h3><p>Find out how RAAWM is helping you!</p>';
        } else if (parent == 'Airplane') {
        var str = '<h3>Airlines</h3><p>Find out how RAAWM is helping you!</p>';
        } else {
        var str = '<h3>Airports</h3><p>Find out how RAAWM is helping you!</p>';
        };

        $m.jQuery(".banner-badges").tooltip({
        bodyHandler: function () {
        return str;
        },
        showURL: false,
        track: true
        });
        }*/

        //Code to have slideshow pause when hovering over Poll Questions
        $m.jQuery('.poll').mouseover(function () {
            $m.jQuery('#SlideShow').cycle('pause');
        });

        $m.jQuery('.poll').mouseout(function () {
            $m.jQuery('#SlideShow').cycle('resume');
        });
    };

    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['#SlideShow']) {
    $m.core.modules['#SlideShow'].construct();
}

