﻿$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 isOffScreenOrClipped,
//        mainNav,
//        self = {};

//    self.construct = function () {
//        mainNav = hub.find('#mainnav');

//        //Main nav flyout animation
//        $m.jQuery('#mainnav li').hover(
//            function () {
//                var hoveredItem = this;
//                var firstUl = $m.jQuery(hoveredItem).find('ul:first');
//                var parentLi = $m.jQuery(firstUl).parents('li');

//                //Check if we have sub nav
//                if (firstUl.length > 0) {
//                    //Check if sub nav is outside visible window
//                    isOffScreenOrClipped = self.IsNodeClippedOrOffscreen(firstUl, parentLi);
//                    if (isOffScreenOrClipped) {
//                        firstUl.addClass('offScreen');
//                    }

//                    firstUl.filter(':not(:animated)').slideDown({ duration: 180, easing: 'easeInOutQuad' });
//                }

//            },
//            function () {
//                var hoveredItem = this;
//                var firstUl = $m.jQuery(hoveredItem).find('ul:first');

//                if (firstUl.length > 0) {
//                    firstUl.fadeOut(150, 'easeInOutQuad');
//                    if (firstUl.hasClass('offScreen')) {
//                        firstUl.removeClass('offScreen');
//                    }
//                }

//            }
//        );

//        hub.listen({
//            'mainNavClone': this.mainNavClone
//        });
//    };

//    self.destruct = function () {

//    };

//    self.mainNavClone = function (bottomNav) {
//        $m.jQuery(mainNav).clone().prependTo(bottomNav);
//    };

//    self.IsNodeClippedOrOffscreen = function (node, parentLi) {
//        var ulPos = node.parent().offset();
//        var ulLeftPos = ulPos.left;
//        var ulTopPos = ulPos.top;
//        var ulWidth = node.outerWidth(true);
//        var ulHeight = node.outerHeight(true);

//        if (parentLi.length > 1) {
//            posX = (ulWidth * 2) + ulLeftPos;
//            var bOffScreen = self.CheckIfPointIsOffScreen(posX, ulTopPos);
//            var bClipped = self.CheckIfPointIsOffScreen(posX, ulTopPos + ulHeight);
//        } else {
//            var bOffScreen = self.CheckIfPointIsOffScreen(ulLeftPos, ulTopPos);
//            var bClipped = self.CheckIfPointIsOffScreen(ulLeftPos + ulWidth, ulTopPos + ulHeight);
//        }

//        return (bOffScreen || bClipped);
//    };

//    self.CheckIfPointIsOffScreen = function (iLeftPos, iTopPos) {
//        var iBrowserWidth = $m.jQuery(window).width();
//        var iBrowserHeight = $m.jQuery(window).height();
//        var bOffScreen = false;

//        if (iLeftPos < 0 || iLeftPos >= iBrowserWidth)
//            bOffScreen = true;

//        if (iTopPos < 0 || iTopPos >= iBrowserHeight)
//            bOffScreen = true;

//        return bOffScreen;
//    };

//    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('#Bottom-Nav', function (hub) {
    var bottomNav,
        ul,
        self = {};

    self.construct = function () {
        bottomNav = hub.container;

        hub.notify({
            type: 'mainNavClone',
            data: bottomNav
        });

        ul = hub.find('#mainnav');
        $m.jQuery(ul).removeAttr('id');
        $m.jQuery('li', ul).each(function () {
            $m.jQuery(this).removeAttr('id');
        });
    };

    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('#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('.product-template', function (hub) {
    var self = {};

    self.construct = function () {
        $m.jQuery('#Admin-Custom-Content').remove();
    };

    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['.product-template']) {
    $m.core.modules['.product-template'].construct();
}



$m.core.register('body.states', function (hub) {
    var self = {};

    self.construct = function () {
        var links = $m.jQuery('#breadcrumb').children().find('a.current');
            var cssObj = {
                'width': 'auto',
                'padding-bottom': '30px'
            }

            if ($m.jQuery(links).length > 0) {
                $m.jQuery('#Page-Name').text($m.jQuery(links[0]).text());
            }

            $m.jQuery('.image-link a img').remove();
            $m.jQuery('.employment-listing a').text('');

            $m.jQuery("p:contains('Moving Seniors')").css(cssObj);
            $m.jQuery("p:contains('Packing Tips')").css(cssObj);

            $m.jQuery('#Bread-Crumb').css('display', 'none');

            $m.jQuery('.moving-services a').attr('href', '#');


        if ($m.jQuery('.main-nav').length) {
            var liLast = $('#mainnav').children().last().find('ul ul');

            $m.jQuery(liLast).addClass('position-right');
        }
    };

    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['body.states']) {
    $m.core.modules['body.states'].construct();
}



$m.core.register('.main-nav', function (hub) {
    var self = {};

    self.construct = function () {
            var topLevel = $m.jQuery('#mainnav ul').find('li');

            $m.jQuery.each(topLevel, function () {
                var ul = $m.jQuery(this).children().filter('ul');

                if ($m.jQuery(ul).length > 0) {
                    $m.jQuery('a', this).first().append('<img src="SiteFiles/501123/Images/NavArrow.gif" />');
                }
            });
    };

    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['.main-nav']) {
    $m.core.modules['.main-nav'].construct();
}


$m.core.register('.quoteInfo', function (hub) {
    var self = {};

    self.construct = function () {
        if ($m.jQuery('.quoteInfo').length) {
            $m.jQuery('.quoteInfo').val('enter city, state or zip');
        }

        $m.jQuery('.quoteInfo').click(function () {

            $m.jQuery(this).val('');

            if ($m.jQuery('.tip').is(':visible')) {
                $m.jQuery('.tip').animate({ opacity: 'toggle' }, 'slow');
                return false;
            } else {
                $m.jQuery('.tip').animate({ opacity: 'toggle' }, 'slow');
                return false;
            }

        });

        $m.jQuery('#GetStarted').click(function () {
            if ($m.jQuery('.quoteInfo').val() == 'enter city, state or zip' || $m.jQuery('.quoteInfo').val() == '') {
                $m.jQuery('.tip').animate({ opacity: 'toggle' }, 'slow');
                return false;
            }
            else {
                window.location.href = 'default.aspx?p=24I30B11382646gB9G4&a=' + $m.jQuery('.quoteInfo').val();
                //window.location.href = 'default.aspx?p=24I30B11619646gB9G4&a=' + $('.quoteInfo').val();
            }
        });
    };

    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['.quoteInfo']) {
    $m.core.modules['.quoteInfo'].construct();
}



$m.core.register('#Default', function (hub) {
    var self = {};

    self.construct = function () {
            var links = $m.jQuery('#mainnav').children().find('a.current');

            if ($m.jQuery(links).length > 0) {
                $m.jQuery('#Page-Name').text($m.jQuery(links[0]).text());
            }
    };

    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['#Default']) {
    $m.core.modules['#Default'].construct();
}



$m.core.register('#Find-Movers', function (hub) {
    var self = {};

    self.construct = function () {
            var links = $m.jQuery('#breadcrumb').children().find('a.current');
            var cssObj = {
                'width': 'auto',
                'padding-bottom': '30px'
            }

            if ($m.jQuery(links).length > 0) {
                $m.jQuery('#Page-Name').text($(links[0]).text());
            }

            $m.jQuery('#MoversTB').val('enter address, state or zip code');

            $m.jQuery('#MoversTB').click(function () {
                $m.jQuery(this).val('');

                if ($m.jQuery('#Find-Movers .tip').is(':visible')) {
                    $m.jQuery('#Find-Movers .tip').animate({ opacity: 'toggle' }, 'slow');
                    return false;
                } else {
                    $m.jQuery('#Find-Movers .tip ').animate({ opacity: 'toggle' }, 'slow');
                    return false;
                }
            });

            $m.jQuery('#Find-Movers-Link').click(function () {
                if ($m.jQuery('#MoversTB').val() == 'enter address, state or zip code' || $m.jQuery('#MoversTB').val() == '') {
                    $m.jQuery('#Find-Movers .tip').animate({ opacity: 'toggle' }, 'slow');
                    return false;
                }
                else {
                    window.location.href = 'default.aspx?p=24I30B11382646gB9G4&a=' + $m.jQuery('#MoversTB').val();
                    //window.location.href = 'default.aspx?p=24I30B11619646gB9G4&a=' + $('#MoversTB').val();
                }
            });
    };

    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['#Find-Movers']) {
    $m.core.modules['#Find-Movers'].construct();
}


$m.core.register('#Franchise-Insight-Video', function (hub) {
    var self = {};

    self.construct = function () {
            $m.jQuery('#Insight-Video').dialog({ autoOpen: false, title: 'Franchisee Insight Video' });

            //Code to top video links in modal for the franchisee insight page
            $m.jQuery('.video-link').click(function () {
                $m.jQuery('#Insight-Video').html('');
                var videoFile = $(this).attr('rel');

                $m.jQuery('#Insight-Video').flash({
                    src: videoFile,
                    width: 320,
                    height: 240
                });

                $m.jQuery('#Insight-Video').dialog('open');

                return 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('.searchPanel', function (hub) {}).construct();
if ($m.core.modules['#Franchise-Insight-Video']) {
    $m.core.modules['#Franchise-Insight-Video'].construct();
}


$m.core.register('.two-men-locator', function (hub) {
    var self = {};

    self.construct = function () {
        $m.jQuery('input, textarea').each(function () {
            var defval = this.value;
            $m.jQuery(this).focus(function () {
                if (this.value == defval) {
                    this.value = '';
                }
            });
            $m.jQuery(this).blur(function () {
                if (this.value == '') {
                    this.value = defval;
                }
            });
        });
    };

    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['.two-men-locator']) {
    $m.core.modules['.two-men-locator'].construct();
}


$m.core.register('#Mobile-Menu', function (hub) {
    var self = {};

    self.construct = function () {
        $m.jQuery('#Mobile-Menu').click(function (e) {
            e.preventDefault();
            $m.jQuery('.main-nav').slideToggle(300, 'easeInOutQuad');
        });
    };

    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['#Mobile-Menu']) {
    $m.core.modules['#Mobile-Menu'].construct();
}

