var sUserAgent = navigator.userAgent;
var fAppVersion = parseFloat(navigator.appVersion);

function compareVersions(sVersion1, sVersion2) {

    var aVersion1 = sVersion1.split(".");
    var aVersion2 = sVersion2.split(".");
    
    if (aVersion1.length > aVersion2.length) {
        for (var i=0; i < aVersion1.length - aVersion2.length; i++) {
            aVersion2.push("0");
        }
    } else if (aVersion1.length < aVersion2.length) {
        for (var i=0; i < aVersion2.length - aVersion1.length; i++) {
            aVersion1.push("0");
        }    
    }
    
    for (var i=0; i < aVersion1.length; i++) {
 
        if (aVersion1[i] < aVersion2[i]) {
            return -1;
        } else if (aVersion1[i] > aVersion2[i]) {
            return 1;
        }    
    }
    
    return 0;

}

var isOpera = sUserAgent.indexOf("Opera") > -1;
var isMinOpera4 = isMinOpera5 = isMinOpera6 = isMinOpera7 = isMinOpera7_5 = isMinOpera8 = false;

if (isOpera) {
    var fOperaVersion;
    if(navigator.appName == "Opera") {
        fOperaVersion = fAppVersion;
    } else {
        var reOperaVersion = new RegExp("Opera (\\d+\\.\\d+)");
        reOperaVersion.test(sUserAgent);
        fOperaVersion = parseFloat(RegExp["$1"]);
    }

    isMinOpera4 = fOperaVersion >= 4;
    isMinOpera5 = fOperaVersion >= 5;
    isMinOpera6 = fOperaVersion >= 6;
    isMinOpera7 = fOperaVersion >= 7;
    isMinOpera7_5 = fOperaVersion >= 7.5;
    isMinOpera8 = fOperaVersion >= 8;
	isMinOpera9 = fOperaVersion >= 9;
}

var isKHTML = sUserAgent.indexOf("KHTML") > -1 
              || sUserAgent.indexOf("Konqueror") > -1 
              || sUserAgent.indexOf("AppleWebKit") > -1; 
              
var isMinSafari1 = isMinSafari1_2 = false;
var isMinKonq2_2 = isMinKonq3 = isMinKonq3_1 = isMinKonq3_2 = false;

if (isKHTML) {
    isSafari = sUserAgent.indexOf("AppleWebKit") > -1;
    isKonq = sUserAgent.indexOf("Konqueror") > -1;

    if (isSafari) {
        var reAppleWebKit = new RegExp("AppleWebKit\\/(\\d+(?:\\.\\d*)?)");
        reAppleWebKit.test(sUserAgent);
        var fAppleWebKitVersion = parseFloat(RegExp["$1"]);

        isMinSafari1 = fAppleWebKitVersion >= 85;
        isMinSafari1_2 = fAppleWebKitVersion >= 124;
    } else if (isKonq) {

        var reKonq = new RegExp("Konqueror\\/(\\d+(?:\\.\\d+(?:\\.\\d)?)?)");
        reKonq.test(sUserAgent);
        isMinKonq2_2 = compareVersions(RegExp["$1"], "2.2") >= 0;
        isMinKonq3 = compareVersions(RegExp["$1"], "3.0") >= 0;
        isMinKonq3_1 = compareVersions(RegExp["$1"], "3.1") >= 0;
        isMinKonq3_2 = compareVersions(RegExp["$1"], "3.2") >= 0;
    } 
    
}

var isIE = sUserAgent.indexOf("compatible") > -1 
           && sUserAgent.indexOf("MSIE") > -1
           && !isOpera;
           
var isMinIE4 = isMinIE5 = isMinIE5_5 = isMinIE6 = false;

if (isIE) {
    var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
    reIE.test(sUserAgent);
    var fIEVersion = parseFloat(RegExp["$1"]);

    isMinIE4 = fIEVersion >= 4;
    isMinIE5 = fIEVersion >= 5;
    isMinIE5_5 = fIEVersion >= 5.5;
    isMinIE6 = fIEVersion >= 6.0;
	isMinIE7 = fIEVersion >= 7.0;
}

var isMoz = sUserAgent.indexOf("Gecko") > -1
            && !isKHTML;

var isMinMoz1 = sMinMoz1_4 = isMinMoz1_5 =  false;

if (isMoz) {
    var reMoz = new RegExp("rv:(\\d+\\.\\d+(?:\\.\\d+)?)");
    reMoz.test(sUserAgent);
    isMinMoz1 = compareVersions(RegExp["$1"], "1.0") >= 0;
    isMinMoz1_4 = compareVersions(RegExp["$1"], "1.4") >= 0;
    isMinMoz1_5 = compareVersions(RegExp["$1"], "1.5") >= 0;
}

var isNS4 = !isIE && !isOpera && !isMoz && !isKHTML 
            && (sUserAgent.indexOf("Mozilla") == 0) 
            && (navigator.appName == "Netscape") 
            && (fAppVersion >= 4.0 && fAppVersion < 5.0);

var isMinNS4 = isMinNS4_5 = isMinNS4_7 = isMinNS4_8 = false;

if (isNS4) {
    isMinNS4 = true;
    isMinNS4_5 = fAppVersion >= 4.5;
    isMinNS4_7 = fAppVersion >= 4.7;
    isMinNS4_8 = fAppVersion >= 4.8;
}

var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");
var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") 
            || (navigator.platform == "Macintosh");

var isUnix = (navigator.platform == "X11") && !isWin && !isMac;

var isWin95 = isWin98 = isWinNT4 = isWin2K = isWinME = isWinXP = false;
var isMac68K = isMacPPC = false;
var isSunOS = isMinSunOS4 = isMinSunOS5 = isMinSunOS5_5 = false;

if (isWin) {
    isWin95 = sUserAgent.indexOf("Win95") > -1 
              || sUserAgent.indexOf("Windows 95") > -1;
    isWin98 = sUserAgent.indexOf("Win98") > -1 
              || sUserAgent.indexOf("Windows 98") > -1;
    isWinME = sUserAgent.indexOf("Win 9x 4.90") > -1 
              || sUserAgent.indexOf("Windows ME") > -1;
    isWin2K = sUserAgent.indexOf("Windows NT 5.0") > -1 
              || sUserAgent.indexOf("Windows 2000") > -1;
    isWinXP = sUserAgent.indexOf("Windows NT 5.1") > -1 
              || sUserAgent.indexOf("Windows XP") > -1;
    isWinNT4 = sUserAgent.indexOf("WinNT") > -1 
              || sUserAgent.indexOf("Windows NT") > -1 
              || sUserAgent.indexOf("WinNT4.0") > -1 
              || sUserAgent.indexOf("Windows NT 4.0") > -1 
              && (!isWinME && !isWin2K && !isWinXP);
} 

if (isMac) {
    isMac68K = sUserAgent.indexOf("Mac_68000") > -1 
               || sUserAgent.indexOf("68K") > -1;
    isMacPPC = sUserAgent.indexOf("Mac_PowerPC") > -1 
               || sUserAgent.indexOf("PPC") > -1;  
}

if (isUnix) {
    isSunOS = sUserAgent.indexOf("SunOS") > -1;

    if (isSunOS) {
        var reSunOS = new RegExp("SunOS (\\d+\\.\\d+(?:\\.\\d+)?)");
        reSunOS.test(sUserAgent);
        isMinSunOS4 = compareVersions(RegExp["$1"], "4.0") >= 0;
        isMinSunOS5 = compareVersions(RegExp["$1"], "5.0") >= 0;
        isMinSunOS5_5 = compareVersions(RegExp["$1"], "5.5") >= 0;
    }
}

/* 
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 */


var EventUtil = new Object;
EventUtil.addEventHandler = function (oTarget, sEventType, fnHandler) {
    if (oTarget.addEventListener) {
        oTarget.addEventListener(sEventType, fnHandler, false);
    } else if (oTarget.attachEvent) {
        oTarget.attachEvent("on" + sEventType, fnHandler);
    } else {
        oTarget["on" + sEventType] = fnHandler;
    }
};
        
EventUtil.removeEventHandler = function (oTarget, sEventType, fnHandler) {
    if (oTarget.removeEventListener) {
        oTarget.removeEventListener(sEventType, fnHandler, false);
    } else if (oTarget.detachEvent) {
        oTarget.detachEvent("on" + sEventType, fnHandler);
    } else { 
        oTarget["on" + sEventType] = null;
    }
};

EventUtil.formatEvent = function (oEvent) {
    if (isIE && isWin) {
        oEvent.charCode = (oEvent.type == "keypress") ? oEvent.keyCode : 0;

        oEvent.eventPhase = 2;
        oEvent.isChar = (oEvent.charCode > 0);
        oEvent.pageX = oEvent.clientX + document.body.scrollLeft;
        oEvent.pageY = oEvent.clientY + document.body.scrollTop;
        oEvent.preventDefault = function () {
            this.returnValue = false;
        };

        if (oEvent.type == "mouseout") {
            oEvent.relatedTarget = oEvent.toElement;
        } else if (oEvent.type == "mouseover") {
            oEvent.relatedTarget = oEvent.fromElement;
        }

        oEvent.stopPropagation = function () {
            this.cancelBubble = true;
        };

        oEvent.target = oEvent.srcElement;
        oEvent.time = (new Date).getTime();
    }
    return oEvent;
};

EventUtil.getEvent = function() {
    if (window.event) {
        return this.formatEvent(window.event);
    } else {
        return EventUtil.getEvent.caller.arguments[0];
    }
};
// Utilities

// take care of firebug console logging for other browsers
var console = window.console || {};
console.log = console.log || function(t) { }; 

// Utilities Class
function Utilities(){
	
	this.clip = function (obj, nTop, nRight, nBottom, nLeft) {
		var oStyle = this.getReference(obj);		
		oStyle.clip = "rect("+nTop+"px " + nRight + "px "+nBottom+"px "+nLeft+"px)";
	};
	this.getReference = function(sElementName){		
		var oRef;
		if(document.getElementById && document.getElementById(sElementName)) oRef = document.getElementById(sElementName).style;
		else if(document.all && document.all[sElementName]) oRef = document.all[sElementName].style;
		else if(document.layers) oRef = document[sElementName];
		return (oRef) ? oRef : 0;
	};
	this.getDom = function(sElementName){
		var oRef;
		if(document.all) oRef = document.all[sElementName];
		else if(document.layers) oRef = document[sElementName];
		else if(document.getElementById) oRef = document.getElementById(sElementName);
		
		return oRef;
	};
	this.setLyr = function(obj,lyr, dx, dy){
		var newX = this.findPosX(obj);
		var newY = this.findPosY(obj);
		var x = this.getReference(lyr);
		x.top = (newY+dy) + 'px';
		x.left = (newX+dx) + 'px';
	};
	this.setLyrWithOffset = function(obj,lyr, dx, dy, offset){
		//alert ( "offset = " + offset);
		var newX = this.findPosX(obj);
		var newY = this.findPosY(obj);
		var x = this.getReference(lyr);
		x.top = (newY+dy) + 'px';
		x.left = (newX+dx+offset) + 'px';
	};
	// Switch display-property. Hide if visible - show if not.
	this.toggleDisplay = function(strElement){
		var objRef = this.getReference(strElement);
		(objRef.display == "none" || objRef.display == "") ? this.showElement(strElement) : this.hideElement(strElement);	
	};
	// Show Element (visibility)
	this.showElement = function(strElementName){
		var objRef = this.getReference(strElementName);
		if(objRef) {
			objRef.display = "block";
			objRef.visibility = "visible";
		}
	};
	// Hide Element (visibility)
	this.hideElement = function(strElementName){
		var objRef = this.getReference(strElementName);
		if(objRef) {
			objRef.display = "none";
			objRef.visibility = "hidden";
		}
	};
	
	this.MOZALPHAMAX = 255./256.;
	

	
	// Get available Browser Window Width
	this.getWindowWidth = function() {
		return (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : ((window.innerWidth) ? window.innerWidth : document.body.clientWidth);
	};
	// Get available Browser Window Height
	this.getWindowHeight = function() {
		return (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : ((window.innerHeight) ? window.innerHeight : document.body.clientHeight);
	};
	
	// Retrieve the rendered height of an element
	this.getObjectHeight = function(obj){
		var elem = (this.isObject(obj)) ? obj : this.getDom(obj);
		var result = 0;
		if (elem.offsetHeight){
			result = elem.offsetHeight;
		} else if (elem.clip && elem.clip.height){
			result = elem.clip.height;
		} else if (elem.style && elem.style.pixelHeight){
			result = elem.style.pixelHeight;
		}
		return parseInt(result);
	};
	
	

	
	this.hasClass = function (el, sClass) {
		if(typeof(el) != "object") el = this.getDom(el);
		
		if (el)	{
			return new RegExp("(^|\\s+)"+sClass+"(\\s+|$)").test(el.className);
		}
		return false;		
	};
	
	this.addClass = function (el, sClass){
		//alert("add class " +  sClass);
		if(typeof(el) != "object") el = this.getDom(el);
		
		if (el)	{
			this.removeClass(el, sClass);
			
			el.className += ((el.className.length > 0) ? " " : '')+ sClass;
			return true;			
		}
		return false;		
	};
	
	this.removeClass = function (el, sClass) {
		//alert("remove class(' " + el + "', '" + sClass + "'");
		if(typeof(el) != "object") el = this.getDom(el);
		
		if (el) {
			var rep = el.className.match(' ' + sClass) ? ' ' + sClass : sClass;
     		el.className = el.className.replace(rep,'');
			return true;
		}
		return false;		
	};
	
	
	this.isUndefined = function (el) { return (typeof el == 'undefined');	};
	this.isDefined   = function (el) { return typeof el != 'undefined'; };
	this.isFunction  = function (el) { return typeof el == 'function'; };
	this.isNull      = function (el) { return typeof el == 'object' && !el; };
	this.isNumber    = function (el) { return typeof el == 'number' && isFinite(el); };
	this.isObject    = function (el) { return (el && typeof el == 'object') || this.isFunction(el);	};
	this.isString    = function (el) { return typeof el == 'string'; };
	this.isArray	 = function (el) { return this.isObject(el) && el.constructor == Array; };
	this.isUndefOrNull = function (el) { return (typeof el == 'undefined') || (typeof el == 'object' && !el) };
	this.objIsInstanceOf = function(obj, classObj) {
		while (obj.__proto__) { 
			if (obj.__proto__ === classObj) {
				return true;				
			}
			obj = obj.__proto__;			
		}
		return false;		
	};
	
	this.urlencode = function(string) {
		string = string.replace(/[\s#]/g, "+");
		string = string.replace(/ä/g, "%E4");
		string = string.replace(/Ä/g, "%C4");
		string = string.replace(/ö/g, "%F6");
		string = string.replace(/Ö/g, "%D6");
		string = string.replace(/ü/g, "%FC");
		string = string.replace(/Ü/g, "%DC");
		string = string.replace(/ß/g, "%DF");
		string = string.replace(/&/g, "%26");
		return string;
	};
	
	this.loadURL = function(sURL){
		location.href = sURL;
		return false;
	};
	
	this.win = {
		openDefault: function(strURL, numWidth, numHeight, wName){
			(!numWidth) ? numWidth = "780" : 0;
			(!numHeight) ? numHeight = "600" : 0;
			var strWindowName = (wName) ? wName : "defaultWindow";
			var strWinProps = "width=" + numWidth + ",height=" + numHeight + ",titlebar=no,status=yes,toolbar=no,menubar=no,scrollbars=yes,resizable=yes";
			this.open(strURL, strWindowName, strWinProps);
			return false;
		},
		// General function to open information windows
		// strURL = URL, numWidth = windowWidth, numHeight = windowHeight
		openInfo: function(strURL, numWidth, numHeight){
			var strWindowName = "infoWindow";
			var strWinProps = "width=" + numWidth + ",height=" + numHeight + ",titlebar=no,status=yes,toolbar=no,menubar=no,scrollbars=no,resizable=yes";
			this.open(strURL, strWindowName, strWinProps);
			return false;
		},
		open: function(strURL, strWindowName, strWinProps){
			var objWin = window.open(strURL, strWindowName, strWinProps);
			objWin.focus();
		}
	};

	


	

}
var goUtils = new Utilities();







// details.js
var goDetails = {
		init: function(){
		//alert("init() called");
		// Set object for navIds and layerIds
		goDetails.setNavObject();
		
		goDetails.oAdNav = goUtils.getDom('detailsNaviStart');
		
		// Get initial set adView-Type
		var sAdViewType = goDetails.getAdViewTypeFromUrl();
		if(!sAdViewType) return;
		else goDetails.setCurrentAdView(sAdViewType);
		
		// Write CSS-Definitions for Ad-Layers (visible or hidden)
		goDetails.setSectionStyles();
		// store current NavId and LayerId
		goDetails.sCurrentNavId = goDetails.oNav[sAdViewType].sNavId;		
		goDetails.setCurrentLayerName(goDetails.oNav[sAdViewType].sLayerId);
		
		goDetails.highlightCurrentNav();
		
		goDetails.setNavHandlers();
	},
	setNavHandlers: function(){
		//alert("setNavHandlers() called");
		EventUtil.addEventHandler(this.oAdNav, "click", this.setAdViewType);
	},
	setAdViewType: function(){
		var evt = EventUtil.getEvent();
		evt.preventDefault();
		//alert("setAdView() called");
		
		// Find id of clicked li-element
		var obj = evt.target;
		if(obj.nodeName.toLowerCase() == "ul") return;
		while(obj.nodeName.toLowerCase() != "li" && obj.nodeName.toLowerCase() != "body") obj = obj.parentNode;
		
		// Remove href of anchor because of preventDefault-failure in Safari
		obj.getElementsByTagName("a")[0].href = "#";
		
		var sAdViewType = obj.getAttribute("adviewtype");
		var sAdViewTitle = obj.getElementsByTagName("a")[0].getAttribute("title");
		var sAdViewChannel = obj.getAttribute("channel");
		//alert(sAdViewChannel);
		// Switch adView-Type
		goDetails.switchSearchType(sAdViewType, sAdViewTitle, sAdViewChannel);
	},
	setCurrentAdView: function(sAdViewType){
		this.sAdViewType = sAdViewType;
	},
	getCurrentAdView: function(){
		return this.sAdViewType;
	},
	setNavObject: function(){
		this.oNav = {
						
			page1:{
				sLayerId: "adView_page1",
				sNavId: "adNav_page1"
			},
			page2:{
				sLayerId: "adView_page2",
				sNavId: "adNav_page2"
			},
			page3:{
				sLayerId: "adView_page3",
				sNavId: "adNav_page3"
			},
			page4:{
				sLayerId: "adView_page4",
				sNavId: "adNav_page4"
			},
			page5:{
				sLayerId: "adView_page5",
				sNavId: "adNav_page5"
			},
			page6:{
				sLayerId: "adView_page6",
				sNavId: "adNav_page6"
			},
			page7:{
				sLayerId: "adView_page7",
				sNavId: "adNav_page7"
			},
			page8:{
				sLayerId: "adView_page8",
				sNavId: "adNav_page8"
			},
			page9:{
				sLayerId: "adView_page9",
				sNavId: "adNav_page9"
			},
			page10:{
				sLayerId: "adView_page10",
				sNavId: "adNav_page10"
			}

		}
	},
	highlightCurrentNav: function(){
		// highlight clicked li
		// Return if class already added
		if(goUtils.hasClass(this.getCurrentNavId(), "on")) return;
		// otherwise add class
		goUtils.addClass(this.getCurrentNavId(), "on");
		
		// set last li to default
		goUtils.removeClass(this.getLastNavId(), "on");
		//alert(this.getLastNavId());
	},
	setCurrentNavId: function(sId){
		// Store last NavId
		this.setLastNavId(this.getCurrentNavId());
		// set current NavId
		this.sCurrentNavId = sId;
	},
	getCurrentNavId: function(){
		return (this.sCurrentNavId) ? this.sCurrentNavId : null;
	},
	setLastNavId: function(sId){
		this.sLastNavId = sId;
	},
	getLastNavId: function(){
		return (this.sLastNavId) ? this.sLastNavId : null;
	},
	switchSearchType: function(sType, sTitle, sChannel){
		var sLayer, sNavId;
		sType.toLowerCase();
	        //alert ( sChannel );	
		if (this.getCurrentAdView() == sType) return;
		
		// Store AdViewType
		goDetails.setCurrentAdView(sType);
		
		// Show Search layer and hide last layer
		goUtils.showElement(this.oNav[sType].sLayerId);
		
		//alert("show " + this.oNav[sType].sLayerId);
		this.setCurrentLayerName(this.oNav[sType].sLayerId);
		if(this.getLastLayerName()) goUtils.hideElement(this.getLastLayerName());
		
		// Set Navigation-Properties
		// Store current navID
		this.setCurrentNavId(this.oNav[sType].sNavId);
		// Activate and highlight clicked Nav-Element
		this.highlightCurrentNav();
				
	},
	setCurrentLayerName: function(sLayer){
		// Store last layer
		this.setLastLayerName(this.sCurrentLayerName);
		// set current layer
		this.sCurrentLayerName = sLayer;		
	},
	getCurrentLayerName: function(){
		return (this.sCurrentLayerName) ? this.sCurrentLayerName : null;
	},
	setLastLayerName: function(sLayer){
		this.sLastLayerName = sLayer;
	},
	getLastLayerName: function(){
		return (this.sLastLayerName) ? this.sLastLayerName : null;
	},
	setSectionStyles: function(){
		var sCurrentAdView = this.getCurrentAdView();
		
		//alert("sCurrentAdView = " + sCurrentAdView);
		
		if(!this.oNav) this.setNavObject();
		
		document.write('<style type="text/css" media="all">');
		for(var o in this.oNav){
			//alert(this.oNav[o].sLayerId);
			document.write('#' + this.oNav[o].sLayerId + '{display:');
			document.write((this.oNav[o] == this.oNav[sCurrentAdView]) ? 'block' : 'none');
			document.write(';}');
		}
		document.write('</style>');
	},
	getAdViewTypeFromUrl: function(){
		var sHash = location.hash;
		return (sHash == "") ? this.getFirstTabElement() : sHash.slice(1);
	},
	getFirstTabElement: function(){
		// If detailsNavi available return Adview-Type - otherwise return false
		return (this.oAdNav && this.oAdNav.getElementsByTagName("li").length > 0) ? this.oAdNav.getElementsByTagName("li")[0].getAttribute("adviewtype") : false;
	},
	resizeToContentHeight: function(n){// Resize iFrame to content
		nAddSpace = 10;
		var oRef = goUtils.getReference(n);
		p = (document.all) ? 'scroll' : 'offset';
		//alert(eval("window.frames['iFrameRoute'].document.getElementsByTagName('body')[0]." + p + "Height+" + nAddSpace) + "px");
		oRef.height = eval("window.frames['iFrameRoute'].document.getElementsByTagName('body')[0]." + p + "Height+" + nAddSpace) + "px";
	},
	loadURL: function(sURL){
		// Open URL in opener if available
		(window.opener && !window.opener.closed) ? opener.goUtils.loadURL(sURL) : goUtils.loadURL(sURL);
		return false;
	}


}

