(function(){

	var nVer = navigator.appVersion;
	var nAgt = navigator.userAgent;
	var bN  = navigator.appName;
	var fV  = ''+parseFloat(navigator.appVersion); 
	var mV = parseInt(navigator.appVersion,10);
	var nameOffset,verOffset,ix;
	//var msie_flag = false;
	
	// In Opera, the true version is after "Opera" or after "Version"
	if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
	 bN = "Opera";
	 fV = nAgt.substring(verOffset+6);
	 if ((verOffset=nAgt.indexOf("Version"))!=-1) 
	   fV = nAgt.substring(verOffset+8);
	}
	// In MSIE, the true version is after "MSIE" in userAgent
	else if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
	 bN = "Microsoft Internet Explorer";
	 fV = nAgt.substring(verOffset+5);
	}
	// In Chrome, the true version is after "Chrome" 
	else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
	 bN = "Chrome";
	 fV = nAgt.substring(verOffset+7);
	}
	// In Safari, the true version is after "Safari" or after "Version" 
	else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
	 bN = "Safari";
	 fV = nAgt.substring(verOffset+7);
	 if ((verOffset=nAgt.indexOf("Version"))!=-1) 
	   fV = nAgt.substring(verOffset+8);
	}
	// In Firefox, the true version is after "Firefox" 
	else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
	 bN = "Firefox";
	 fV = nAgt.substring(verOffset+8);
	}
	// In most other browsers, "name/version" is at the end of userAgent 
	else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) ) 
	{
	 bN = nAgt.substring(nameOffset,verOffset);
	 fV = nAgt.substring(verOffset+1);
	 if (bN.toLowerCase()==bN.toUpperCase()) {
	  bN = navigator.appName;
	 }
	}
	// trim the fV string at semicolon/space if present
	if ((ix=fV.indexOf(";"))!=-1) fV=fV.substring(0,ix);
	if ((ix=fV.indexOf(" "))!=-1) fV=fV.substring(0,ix);
	
	mV = parseInt(''+fV,10);
	if (isNaN(mV)) {
	 fV  = ''+parseFloat(navigator.appVersion); 
	 mV = parseInt(navigator.appVersion,10);
	}
	
	//console.log("bN: " + bN); console.log("mV: " + mV); console.log("fV: " + fV);
	
	
	// GLOBAL AJAX
	var Hash = location.hash,	
		Href = location.href,
		Host = location.host,
		Path = location.pathname,
		Pathlenght = Path.length;
		Href = Href.toLowerCase();
		Path = Path.toLowerCase();
		
	String.prototype.startsWith = function (str){ return this.indexOf(str) == 0; };
	//"Hello World!".startsWith("He"); // true

	switch(true){
		
		// Check Browser compatibility
		case (bN == "Microsoft Internet Explorer" && mV < 7):			
			redirectURL();
			break;
			
		case (bN == "Safari" && fV < 4):
			redirectURL();
			break;
			
		case (bN == "Firefox" && fV < 3.5):
			redirectURL();
			break;
			
		// Homepage & First time visitor 
		/*case (Pathlenght <= 1 && (!Hash || Hash == '#' || Hash == '#!' || Hash == '#!/') ):
			return false;
			break;*/
		
		// Standard Subpage & First time visitor
		//case (!Hash && Pathlenght > 1 && Href != 'http://' + Host + '/404.html' && Href != 'http://' + Host + '/browser-unsupported.html'): && Path != '/index.php'
		
		 case (!Hash && Pathlenght > 1 && Path != '/404.html' && Path != '/browser-unsupported.html' && !Path.startsWith("/downloads") && !Path.startsWith("/techinfo")  && !Path.startsWith("/assets")):
			window.location.assign('http://' + Host + '/#!' + Path);
			break;		
		
		case (Hash == '#!/index.php' || Hash == '#!/#'):
			window.location.assign('http://' + Host);
			break;	
			
		default: 
			//Browser supported
			return false;			
	
	}
	
})();

function redirectURL(){
	var url= '/browser-unsupported.html',
		domain= window.location.hostname;		
	url = 'http://' + domain + url;
	window.location.href = url;
}


