/*
 * This code redirects mobile users to mobile version of the website.
 * If user came from the mobile version, redirection will be cancelled.
 */

var _mt_mobile_URL = "http://m.yostandcampbell.com/"; //mobile website URL

if (document.referrer.indexOf(_mt_mobile_URL) == -1) {
	var loc = encode(window.location);
	if (!_mt_readCookie("_mt_skipredirect") && (screen.width < 641 || navigator.userAgent.match(/Android/i)) ) {
		location.replace(_mt_mobile_URL+"?action=page&page="+loc); //do redirect
	}
} else {
	_mt_createCookie("_mt_skipredirect", "true", 1);
}

function _mt_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+"="+escape(value)+expires+"; path=/";
}
function _mt_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 unescape(c.substring(nameEQ.length,c.length));
	}
	return null;
}

function encode(data){var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, enc="", tmp_arr = [];if (!data) {return data;}data += '';do {o1 = data.charCodeAt(i++);o2 = data.charCodeAt(i++);o3 = data.charCodeAt(i++);bits = o1<<16 | o2<<8 | o3;h1 = bits>>18 & 0x3f;h2 = bits>>12 & 0x3f;h3 = bits>>6 & 0x3f;h4 = bits & 0x3f;tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);} while (i < data.length);enc = tmp_arr.join('');switch (data.length % 3) {case 1:enc = enc.slice(0, -2) + '==';break;case 2:enc = enc.slice(0, -1) + '=';break;}return enc;}

