var mob=jQuery
mob.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = mob.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
mob(document).ready(function(){
	var cookieName = 'mobile_check';
	var cookieOptions = {expires: 1, path: '/'};
	$.extend({
	  getUrlVars: function(){
 	   var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
   		for(var i = 0; i < hashes.length; i++)
  	 	{
     	 hash = hashes[i].split('=');
      	 vars.push(hash[0]);
      	 vars[hash[0]] = hash[1];
    	}
    	return vars;
  	},
  	getUrlVar: function(name){
    return $.getUrlVars()[name];
  	}
	});
//$("#verbose").val("");
var url_mobile = $.getUrlVar('mobile')
mob.cookie(cookieName, url_mobile, cookieOptions);

//	$("#showCookie").click(function(e){
//		e.preventDefault();
//		$("#verbose").val("Cookie value is " + $.cookie(cookieName) + "."  );
//	});

if ( mob.cookie(cookieName) != 'yes') 
{
	if (screen.width <= 699) {
	document.location = "http://www.celtic-manor.com/mobile/index.html";
	}
        if ( (navigator.userAgent.indexOf('Android') != -1) ) {
               document.location = "http://www.celtic-manor.com/mobile/index.html";
        }
}
		
else {
$('<a href="http://www.celtic-manor.com"><div id="back_mobile" style="position:absolute; top:0; right:0; width:181px; height:25px; background:url(mobile_tab.png); color:#fff; "><center><p style="padding:5px 0 0px 10px; height:19px;">Back to mobile website</p></center></div></a>').appendTo('body');	
}


});
