function setNoMobiCookie(){
    // get the current date and time
    var nowDate = new Date();
    // add 30 minutes to the date (by adding 30 * 60 * 1000 - minutes times seconds/minute times milliseconds/second)
    nowDate.setTime(nowDate.getTime() + 1800000);
    
    // create a cookie
    document.cookie = "NoMobi=TRUE; expires=" + nowDate.toUTCString();
    
}

function checkNoMobiCookie(){
    
    var bNoMobiCookie = false
    // grab any cookies for this domain 
    
    if(document.cookie.length>0) {
        
        var iNoMobi = document.cookie.indexOf("NoMobi");
        
        bNoMobiCookie = (iNoMobi >= 0) ? true : false;
    }
    
    return bNoMobiCookie
}



// if we have a checkNoMobiCookie, then we can just skip all this
if(!checkNoMobiCookie()) {

// get the URL from the browser so we can check for our NoMobi variable
var sURL = window.document.location.href;

// check to see if NoMobi is set to true
var bNoMobi = sURL.match(/nomobi=true/i);

// set a variable to force the mobile version
var bShowMobi = sURL.match(/showmobi/i);

// if we don't find NoMobi set to true, then run a browser check and redirect if necessary
if(bNoMobi==null){
    // check to see if it's a mobile browser
    if(navigator.userAgent.match(/(palm|blackberry|windows ce|android|series60|symbian|iphone|ipod|ipad|lge|lg)/i) || bShowMobi){ // this is the live conditional
	//if(bShowMobi){ // this conditional is for testing purposes
       // load the mobile stylesheet
	   document.write('<link media="screen" href="css/mobileRaces.css" type="text/css" rel="stylesheet" />');
	   document.write('<meta name="viewport" content="width=device-width, initial-scale=1.0" />');
	   
		// declare a jQuery onload to update code that we can't do with just a stylesheet
		$(document).ready(function(){
		
		
		var htmlLogo = '<a href="index.html"><img src="images/logo-top.jpg" style="width:100%;" alt="Spartan Race obstacle course racing, trail racing &amp; death race" /></a>';
		
		var htmlRegisterNow = $("div#sidebar div:first").html();
		
		
		$("#logo").html(htmlLogo);
		$("#logo").append("<div class='sideblock block_grey' id='register_top'>" + htmlRegisterNow + "</div>");
		var intHeight = $("#register_top").height();
		$("#register_top").height(intHeight + 15);
		Cufon.refresh();
		
		
		var hrefImg = $("div.logo-super,div.logo-sprint,div.logo-beast,div.logo-death").next().children("img").attr("src");
		var altImg = $("div.logo-super,div.logo-sprint,div.logo-beast,div.logo-death").next().children("img").attr("alt");
		
		var htmlImg = "<img src='" + hrefImg + "' alt='" + altImg + "' class='fade' style='opacity: 1; width:100%;' />";
		
		$("div.logo-super,div.logo-sprint,div.logo-beast,div.logo-death").next().html(htmlImg); // update the image
		
		$("img.fade").show(); // show the image
		
		// update the width on the table 
		$("table").attr("width","320");
		$("table td").attr("width","160");
		$("table").show();
		
		
		
		
		});
    }

} else {
// this means we found nomobi set to true, so we want to set a cookie so they don't get redirected on other pages
setNoMobiCookie();
}
}







