var agent = navigator.userAgent.toLowerCase();
var devices = ['android','iphone','ipod','blackberry','vnd.wap.xhtml+xml', 'sony', 'symbian', 'nokia', 'samsung', 'mobile', 'windows ce', 'epoc', 'opera mini', 'nitro', 'j2me', 'midp-', 'cldc-', 'netfront', 'mot', 'up.browser', 'up.link', 'audiovox', 'ericsson', 'panasonic', 'philips', 'sanyo', 'sharp', 'sie-', 'portalmmm', 'blazer', 'avantgo', 'danger', 'palm', 'series60', 'palmsource', 'pocketpc', 'smartphone', 'rover', 'ipaq', 'au-mic', 'alcatel', 'ericy', 'vodafone', 'wap1', 'wap2', 'teleca', 'playstation', 'lge', 'lg-', 'htc', 'dream', 'webos', 'bolt', 'nintendo'];

var referringURL = document.referrer;
var hostname = location.hostname;
var isMobile = false;
// We don't want ipad or android tablets to go to mobile
//if (agent.indexOf('ipad') != -1 || (agent.indexOf('android') != -1 && agent.indexOf('mobile') == -1)) {
	// It's an ipad or google tablet
//} else {
	for (var i in devices) {
		if (agent.indexOf(devices[i]) != -1) {
			isMobile = true;	
			break; // for eficiency
		}
	}
//}
if (! referringURL || ! referringURL.match(/\.wnd\.com/)) {
	if (isMobile && ! hostname.match(/^mobile.*\.wnd\.com$/)) {
		// We're making this flexible so it will work in dev and on the live and any other subdomains	
		if (hostname.match("^ww")) {
			location.replace(location.protocol + "//mobile.wnd.com");
		}
		else if (hostname.match("\.wnd\.com$")) {
			location.replace(location.protocol + "//mobile." + hostname);
		}
	}
}

