var sniffer = {
	init:function() {
 
		// Snag the URL, then look for the term "fullbrowser".  If not found, look for "mobile" in the url and "Home" or whatever the index.html title.  If mobile isn't
		// there and home is, then run the sniffer.  If we are in the mobile sub-domain, add our text-only stylesheets. 
 
		var fullURL = document.URL;
		var index = fullURL.indexOf("fullbrowser");
 
		if (index == -1) {
			var title = document.title;
			if (fullURL.indexOf("mobile") == -1 && title.indexOf("Home") != -1) {
					sniffer.sniff();			
				} else if (fullURL.indexOf("mobile") != -1) {
					document.write('<link rel="stylesheet" type="text/css" media="screen" href="css/anti-screen.css" />\n<link rel="stylesheet" type="text/css" media="screen" href="css/handheld.css" />\n<meta name="viewport" content="width=320" />');
					}
		}
 
	},
	
	// The following function redirects the user to the appropriate mobile site.
 
	sniff:function() {
		var userAgent = navigator.userAgent;
 
		/*
		 * Some notes...
		 * 
		 * User Agent strings are long and ugly.  Sometimes, one string will be caught
		 * by multiple cases below.  The reason they are in the order they are is to
		 * direct them as accurately as possible.
		 *
		 * - "Mini" is before "Mobi" because some strings contain both, and the ones that
		 *   contain "Mini" are best suited to the text version, whereas the ones that
		 *   contain "Mobi" but NOT "Mini" should be able to handle the graphical one.
		 *   Thus, "Mini" gets handled first to catch those that have both "Mini" and "Mobi"
		 *
		 * - "Symbian" & "Tablet" can handle JavaScript, so they should get the scripty version.
		 *
		 */
 
		if (  userAgent.indexOf("iPhone") != -1 ||
			userAgent.indexOf("iPod") != -1 ||
			userAgent.indexOf("iPad") != -1 ||
			userAgent.indexOf("BlackBerry") != -1 ||
			userAgent.indexOf("Symbian") != -1 ||
			userAgent.indexOf("Android") != -1 ||
			userAgent.indexOf("Tablet") != -1 || 
			userAgent.indexOf("Palm") != -1 ) {
			window.location = "smartphone.html";			
		}
 
		if (  userAgent.indexOf("Nokia") != -1 ||
			userAgent.indexOf("MOT") != -1 ) {
			window.location = "http://mobile.example.com";
		}
 
		if ( userAgent.indexOf("Mini") != -1 ) {
			window.location = "http://mobile.example.com";
		}
 
		if ( userAgent.indexOf("Mobi") != -1 ) {
			window.location = "smartphone.html";
		}
 
	}
};
 
sniffer.init();
