/*!
 * Copyright 2011 Pebble Design. All Rights Reserved.
 * All JS libraries copyrighted to their respective owners.
 * Author: Gary Swanpeoel Date Created: 20111212 
 * Version:2.0 Date Modified:20111212
 * <script type="text/javascript">var visitorDeviceClass = "{system_visitorDeviceClass}";</script><script type="text/javascript" src="http://www.pebbledesign.com.au/system/js/detectdevice-2.0.js"></script>
 */

   /*******************************/
    function createCookie(name,value,days) {
        if (days) {
                var date = new Date();
                date.setTime(date.getTime()+(days*24*60*60*1000));
                var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
    }
    
    function readCookie(name) {
        var nameEQ = name + "=";
        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 eraseCookie(name) {
        createCookie(name,"",-1);
    }
    
    var url = window.location.pathname;
    url = url.split('/');
    
    
    if ((visitorDeviceClass == 'phone') && (url[1] != 'm')) {
	window.location = "/m";
    }
	
    if ((visitorDeviceClass == 'desktop') && (url[1] == 'm')) {
	window.location = "/";
    }
	
    /** ON PHONE **/
    
    
    function viewfullsite() {
        createCookie('visitorDeviceClass','desktop',0);
        window.location = "/";
	alert('Transferring you now.');
    }
    jQuery('a#viewfullsite').click(function(event){
	event.preventDefault();
        createCookie('visitorDeviceClass','desktop',0);
        window.location = "/";
	alert('Redirecting you now');
    });
