$(document).ready(function(){

		var is_mobile_url = "/Ccpr/mobile/wireless.php";

		$.ajax({
			url: is_mobile_url,
			cache: false,
			success: function(e) {
                              if (e == "True")
                              {
				mobile_event(e);
                              }
			}
		});
	});
	
	function mobile_event(e) 
	{
		var wireless_device = e;		
		redirect_mobile_site(wireless_device);		
	}

	
	function redirect_mobile_site(e)
	{
		var mobile_url 		=  'http://m.murdoch.edu.au';
		var mobile_cookie 	= check_mobile_cookie('mobile_redirect');
		
		//-- if ccokie is not set
		if ((mobile_cookie == null) || (mobile_cookie == 1))
		{
			var redirect 		= confirm('You appear to be using a mobile device - would you like to redirect to the mobile version of this site?');
			if (redirect == true) {
				set_mobile_cookie('mobile_redirect', 1);
				window.location = mobile_url;
			} else {
				set_mobile_cookie('mobile_redirect', 0);
			}
			//mobile_cookie = check_mobile_cookie('mobile_redirect');		
		}		
        //-- IF COOKIE IS TRUE REDIRECT
		//else if (mobile_cookie == 1)
		//{
			//window.location = mobile_url;
		//}			
	}

	function check_mobile_cookie(cookieName)
	{
		var nameEQ = cookieName + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	
	
	function set_mobile_cookie(cookieName, cookieValue)
	{
		var today = new Date();
		var expire = new Date();
		expire.setTime(today.getTime() + 3600000*6);
		document.cookie = cookieName+'='+escape(cookieValue) + ';expires='+expire.toGMTString();
	}
