	$(document).ready(function() {

    /*******************************************************************
    Function: Section Nav More Menu Function
		This function controls the expand/contract of the "global more menu"
    ********************************************************************/

    // Set up the function to fire when the more menu is clicked in the main menu
    $("#ts-section_nav_more_link").click(function(event) {
        event.preventDefault();
        // Toggle the more panel		
        $("#ts-section_nav_more_menu").slideToggle("normal");
    });

    // Set up the function to fire when the collapse menu is clicked when the more menu	is expanded
    $("#ts-collapse_section_nav_more_menu").click(function(event) {
        event.preventDefault();
        // Slide up the more panel
        $("#ts-section_nav_more_menu").slideUp("normal");
    });


    /*******************************************************************
    Function: Hover Button
		This function sets up a generic rollover event. It looks for any element with a 
    class of "ts-hover_button" and, on rollover, adds  "_hover" to the src of the image
    ********************************************************************/

    // Search box hover button
    $(".ts-hover_button").mouseover(
		function() {
		    // var src = $(this).attr("src").match(/[^\.]+/) + "_hover.gif";
		    var src = $(this).attr("src").replace(/\.([^.]+)$/, '_hover.$1');
		    $(this).attr("src", src);
		}).mouseout(function() {
		    var src = $(this).attr("src").replace("_hover", "");
		    $(this).attr("src", src);
		}
	);


    // Check if device is Java-based mobile device, blackberry or windows mobile
    var isMobile = (navigator.userAgent.search(/(midp|j2me|blackberry|iemobile)/i) > -1) ? true : false;
    // Check if device is using Mobile Webkit based browsers
    var isMobileTouch = (navigator.userAgent.search(/(iphone|ipod|android|webos|symbianos)/i) > -1) ? true : false;
    
    // If viewing on a mobile device, show link to view mobile site
    if (isMobile || isMobileTouch) {

        var mobileLink = $('<a></a>')
                            .click(switch_ui_mobile)
                            .text('View mobile site')
                            ;

        // Set appropriate link based on device type
        var mobileLinkHref = ''
        if (isMobile) {
            mobileLinkHref = '/mobile';
        } else if (isMobileTouch) {
            mobileLinkHref = '/iphone';
        } else {
            mobileLinkHref = '#';
        }
        mobileLink.attr('href', mobileLinkHref);

        $('<div></div>')
            .addClass('td-mobile_links_header')
            .prependTo($('body'))
            .append(mobileLink)
        ;
    }

});  // End DOM ready functions

var MoreMenu = {
    init: function() {
	
     /*******************************************************************
     Function: More Menu Function

     This function controls the expand/contract of the "global more menu"
     ********************************************************************/

     // Hide the menu before page is displayed. If the browser is not JS compliant, the menu will remain open (a desired effect)
        $("#ts-global_more_menu").hide();
        // We also must show the site map link, and hide the collapse link	
        $("#ts-global_site_map").hide();
        $("#ts-collapse_more_menu").show();

        // Set up the function to fire when the more menu is clicked in the main menu
        $("#ts-global_menu_more_link").click(function(event) {
            event.preventDefault();
            // Toggle the more panel		
            $("#ts-global_more_menu").slideToggle("normal");
            // Toggle the more menu active state		
            $("#ts-global_menu_more_link").toggleClass("ts-more_active");
            // Toggle the opacity of the site map link in the more menu
            $("#ts-global_site_map").animate({
                opacity: 'toggle'
            }, "fast");
        });

        // Set up the function to fire when the collapse menu is clicked when the more menu	is expanded
        $("#ts-collapse_more_menu").click(function(event) {
            event.preventDefault();
            // Slide up the more panel
            $("#ts-global_more_menu").slideUp("normal");
            // Toggle the more menu active state
            $("#ts-global_menu_more_link").toggleClass("ts-more_active");
            // Toggle the opacity of the site map link in the more menu
            $("#ts-global_site_map").animate({
                opacity: 'toggle'
            }, "fast");
        });
    }
}


/* Switches user's preferred UI to mobile */
function switch_ui_mobile(e) {
    e.preventDefault;
    TD.ProjectTheStar.CreateCookie('star_ui', '', 7);
    location.href = '/';
    return false;
}
