function BrowserRecommendationBar() {
	
	this.language = "en";
	
	this.backgroundColor = "#FFFEE0";
	this.linkColor = "#0000C0";
	this.textColor = "#000000";
	
	this.upgradeText = "";
	this.updateText = "";
	
	this.showInfoLink = true;
	
	// Actions
	this.action_ie0 = "recommend_ff3";
	this.action_ie7 = "recommend_ff3";
	this.action_ff0 = "update";
	this.action_op0 = "update";
	this.action_op9 = "";
	
	this.text = {
		"de": {
			"textUpgrade" : "Sie verwenden einen Browser, der moderne Web-Technologien nicht korrekt unterst&uuml;tzt. "
				+ "Testen Sie {link}!",
			"textUpdate" : "Es steht eine neue Version Ihres Browsers zum Download zur Verf&uuml;gung. "
				+ "Testen Sie den neuen {link}."
		},
		"en": {
			"textUpgrade" : "You are using a browser which doesn't support modern web-technologies correctly. "
				+ "Try {link}!",
			"textUpdate" : "A newer version of your web browser is available. "
				+ "Download the new {link}."
		}
	};
	var language = "en";
	
	var bar;
	var height = 0;
	var browser = "unknown";
	var browserVersion = 0;
	
	this.hide = function() {
		
		bar.style.display = "none";
		
		// set cookie
		var date = new Date();
		var time = date.getTime() + (7 * 24 * 60 * 60 * 1000);
		date.setTime(time);
		document.cookie = "brbHidden=true; expires=" + date.toGMTString();
		
	}
	
	this.init = function() {
		
		// check cookie
		var cookie = document.cookie;
		if(cookie.search("brbHidden") > -1)
			return;
		
		// detect browser
		detectBrowser();
		
		
		// set action
		var linkTarget = "";
		var linkText = "";
		var type = "";
		if(browser == "ie") {
			if(compareVersion("7", browserVersion) > 0) {
				// IE <= 6
				if(this.action_ie0 == "update") {
					type = "update";
					linkTarget = "http://www.microsoft.com/windows/products/winfamily/ie/default.mspx";
					linkText = "Internet Explorer 7";
				}
				else if(this.action_ie0 == "recommend_ff3") {
					type = "upgrade";
					linkTarget = "http://www.firefox.com";
					linkText = "Mozilla Firefox 3";
				}
				else
					return;
			}
			else {
				// IE 7
				if(this.action_ie7 == "recommend_ff3") {
					type = "upgrade";
					linkTarget = "http://www.firefox.com";
					linkText = "Mozilla Firefox 3";
				}
				else
					return;
			}
		}
		else if(browser == "firefox") {
			if(compareVersion("3", browserVersion) > 0) {
				// FF <= 3
				if(this.action_ff0 == "update") {
					type = "update";
					linkTarget="http://www.firefox.com";
					linkText = "Mozilla Firefox 3";
				}
				else
					return;
			}
			else
				return;
		}
		else if(browser == "opera") {
			if (compareVersion("9", browserVersion) > 0) {
				// Opera <= 8
				if (this.action_op0 == "update") {
					type = "update";
					linkTarget = "http://www.opera.com";
					linkText = "Opera 9";
				}
				else if(this.action_op0 == "recommend_ff3") {
					type = "upgrade";
					linkTarget = "http://www.firefox.com";
					linkText = "Mozilla Firefox 3";
				}
				else
					return;
			}
			else
				return;
			/* Opera 9 is OK ;)
			else {
				// Opera 9
				if(this.action_op9 == "recommend_ff3") {
					type = "upgrade";
					linkTarget = "http://www.firefox.com";
					linkText = "Mozilla Firefox 3";
				}
				else
					return;
			}
			*/
		}
		else
			return;
				
		
		// detect language
		if(navigator.language != null)
			var lang = navigator.language.substring(0, 2);
		else if(navigator.browserLanguage != null)
			var lang = navigator.browserLanguage.substring(0, 2);
		else
			var lang = "en";
		if(this.text[lang] != undefined)
			language = lang;
			
		if(this.upgradeText == "")
			this.upgradeText = this.text[language]['textUpgrade'];
		if(this.updateText == "")
			this.updateText = this.text[language]['textUpdate'];
			
		
		// create bar
		bar = document.createElement("div");
		bar.id = "BRB_bar";
		
		bar.style.fontFamily = "Arial, Verdana, Helvetica";
		bar.style.fontSize = "10pt";
		bar.style.backgroundColor = this.backgroundColor;
		bar.style.color = this.textColor;
		bar.style.borderBottom = "ridge 2px #848075";
		bar.style.zIndex = 100;
		
		bar.style.position = "absolute";
		bar.style.top = "0px";
		bar.style.left = "0px";
		bar.style.width = "100%";
		bar.style.height = "0px";
		bar.style.overflow = "hidden";
		
		
		// build text
		
		if(type == "upgrade")
			var currentText = this.upgradeText;
		else
			var currentText = this.updateText;
		currentText = currentText.replace("{link}", '<span style="cursor: pointer; text-decoration: underline; color: ' + this.linkColor + '" onclick="location.href=\'' + linkTarget + '\'">' + linkText + '</span>');
		
		var html = '<div id="BRB_right" style="padding: 5px; float: right; margin-left: 20px">';
			
		if(this.showInfoLink)
			html += '<span style="cursor: pointer; text-decoration: underline; color: ' + this.linkColor + '" onclick="BRB.info()">Info</span> | '
				
		var protocol = (document.location.protocol == "https:" ? "https" : "http");
				
		html += '<span style="cursor: pointer; text-decoration: underline; color: ' + this.linkColor + '" onclick="BRB.hide()">Close</span>'
			+ '</div>'
			+ '<div id="BRB_text" style="padding: 5px">'
				+ '<img src="' + protocol + '://browser.fusonic.net/script/caution_16.png" style="position: relative; top: 2px; margin-right: 3px" />'
				+ currentText
			+ '</div>';
			
		bar.innerHTML = html;
		
		
		// set onload event
		window.onload = new Function("BRB.run()");
		
	}
	
	this.run = function () {
		
		if(document.body.childNodes.length == 0)
			document.body.appendChild(bar);
		else
			document.body.insertBefore(bar, document.body.childNodes[0]);
			
		this.runIn();

	}
	
	this.runIn = function() {
		
		height += 2;
		
		if (height >= document.getElementById("BRB_text").offsetHeight) 
			bar.style.height = "";
		else {
			window.setTimeout("BRB.runIn()", 50);
			bar.style.height = height + "px";
		}
		
	}
	
	this.fadeInfo = function() {
		
		var value = parseFloat(document.getElementById("BRB_infoOverlay").style.opacity);
		
		if(value < 0.5) {
			
			value += 0.05;
			
			document.getElementById("BRB_infoOverlay").style.opacity = value;
			document.getElementById("BRB_infoOverlay").style.filter = "alpha(opacity=" + (value * 100) + ")";
			document.getElementById("BRB_infoContent").style.opacity = value * 2;
			document.getElementById("BRB_infoContent").style.filter = "alpha(opacity=" + (value * 200) + ")";
			
			window.setTimeout("BRB.fadeInfo()", 20);
			
		}
		
	}
	
	this.info = function() {
		
		var overlay = document.createElement("div");
		overlay.id = "BRB_infoOverlay";
		overlay.style.position = "absolute";
		overlay.style.top = "0%";
		overlay.style.left = "0%";
		overlay.style.width = "100%";
		overlay.style.height = "100%";
		overlay.style.backgroundColor = "#000000";
		overlay.style.opacity = "0";
		overlay.style.filter = "alpha(opacity=0)";
		overlay.style.zIndex = 1000;
		
		var content = document.createElement("div");
		content.id = "BRB_infoContent";
		content.style.width = "500px";
		content.style.marginLeft = "-250px";
		content.style.position = "absolute";
		content.style.top = "50px";
		content.style.left = "50%";
		content.style.backgroundColor = "#FFFFFF";
		content.style.padding = "10px";		
		content.style.fontFamily = "Arial, Verdana, Helvetica";
		content.style.fontSize = "10pt";
		content.style.zIndex = 1001;
		
		// Set content
		
		var title = "What's this all about?";
		var text = "<p>Jeder Web-Entwickler weiß, wie wichtig die Einhaltung von Web-Standards für die zukünftige Entwicklung des Internets ist. Nur so kann sich die Vision des Erfinders des WWW Tim Berners-Lee  weiter entfalten.</p>"
				+ "<p>Während von Seiten professioneller Web-Entwickler die vom W3C veröffentlichten Richtlinien verfolgt werden, geht die Entwicklung nur sehr langsam voran.</p>"
				+ "<p>Zurückzuführen ist dies neben zu geringem Interesse von Browser-Herstellern auch auf die Unkenntnis der Anwender. Diese blockieren die positive Entwicklung der letzten Jahre oft durch die Wahl schlechter Software.</p>"
				+ "<p>Das Projekt \"Browser Recommendation\" soll Bewusstsein schaffen und Anwender motivieren, einen Beitrag zur zukünftigen Entwicklung des WWW zu leisten.</p>"
				+ "<p>Die \"Browser Recommendation Bar\" weist unerfahrene Benutzer darauf hin, dass nicht oder schlecht kompatible Browser verwendet werden.</p>";
		var implementOnYourSite = "Implement on your site!";
		
		if(language == "de") {
			title = "Um was geht es eigentlich?";
			text = "<p>Jeder Web-Entwickler weiß, wie wichtig die Einhaltung von Web-Standards für die zukünftige Entwicklung des Internets ist. Nur so kann sich die Vision des Erfinders des WWW Tim Berners-Lee  weiter entfalten.</p>"
				+ "<p>Während von Seiten professioneller Web-Entwickler die vom W3C veröffentlichten Richtlinien verfolgt werden, geht die Entwicklung nur sehr langsam voran.</p>"
				+ "<p>Zurückzuführen ist dies neben zu geringem Interesse von Browser-Herstellern auch auf die Unkenntnis der Anwender. Diese blockieren die positive Entwicklung der letzten Jahre oft durch die Wahl schlechter Software.</p>"
				+ "<p>Das Projekt \"Browser Recommendation\" soll Bewusstsein schaffen und Anwender motivieren, einen Beitrag zur zukünftigen Entwicklung des WWW zu leisten.</p>"
				+ "<p>Die \"Browser Recommendation Bar\" weist unerfahrene Benutzer darauf hin, dass nicht oder schlecht kompatible Browser verwendet werden.</p>";
			implementOnYourSite = "Auf der eigenen Website einbinden!";
		}
		
		content.innerHTML = "<div style=\"position: absolute; cursor: pointer; top: 10px; right: 10px; color: black !important\" onclick=\"BRB.hideInfo()\">Close</div>" 
			+ "<div style=\"font-weight: bold; font-size: 120%; margin-bottom: 10px; color: black !important\">" + title + "</div>"
			+ "<div style=\"text-align: justify; overflow-y: auto; height: 300px; padding: 5px; color: black !important\">"
			+ text
			+ "</div>"
			+ "<div style=\"float: left; margin-top: 5px; padding-top: 2px\">"
			+ "<a href=\"http://browser.fusonic.net\" target=\"_blank\" style=\"color: black !important\">" + implementOnYourSite + "</a>"
			+ "</div>"
			+ "<div style=\"text-align: right; border-top: solid 1px #808080; margin-top: 5px; padding-top: 2px\">"
			+ "by <a href=\"http://www.fusonic.net\" target=\"_blank\" style=\"color: black !important\">Fusonic</a>"
			+ "</div>";
		
		document.body.insertBefore(overlay, document.body.childNodes[0]);
		document.body.insertBefore(content, document.body.childNodes[0]);
		
		this.fadeInfo();
		
		//window.open("http://browser.fusonic.net/info");
		
	}
	
	this.hideInfo = function() {
		
		document.body.removeChild(document.getElementById("BRB_infoOverlay"));
		document.body.removeChild(document.getElementById("BRB_infoContent"));
		
	}
	
	function detectBrowser() {
		
		var a = navigator.userAgent;
		
		if(a.match("Firefox")) {
			
			browser = "firefox";
			
			var res = a.search(/Firefox\/([\.\d]+)/);
			if(res > -1)
				browserVersion = RegExp.$1;
			else
				browserVersion = "unknown";
				
		}
		else if(a.match("Opera")) {
			
			browser = "opera";
			
			var res = a.search(/Opera\/([\.\d]+)/);
			if (res > -1) 
				browserVersion = RegExp.$1;
			else {
				res = a.search(/Opera ([\.\d]+)/);
				if(res > -1)
					browserVersion = RegExp.$1;
				else
					browserVersion = "unknown";
			}
				
		}
		else if(a.match("MSIE")) {
			
			browser = "ie";
			
			var res = a.search(/MSIE ([\.\d]+)/);
			if(res > -1)
				browserVersion = RegExp.$1;
			else
				browserVersion = "unknown";
			
		}
		
	}
	
	function compareVersion(_version1, _version2) {
	
		var _version1_1, _version1_2, _version1_3, _version2_1, _version2_2, _version2_3;	
	
		if(_version1.match(/(\d+)\.(\d+)\.(\d+)/)) {
			_version1_1 = RegExp.$1;
			_version1_2 = RegExp.$2;
			_version1_3 = RegExp.$3;
		}
		else if(_version1.match(/(\d+)\.(\d+)/)) {
			_version1_1 = RegExp.$1;
			_version1_2 = RegExp.$2;
			_version1_3 = 0;
		}
		else if(_version1.match(/(\d+)/)) {
			_version1_1 = RegExp.$1;
			_version1_2 = 0;
			_version1_3 = 0;
		}
	
		if(_version2.match(/(\d+)\.(\d+)\.(\d+)/)) {
			_version2_1 = RegExp.$1;
			_version2_2 = RegExp.$2;
			_version2_3 = RegExp.$3;
		}
		else if(_version2.match(/(\d+)\.(\d+)/)) {
			_version2_1 = RegExp.$1;
			_version2_2 = RegExp.$2;
			_version2_3 = 0;
		}
		else if(_version2.match(/(\d+)/)) {
			_version2_1 = RegExp.$1;
			_version2_2 = 0;
			_version2_3 = 0;
		}
		
		if(_version1_1 > _version2_1)
			return 1;
		else if(_version2_1 > _version1_1)
			return -1;
		else if(_version1_2 > _version2_2)
			return 1;
		else if(_version2_2 > _version1_2)
			return -1;
		else if(_version1_3 > _version2_3)
			return 1;
		else if(_version2_3 > _version1_3)
			return -1;
		else
			return 0;
	
	}
	
}

var BRB = new BrowserRecommendationBar();
