function isMobile()
{

    var browser = navigator.userAgent.toLowerCase();
    mobile = false;

    if( browser.search("ipod") != -1 )
    {   
        mobile = true;
    }   
    else if( browser.search("iphone") != -1 )
    {   
        mobile = true;
    }   
    else if( browser.search("ipad") != -1 )
    {   
        mobile = true;
    }   
    else if( browser.search("android") != -1 )
    {   
        mobile = true;
    }   
    else if( browser.search("midp") != -1 )
    {   
        mobile = true;
    }   
    else if( browser.search("dsi") != -1 )
    {   
        mobile = true;
    }   
    else if( browser.search("mobile") != -1 )
    {   
        mobile = true;
    }   
    else if( browser.search("symbian") != -1 )
    {   
        mobile = true;
    } 

    return mobile;

} //End of isMobile

$(document).ready(function()
{

   /* Write the delagate for taking care of the mobile cookie if they want to
     * go back to the mobile version.
     */
    $(document).delegate("#mobile-link", "click", function(event)
    {
       $.cookie('gfu_mobile', 'yes', { path: '/', domain: 'georgefox.edu' });
    });

    if( $("#mobile-link").length != 0 )
    {

        if( isMobile() && $.cookie('gfu_mobile') == "yes" )
        {
            window.location = $("#mobile-link").attr("href");
        }
        else if( isMobile() && $.cookie('gfu_mobile') == null )
        {
            var mobile = confirm("George Fox University has a site customized for mobile devices. Continue to the mobile site?");
            
            if( mobile )
            {
                $.cookie('gfu_mobile', 'yes', { path: '/', domain: 'georgefox.edu' });
                window.location = $("#mobile-link").attr("href");
            }
            else
            {
                //Assume they don't want to be asked again
                $.cookie('gfu_mobile', 'no', { path: '/', domain: 'georgefox.edu' });
            }

        }
    
    }//End of if mobile link exists



});
