var mobile = function (host) {
	'use strict';
	var regex, mobileUA, ui, LS_KEY = host + '-PROMPT';
	mobileUA = [
		'Android',
		'AvantGo',
		'BlackBerry',
		'DoCoMo',
		'iPod',
		'iPhone',
		'J2ME',
		'MIDP',
		'NetFront',
		'Nokia',
		'Opera Mini',
		'PalmOS',
		'PalmSource',
		'portalmmm',
		'Plucker',
		'ReqwirelessWeb',
		'SonyEricsson',
		'Symbian',
		'UP.Browser',
		'webOS',
		'Windows CE',
		'Xiino'
	];
	regex = new RegExp(mobileUA.join('|'), "gi");
	prompt = {
		setLast: function () {
			if (window.localStorage) {
				window.localStorage[LS_KEY] = String(new Date().getTime());
			}
		},
		getLast: function () {
			var value = 0;
			if (window.localStorage) {
				if (!isNaN(window.localStorage[LS_KEY])) {
					value = window.localStorage[LS_KEY];
				}
			}
			return value;
		},
		reset: function () {
			if (window.localStorage) {
				window.localStorage[LS_KEY] = null;
			}
		}
	};
	ui = {
		isMobile: function () {
			if (navigator.userAgent.match(regex) !== null) {
				return true;
			}
			return false;
		},
		redirect: function () {
			if (typeof (host) !== 'undefined') {
				window.location = window.location.href.replace(window.location.host, host);
			}
		},
		canPrompt: function () {
			var hour = 1000 * 3600, now = Number(new Date().getTime()), then = Number(prompt.getLast());
			return (then === 0 || (now - then) > hour) ? true : false;
		},
		prompt: function (msg) {
			if (typeof (msg) === 'undefined') {
				msg = "Would you like to visit our mobile site?";
			}
			if (typeof (host) !== 'undefined' && this.canPrompt() && confirm(msg)) {
				prompt.setLast();
				this.redirect();
			}
			prompt.setLast();
		},
		clear: function () {
			prompt.reset();
		}
	};
	return ui;
};
if (window.location.pathname === '/') {
	var myMobile = mobile('m.visitsouthwalton.com');
	if (myMobile.isMobile()) {
		myMobile.prompt();
	}
}
