var client = new Browser();

function Browser() {
	this.opera		=	false;
	this.mie		=	false;
	this.net6		=	false;
	this.net4		=	false;
	this.mozilla	=	false;
	this.icab		=	false;
	this.version	=	0;
	this.win		=	false;
	this.mac		=	false;
	if (navigator.userAgent.indexOf("iCab") != -1) {
		this.icab = true;
		this.version = navigator.userAgent.substr(navigator.userAgent.indexOf("iCab") +5 ,3);
	} else if (navigator.userAgent.indexOf("Opera") != -1) {
		this.opera = true;
		this.version = navigator.userAgent.substr(navigator.userAgent.indexOf("Opera") +6 ,3);
	} else if (navigator.appName.indexOf("Netscape") != -1) {
		if (navigator.userAgent.indexOf("Gecko") != -1) {
			if (navigator.userAgent.indexOf("Netscape6") != -1) {
				this.net6 = true;
				this.version = navigator.userAgent.substr(navigator.userAgent.indexOf("Netscape6") +10 ,3);
			} else {
				this.mozilla = true;
				this.version = navigator.userAgent.substr(navigator.userAgent.indexOf("rv:") +3 ,5);
			}
		} else {
			this.net4 = true;
			this.version = navigator.appVersion.substr(0,3);
		}
	} else if (navigator.userAgent.indexOf("MSIE") != -1) {
		this.mie = true;
		this.version = navigator.userAgent.substr(navigator.userAgent.indexOf("MSIE") +5 ,3);
	} 
	if (navigator.platform.indexOf("Mac") != -1) {
		this.mac = true;
	} else if (navigator.platform.indexOf("Win") != -1) {
		this.win = true;
	}
}


/**
* Loader function, called on window.onload
* Use it to assign and start javascript functionality
*/
function loader() {
	addImageAnimation("topImage", "themes/flash/header.swf", 150);
	addImageAnimation("topImageSmall", "themes/flash/header.swf", 75);
	assigninputFX("#FFE8D9", "#333");
	assignPopUps("popUpImg", 500, 500, "no", true);
	assignPopUps("popUpLink", 500, 600, "yes", false);
	resizeImagePopUp("popUpZoomImage", "content");
}

//  loader function
window.onload = loader;

/**
* Assigns focus and blur effects to text and password input tags
* and onmouseover and onmouseout effects to submit, reset and button input tags
*
* @param bgC string the onfocus color of text and password input tags
* @param overC string the onmouseover color of submit, reset and button input tags
*/
function assigninputFX(bgC, overC) {
	if(document.getElementById) {
		var n = document.getElementsByTagName("input");
		var nN = n.length;
		if(nN > 0) {
			for(var i = 0; i < nN; i++) {
				if((n[i].type == "text") || (n[i].type == "password")) {
					n[i].onfocus = function() {
						this.oldBgC = this.style.backgroundColor;
						this.style.backgroundColor = bgC;
					}
					n[i].onblur = function() {
						this.style.backgroundColor = this.oldBgC;
					}
				}
				if((n[i].type == "submit") || (n[i].type == "reset") || (n[i].type == "button")) {
					n[i].onmouseover = function() {
						this.oldColor = this.style.color;
						this.style.color = overC;
					}
					n[i].onmouseout = function() {
						this.style.color = this.oldColor;
					}
				}
			}
		}
	}
}

/**
* Assigsn popup functions to "a" tags, use class attribute as trigger
*
* @param cl string trigger class
* @param w int default width of the popup
* @param h int default height of the popup
* @param string "no"|"yes" popup with or without scrollbars
* @param tTip bool add tooltip to the element (only for images)
*/
function assignPopUps(cl, w, h, scrl, tTip) {
	if(document.getElementById) {
		var n = document.getElementsByTagName("a");
		var nN = n.length;
		if(nN > 0) {
			for(var i = 0; i < nN; i++) {
				var nC = n[i].getAttribute("class");
				if((nC == null) && (n[i].attributes["class"] != null)) {
					nC = n[i].attributes["class"].nodeValue;
				}
				if(nC == cl) {
					n[i].onclick = function() {
						return openPopUp(this.href, cl + "Win", w, h, scrl);
					}
					// add ToolTip
					if(tTip) {
						addImageToolTip(n[i], cl + "ToolTip");
					}
				}
			}
		}
	}
}

/**
* adds a tooltip to an image within n (only for image-popups)
*
* @param n domnode node which the tooltip should be append to
* @param cl string the class of the tooltip element
*/
function addImageToolTip(n, cl) {
	// dosn't work in MSIE
	if((document.getElementsByTagName) && (navigator.userAgent.indexOf("MSIE") == -1)) {
		var img = n.getElementsByTagName("img")[0];
		if(img != null) {
			var zTtop = (img.offsetTop + (img.height - 20));
			var zTleft = (img.offsetLeft + (img.width - 20));
			var zT = document.createElement("span");
			zT.setAttribute("class", cl);
			zT.setAttribute("style", "top: " + zTtop + "px; left: " + zTleft + "px;");
			zT.innerHTML = "&#160;";
			n.appendChild(zT);
		}
	}
}

/**
* Opens popup window
*
* @param url string
* @param name string the name of the window
* @param w int default width of the popup
* @param h int default height of the popup
* @param string "no"|"yes" popup with or without scrollbars
*/
function openPopUp(url, name, w, h, scrl) {
	var lP = (screen.width - w) / 2;
	var tP = (screen.height - h) / 2;
	popUp = window.open(url, name, 'height=' + h + ',width=' + w + ',locationbar=no,menubar=no,toolbar=no,scrollbars=' + scrl + ',resizable=no,top=' + tP + ',left=' + lP + ',status=yes');
	popUp.moveTo(lP, tP);
	popUp.resizeTo(w, h);
	popUp.focus();
	return false;
}

/**
* Resizes the popup, so it fits the element (image) with id id if an element with this id exists
*
* @param cl string id
* @param p string id of the content section to add text-align center
*/
function resizeImagePopUp(id, pCl) {
	if(document.getElementById) {
		var n = document.getElementById(id);
		if(n != null) {
			initWinSize(n.width + 100, n.height + 100);
			document.getElementById(pCl).style.textAlign = "center";
		}
	}
}

/**
* Resize window
*
* @param w int width
* @param h int height
*/
function initWinSize(w, h) {
	var newWidth = w + 20;
	var newHeight = h + 50;
	if(newWidth < 250) {
		newWidth = 250;
	}
	if(newHeight < 250) {
		newHeight = 250;
	}
	if (((screen.height / 2) - h) > screen.height) {
		window.moveTo(10,10);
	} else {
		window.moveTo((screen.width-newWidth)/2,(screen.height-newHeight)/2);
	}
	window.resizeTo(newWidth,newHeight);
}

/**
* Adds animation (Flash) to element with id if the element exists
*
* @param id string the id of the element
* @param fUrl string the url of the flash swf movie
* @param h int the height of the element (for anaza 75 and 150)
*/
function addImageAnimation(id, fUrl, h) {
	if(document.getElementById) {
		var tiDiv = document.getElementById(id);
		if(tiDiv != null) {
			var tiImg = tiDiv.getElementsByTagName("img")[0];
			if(tiImg != null) {
				if(window.hasFlash) {
					var height = h;
					imageFlashReplace(tiImg, fUrl, "false", "false", "high", "noscale", "TL", "transparent", tiDiv.style.backgroundColor, 600, height);
				} else {
					tiImg.style.display = "block";
				}
			}
		}
	}
}

/**
* Replaces node (image) with a flash swf movie and passes the content of the src and alt attribute to the swf movie
*
* @param node domnode the image which should be replaced
* @param movie string url of the swf movie
* @param loop string flash parameter
* @param menu string flash parameter
* @param quality string flash parameter
* @param scale string flash parameter
* @param salign string flash parameter
* @param wmode string flash parameter
* @param bgcolor string flash parameter
* @param width int width of the swf movie 
* @param height int height of the swf movie 
*/
function imageFlashReplace(node, movie, loop, menu, quality, scale, salign, wmode, bgcolor, width, height) {
	if(node != null) {
		var p = node.parentNode;
		node.style.visibility = "hidden";
		var divAttr = new Array(); divAttr[0] = new Array();
		divAttr[0]["name"] = "style";
		divAttr[0]["value"] = "width:" + width + "px;height:" + height + "px;";
		var div = createNodeWithAttributes("div", divAttr);
		var url = (movie.indexOf("?") == -1) ? movie + "?": movie + "&amp;";
		url = url + 'url=' + node.src + '&amp;txt=' + escape(node.alt);
		div.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + width + '" height="' + height + '" align="left">' +
			'<param name="movie" value="' + url + '" />' +
			'<param name="loop" value="' + loop + '" />' +
			'<param name="menu" value="' + menu + '" />' +
			'<param name="quality" value="' + quality + '" />' +
			'<param name="scale" value="' + scale + '" />' +
			'<param name="salign" value="' + salign + '" />' +
			'<param name="wmode" value="' + wmode + '" />' +
			'<param name="bgcolor" value="' + bgcolor + '" />' +
			'<embed src="' + url + '" loop="' + loop + '" menu="' + menu + '" quality="' + quality + '" scale="' + scale + '" salign="' + salign + '" wmode="' + wmode + '" bgcolor="' + bgcolor + '" width="' + width + '" height="' + height + '" align="left" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
			'</object>';
		 p.replaceChild(div, node);
	 }
}

/**
* Returns a new Domnode (element n) with attributes a
*
* @param n string element (tag) name
* @param a array attributes example: array[0]["name"] = "attribute name"; array[0]["value"] = "attribute value"
*/
function createNodeWithAttributes(n, a) {
	var n = document.createElement(n);
	var aN = a.length;
	for(var i = 0; i < aN; i++) {
		n.setAttribute(a[i]["name"], a[i]["value"]);
	}
	return n;
}

/**
* Flash detection (Flash 6)
*/
var hasFlash = function(){
	var nRequiredVersion = 6;	
	if(navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("Windows") > -1){
		document.write('<script language="VBScript"\> \n');
		document.write('on error resume next \n');
		document.write('hasFlash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & ' + nRequiredVersion + '))) \n');  
		document.write('<'+'/script\> \n');
		if(window.hasFlash != null){
			return window.hasFlash;
		};
	};
	if(navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
		var flashDescription = (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description;
		var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
		return flashVersion >= nRequiredVersion;
	};
	return false;
}();