var deviceIphone = "iphone";
var deviceIpod = "ipod";

//Initialize our user agent string to lower case.
var uagent = navigator.userAgent.toLowerCase();

//**************************
// Detects if the current device is an iPhone.
function DetectIphone()
{
   if (uagent.search(deviceIphone) > -1)
      return true;
   else
      return false;
}

//**************************
// Detects if the current device is an iPod Touch.
function DetectIpod()
{
   if (uagent.search(deviceIpod) > -1)
      return true;
   else
      return false;
}

//**************************
// Detects if the current device is an iPhone or iPod Touch.
function DetectIphoneOrIpod()
{
    if (DetectIphone())
       return true;
    else if (DetectIpod())
       return true;
    else
       return false;
}
function addIPhoneCSS() {
    //var filename = "/media/css/iphone-0.1.css";
    var filename = "http://www.svartvit.se/style.css";
    
    var fileref = document.createElement("link")
    fileref.setAttribute("rel", "stylesheet")
    fileref.setAttribute("type", "text/css")
    fileref.setAttribute("href", filename)
    if (typeof fileref!="undefined")
        document.getElementsByTagName("head")[0].appendChild(fileref)
}

// 
jQuery(function(e) {
    //if (DetectIphone()) {
    if (false && DetectIphone()) {
        // Check if user has saved a cookie
        var urw = jQuery.cookie('useregularweb');
        if (urw && urw == 'yes') {
            // Use regular webpage
            var p = jQuery('<p class="gotoregularwebpage"></p>');
            var a = jQuery('<a href="#">Visa mobil variant</a>');
            a.click(function(e) {
                e.stopPropagation();
                // Save decision in cookie, go for one day
                jQuery.cookie('useregularweb', null);
                window.location = '/diary/';
                return false;
            });
            p.append(a);
            jQuery("#footer").append(p);
        } else {
            var p = jQuery('<p class="gotoregularwebpage"></p>');
            var a = jQuery('<a href="#">Visa fullständig webbplats</a>');
            a.click(function(e) {
                e.stopPropagation();
                // Save decision in cookie, go for one day
                jQuery.cookie('useregularweb', 'yes', { expires: 1 });
                window.location = '/diary/';
                return false;
            });
            p.append(a);
            jQuery("#footer").parent().append(p);
            addIPhoneCSS();
        }
    }
});

