/* some basic wob functions

	most - if not all - of them require prototype
*/
/**
 * Greps all <a> tags with attribute rel="external" and
 * inserts a target="_blank" into the DOM tree.
 */
document.observe("dom:loaded", function() {

    $$('a[rel="external"]').each(function(link) {
        if(link.readAttribute('href') != '' && link.readAttribute('href') != '#') {
            link.writeAttribute('target','_blank');
        }
    });
});
/**
 * Prevent embedding a page within a frame
 * from a external host.
 */
document.observe("dom:loaded", function() {
	try {
		if(self != top) { // we have frames
			try {
				url = top.location.href; // if this is denied by the Same Domain Policy
			} catch(e) { // redirect
				top.location.href = location.href;
			}
		}
	} catch(e) {};
});
/**
 * Open/Close Handler class for secondary navigation/price bon
 */
var secondNavHandler = Class.create({
	
	 // open
	
	/**
	 * Constructor
	 *
	 * set some defaults
	 */
	initialize: function() {
		this.status=1;
		this.elem = $('sntog');
		if (this.elem != null) {
			this.elem.observe('click', this.toggle.bind(this));
		}
		return true;
	}
	/**
	 * Toggle Secondnav Status
	 *
	 */
	,toggle: function(e) {
		if (this.elem == null) return true;
		if (this.elem.down('img').src.endsWith('sn_up.gif')) {
			this.status=0;
			return this.close();
		}
		this.status=1;
		return this.open();
	}
	/**
	 * Close Secondnav
	 *
	 */
	,close: function() {
		if (this.elem == null) return true;
		if(this.elem.down('img').src.endsWith('sn_down.gif')) {
			return true
		};
		Effect.SlideUp('snslide', { duration: 1.0, queue: 'end', scope: 'slider' });
		this.elem.down('img').src = "/_gfx/sn_down.gif";
		this.status=0;
		return true;
	}
	/**
	 * Open Secondnav
	 *
	 */
	,open: function() {
		if (this.elem == null) return true;
		if(this.elem.down('img').src.endsWith('sn_up.gif')){
			return true;
		} 
		Effect.SlideDown('snslide', { duration: 1.0 , queue: 'end', scope: 'slider'});
		this.elem.down('img').src = "/_gfx/sn_up.gif";
		this.status=1;
		return true;

	}
	
	/**
	 * Close Secondnav
	 *
	 */
	,autoclose: function() {
		if (this.elem == null) return true;
		//alert (this.status)
		//if (this.status==1) return true;
		if(this.elem.down('img').src.endsWith('sn_down.gif')) return true;
		Effect.SlideUp('snslide', { duration: 1.0 , queue: 'end', scope: 'slider' });
		this.elem.down('img').src = "/_gfx/sn_down.gif";
		return true;
	}
	/**
	 * Open Secondnav
	 *
	 */
	,autoopen: function() {
		if (this.elem == null) return true;
		if (this.status==0) return true;
		if(this.elem.down('img').src.endsWith('sn_up.gif')) return true;
		Effect.SlideDown('snslide', { duration: 1.0 ,queue: 'end',scope: 'slider'  });
		this.elem.down('img').src = "/_gfx/sn_up.gif";
		return true;
	}
	
});
document.observe('dom:loaded', function() {
	secondNavHdl = new secondNavHandler(); 
});
	/**
	 * Second nav Handler API compatibility to old global functions
	 */
	function toggleSN() {
		return secondNavHdl.toggle();
	}
	function closeSN() {
		return secondNavHdl.close();
	}
	function openSN() {
		return secondNavHdl.open();
	}

function fixHover() {
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {

		$$('div[class="main"] ul li ').each(function(element) {
			if (element == null) return true;
			element.observe('touchstart', function(){

		      	console.log("touch started");
		    });
		
			element.observe('touchend', function(){
		        console.log("touch ended");
		    });
		});
	}
}

document.observe("dom:loaded",fixHover);

/**
 * Observe Modell-Nav Links and change images accordingly
 */
 
function observeModellNav() {
	timeout = null;

	

	var modellnav = $$('div[class="modellnav"]>div[class="links"]>div>a');// xpath to div's containing the links#
	
	try {
		var alt = modellnav[0].innerHTML.strip();
		var images = modellnav[0].parentNode.parentNode.parentNode.select('div div img');
		var startimgsrc   = images[0].src ;
		var startimgalt   =	images[0].alt;
		var startimgtitle =	images[0].title ;	
	
	}
	
	
	
	catch(err) {}
	for (var i=0; i<modellnav.length; i++) {
	
		modellnav[i].innerHTML.strip();
		Event.observe(modellnav[i],'mouseover', function(event) {
			clearTimeout(timeout);
			evElement = Event.element(event); // the a href
			var alt = evElement.innerHTML.strip();
			// images = evElement.parentNode.parentNode.parentNode.select('div[class="image"]>div>img'); // in fact, there's only one image, select returns an array.
			var images = evElement.parentNode.parentNode.parentNode.select('div div img');
			images[0].src = "/_gfx/modellnav/" + alt.toLowerCase().replace(" ","_") + ".jpg";
			images[0].alt = alt + " KENNENLERNEN";
			images[0].title = alt + " KENNENLERNEN";
		
			$('navkeybutton').src ="/_gfx/modellnav/" + alt.toLowerCase().replace(" ","_") + "_button.gif";
			$('navkeybutton').alt = alt + " FINANZIEREN";
			$('navkeybutton').title = alt + " FINANZIEREN";
			
			switch (alt) {
    			case "i10": 			$('navkeyvis').href = "/pages/modelle/i10/index.html"; break;
 			    case "i20":				$('navkeyvis').href = "/pages/modelle/i20/index.html"; break;
 				case "ix20":			$('navkeyvis').href = "/pages/modelle/ix20/index.html"; break;
				case "i30":				$('navkeyvis').href = "/pages/modelle/i30/index.html"; break;
				case "i30cw":			$('navkeyvis').href = "/pages/modelle/i30cw/index.html"; break;
				case "ix35":			$('navkeyvis').href = "/pages/modelle/ix35/index.html"; break;
				case "VELOSTER":		$('navkeyvis').href = "/pages/modelle/veloster/index.html"; break;
				case "i40cw":			$('navkeyvis').href = "/pages/modelle/i40cw/"; break;
				case "SANTA FE":		$('navkeyvis').href = "/pages/modelle/santafe/index.html"; break;
				case "ix55":			$('navkeyvis').href = "/pages/modelle/ix55/index.html"; break;
				case "GENESIS COUPE":	$('navkeyvis').href = "/pages/modelle/genesiscoupe/index.html"; break;
				case "H-1 TRAVEL":		$('navkeyvis').href = "/pages/modelle/h1_travel/index.html"; break;
				case "H-1 CARGO":		$('navkeyvis').href = "/pages/modelle/h1_cargo/index.html"; break;
				case "ALLE MODELLE":	$('navkeyvis').href = "/pages/modelle/alle/index.html"; break;
				
    			default: $('navkeyvis').href = "/pages/modelle/alle/index.html"; 
  			}
			
			$$('div[class="flyout"]').each(function(singleflout) {
				singleflout.hide();
			});
		   	$$('div[class="flyoutblack"]').each(function(singleflout) {
				singleflout.hide();
			});
			$("nav_" + alt.toLowerCase().replace(" ","_")).show();
		
		
		//	Event.stop(event);

		});
		Event.observe(modellnav[i],'mouseout', function(event) {

			clearTimeout(timeout);
			timeout=setTimeout(function(){
				images = modellnav[0].parentNode.parentNode.parentNode.select('div div img');
				images[0].src = startimgsrc;
				images[0].alt = startimgalt;
				images[0].title = startimgtitle;

			var links = $$('div[class="modellnav"]>div[class="links"]>div>a')
			for (var i=0; i<links.length; i++) {
				var linkpath = links[i].pathname;
				// on IE6 linkpath doesn't start with a "/"
				if (linkpath.substring(0,1) != "/") linkpath = "/"+linkpath;
				var linkmatches=linkpath.match('^\/.*\/(.*)\/(.*)\/.*');
				var pathmatches=location.pathname.match('^\/.*\/(.*)\/(.*)\/.*');
				if(linkmatches && pathmatches) {
					if (linkmatches[2] == pathmatches[2]) {
						try{
							var alt = links[i].innerHTML.strip();
							// images = evElement.parentNode.parentNode.parentNode.select('div[class="image"]>div>img'); // in fact, there's only one image, select returns an array.
							var images = links[i].parentNode.parentNode.parentNode.select('div div img');
							images[0].src = "/_gfx/modellnav/" + alt.toLowerCase().replace(" ","_") + ".jpg";
							images[0].alt = alt
							images[0].title = alt;
	
						}
						catch (err) {}
					}
				}
			}

			},15000);

		});
	}
}
document.observe("dom:loaded",observeModellNav);
/**
 * set class="active" on link to current page in subnav
 */
function setSubnavActive() {
	var links = $$('div[id="snslide"] a:not([class])');
	for (var i=0; i<links.length; i++) {
		var linkpath = links[i].pathname;
		// on IE6 linkpath doesn't start with a "/"
		if (linkpath.substring(0,1) != "/") linkpath = "/"+linkpath;
		if (location.pathname == linkpath) {
			links[i].writeAttribute("class","active");
		}
	}
}
document.observe("dom:loaded",setSubnavActive);

/**
 * set class="active" on link to current page in main
 *  and also highlight the main navigation entry
 *  on modell it chnages the picture
 */
function setDropdownActive() {
	var links = $$('li[class="top"]  a:not([class])');
	for (var i=0; i<links.length; i++) {
		var linkpath = links[i].pathname;
		// on IE6 linkpath doesn't start with a "/"
		if (linkpath.substring(0,1) != "/") linkpath = "/"+linkpath;
		var linkmatches=linkpath.match('^\/.*\/(.*)\/(.*)\/.*');
		var pathmatches=location.pathname.match('^\/.*\/(.*)\/(.*)\/.*');
		if(linkmatches && pathmatches) {
			if (linkmatches[2] == pathmatches[2]) {
				links[i].writeAttribute("class","active");
				try{
					var alt = links[i].innerHTML.strip();
					var images = links[i].parentNode.parentNode.parentNode.select('div div img');
					images[0].src = "/_gfx/modellnav/" + alt.toLowerCase().replace(" ","_") + ".jpg";
					images[0].alt = alt
					images[0].title = alt;
				}
				catch (err) {}
			}

			if (linkmatches[1] == pathmatches[1]) {
				$('main_'+linkmatches[1]).setStyle({
					color: '#153C80'
				});
			}
		}
	}
}
document.observe("dom:loaded",setDropdownActive);

/**
 * add event listener to download links for Google Analytics tracking
 */
function observeDownloadLinks() {
	// fetch all a tags within div#content
	var links = $$('div[id="content"] a');
	if (links.length == 0) return;
	for (var i=0; i<links.length; i++) {
		if (links[i].href.length == 0) continue; // empty link ?
		var link_path = links[i].pathname;
		if (location.host == links[i].hostname) {
			if (link_path.match(/\.(doc|pdf|xls|ppt|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)$/)) {
				// open PDF, DOC,... in a new Window
				if (link_path.match(/\.(pdf|doc|xls|ppt|js|css)$/)) links[i].target = "_blank";
				// observe the onclick event for google analytics
				links[i].observe('click', function(event) {
					evElement = Event.element(event);
					if (typeof(pageTracker) == 'object')
						pageTracker._trackPageview(evElement.pathname);
				})
			}
		}
	}
}
document.observe("dom:loaded",observeDownloadLinks);

/**
 * zubehör tabs
 */

var inpageTabs = function(opt){
  var o = opt;
  var load = function() {

		$A(o.tabs).each(function(s) {
			var tab='inpage-tab_'+s;
			var nav='inpage-nav_'+s;
			try {
				if($(tab)) return false;
				$(tab).hide();
				$(nav).observe('click', function(e){ // die Zeile schmeisst einen Fehler, wenn keine Zubehör nav da ist!
					$A(o.tabs).each(function(hide) {
							try {
								var tabhide='inpage-tab_'+hide;
								$(tabhide).hide();
								var inactive_nav='inpage-nav_'+hide;
								$(inactive_nav).writeAttribute("class");
							}
							catch(err) {}
						}
					);
					var tabshow='inpage-tab_'+s;
					$(tabshow).show();
					var active_nav='inpage-nav_'+s;
					$(active_nav).writeAttribute("class","active");
					}
				);
			}
			catch(err) {}

		});
	try {
		var active_content='inpage-tab_'+o.active;
		var content_element = $(active_content);
		if (content_element) content_element.show();
		var active_nav='inpage-nav_'+o.active;
		var nav_element = $(active_nav);
		if (nav_element) nav_element.writeAttribute("class","active");
	}
	catch(err) {}
  };

if (typeof $('inpage-tabs') == 'object')
	document.observe("dom:loaded",load);
}
inpageTabs({
  tabs : ['one','two','three','four','five'],
  active : 'one'
});


/**
 * Class to handle Background-Position,
 * 	which is different between IE and the rest of the World.
 * This class needs prototype.js
 *
 * Currently always uses "px" as unit.
 */
var bgImageHandler = Class.create({
	
	/**
	 * Constructor
	 *
	 * set some defaults
	 */
	initialize: function(elem) {
		this.elem = $(elem);
		this.isIE = Prototype.Browser.IE;
		if (this.isIE) {
			this.posX = this.elem.getStyle('backgroundPositionX');
			this.posY = this.elem.getStyle('backgroundPositionY');
		} else {
			var splitRes = this.elem.getStyle('backgroundPosition').split(' ');
			this.posX = splitRes[0];
			this.posY = splitRes[1];
		}
	},
	/**
	 * setter for x-coordinate
	 */
	setX: function(pixels) {
		
		if (this.isIE) {
			this.elem.setStyle({backgroundPositionX: pixels + 'px'});
		} else {
			this.elem.setStyle({backgroundPosition: pixels + 'px' + ' ' + this.posY });
		}
		
		return;
	},
	/**
	 * setter for y-coordinate
	 */
	setY: function(pixels) {
		
		if (this.isIE) {
			this.elem.setStyle({backgroundPositionY: pixels + 'px'});
		} else {
			this.elem.setStyle({backgroundPosition: this.posX + ' ' + pixels + 'px'});
		}
		
		return;
	}
}); // end Class bgImageHandler


/**
 * technik-lexikon tabs
 */

function observePathnavTabs() {
	try{
		var pathnavtabs = ['antrieb', 'fahrwerk', 'innenraum', 'karosserie', 'komfort', 'sicherheit'];
		pathnavtabs.each(function(element){
			if ($('tab_' + element).hasClassName('active')) {
				var bgh = new bgImageHandler($('tab_' + element));
				bgh.setY(-42);
				$('tab_content_' + element).show();
			} else if ($('tab_' + element).hasClassName('visited')) {
				var bgh = new bgImageHandler($('tab_' + element));
				bgh.setY(-0);
				$('tab_content_' + element).hide();
			} else {
				var bgh = new bgImageHandler($('tab_' + element));
				$('tab_content_' + element).hide();
				//bgh.setY(0);
				bgh.setY(-0);
			}
		});
	
		pathnavtabs.each(function(element){
	
			if($('tab_' + element) === null) { return true; }
			$('tab_' + element).observe('click', function(event) {
				pathnavtabs.each(function(e){
					$('tab_content_' + e).hide();
					$('tab_' + e).removeClassName('active');
					var bgh = new bgImageHandler($('tab_' + e));
					bgh.setY(-0);	
				});
				$('tab_content_' + element).show();
				$('tab_' + element).addClassName('active');
				var bgh = new bgImageHandler($('tab_' + element));
				bgh.setY(-42);
			});
			return null;
		});
		
		return null;
	}
	catch(e){
		return null;
	}
}
document.observe("dom:loaded",observePathnavTabs);

/* Bei der Probefahrt wird die motorisierug abhängig vom Modell eingeblendet */


function probefahrtMotorisierungFromQuerystring(){
	typ='';
	var elem = $('normal_oder_diesel');
	if (elem == null) return true;
	var url=document.URL;
	var query=url.parseQuery();
	if (query.modell_id != null) {
		typ= query.modell_id;
		probefahrtMotorisierung(typ);
	}
	return true;
}
document.observe("dom:loaded",probefahrtMotorisierungFromQuerystring);


function probefahrtMotorisierung(typ) {
	typ = typ.split(".");
	if (typ[1]=="benzin"){
		document.getElementById('normal_oder_diesel').style.display="none";
		document.getElementById('diesel').style.display="none";
		document.getElementById('normal').style.display="block";
	} else if (typ[1]=="diesel"){
		document.getElementById('normal').style.display="none";
		document.getElementById('normal_oder_diesel').style.display="none";
		document.getElementById('diesel').style.display="block";
	} else {
		document.getElementById('normal').style.display="none";
		document.getElementById('diesel').style.display="none";
		document.getElementById('normal_oder_diesel').style.display="block";
	}
}

/*
	Konfigurator

  */
function konfigfarbe(name){
/*
	Tabellentext auf fontWeight normal setzen
	var zellen=document.getElementsByName(name)[0].parentNode.parentNode.parentNode;
		zellen=zellen.firstChild;
	while (zellen!=null) {
		if(zellen.nodeName=="TR") zellen.style.fontWeight="normal";
		zellen = zellen.nextSibling;
	}
*/
	// alle(!) Bilder verstecken

	var bilder = $$('div[id="konfigurator_img"] img');

	//var bilder=document.getElementsByTagName("img");
	i=0;
	while (bilder[i]) {
		bilder[i].style.visibility="hidden";
		i++;
	}

	var text = $$('div[id="konfigurator_img"] div[class="car-description"]');

	//var bilder=document.getElementsByTagName("img");
	i=0;
	while (text[i]) {
		text[i].style.visibility="hidden";
		i++;
	}


	//selectbox ermitteln
	id = name.slice(6,8)-1;
	document.getElementsByName("farbe")[id].checked="true";

	//auswahl highlighten
	//document.getElementsByName(name)[1].parentNode.parentNode.style.fontWeight="bold";
	//document.getElementsByName(name)[2].style.visibility="visible";

	var preis='konfigtext-'+ name;
	//alert (preis);
	try{
		$(preis).style.visibility="visible";
	} catch(e) {}

	document.getElementsByName(name)[0].style.visibility="visible";
}

function observCo2() {
	var elem = $('co2');
	if (elem == null) return true;
	elem.hide();
	var elem = $('overlay');
	if (elem == null) return true;
	elem.toggle();
	var elem = $('emission');
	if (elem == null) return true;
	$('emission').observe('click', function(e){
		//$('co2').setStyle({cursor:'pointer'});

		if (!$("co2").visible()) {
			//$('co2').setStyle({cursor:'pointer'});
			//var h=document.viewport.getHeight();
			//var w=document.viewport.getWidth();
			//var scroll=document.viewport.getScrollOffsets()
			//var wh=$("outer").getHeight();
			//var wh=wh+55;
			//document.getElementById("overlay").style.height = wh + "px";
			//Effect.Appear('overlay', { duration: 0.5 ,from:0.0, to:0.30});
			Effect.Appear('co2', { duration: 0.5 ,from:0.0, to:0.96});
		}
	});

	$('co2').observe('click', function(e){
		//$('co2').setStyle({cursor:'auto'});
		//Effect.Fade('overlay', { duration: 0.5 ,from:0.30, to:0.0});
		Effect.Fade('co2',{ duration: 0.5 ,from:0.96, to:0.0});
	});
}

document.observe("dom:loaded",observCo2);




function observeEmission() {
	var elem = $('emissiontable');
	if (elem == null) return true;
	elem.hide();
	var elem = $('overlay');
	if (elem == null) return true;
	elem.toggle();
	var elem = $('emission');
	if (elem == null) return true;

	$('emission').observe('click', function(e){
		if (!$("emissiontable").visible()) {
			var h=document.viewport.getHeight();
			var w=document.viewport.getWidth();
			var scroll=document.viewport.getScrollOffsets()
			var wh=$("outer").getHeight(); wh+=55;
			$("overlay").setStyle({ height: wh + "px" });
			//document.getElementById("overlay").style.width = w + "px";

			// place image
			//	var imgw= scroll.left + ((w/2) - ($("emissiontable").getWidth()/2));
			var imgh= scroll.top + ((h/2)- ($("emissiontable").getHeight()/2));

			$("emissiontable").setStyle({top: imgh+"px"});
			//	$("emissiontable").setStyle({left: imgw+"px;"});
			Effect.Appear('overlay', { duration: 0.5 ,from:0.0, to:0.30});
			Effect.Appear('emissiontable', { duration: 0.5 ,from:0.0, to:0.96});
		}
	});

	$('emissiontable').observe('click', function(e){
		//$('co2').setStyle({cursor:'auto'});
		Effect.Fade('overlay', { duration: 0.5 ,from:0.30, to:0.0});
		Effect.Fade('emissiontable',{ duration: 0.5 ,from:0.96, to:0.0});
	});

}
document.observe("dom:loaded",observeEmission);

function observeFahrzeugschein() {
	var elem = $('fahrzeugschein');
	if (elem == null) return;
	elem.hide();
	var elem = $('fahrzeugscheinlink');
	if (elem == null) return;
	$('fahrzeugscheinlink').observe('click', function(e){
		var mouseY = Event.pointerY(e) + 'px';
		$('fahrzeugschein').setStyle({
			position: 'absolute',
			top: mouseY
		});
		Effect.Appear('fahrzeugschein', { duration: 0.5 ,from:0.0, to:1.0});
	});
	$('fahrzeugschein').observe('click', function(e){
		$('fahrzeugschein').setStyle({cursor:'pointer'});
		Effect.Fade('fahrzeugschein',{ duration: 0.5 ,from:1.0, to:0.0});
	});

}
document.observe("dom:loaded",observeFahrzeugschein);

function changeMandatory(type) {
	var mandatory=$A(["span.mandatoryemail","span.mandatoryphone","span.mandatorypost","span.mandatoryfax"]);
	var error=$A(["span.emailerror","span.phoneerror","span.posterror","span.faxerror"]);
	//var elem = $(type);
	//if (elem == null) return true;
	mandatory.each(function(s) {
			$$(s).each(function(elem) {
			if (elem == null) return true;
			elem.hide();
		});
	});
	error.each(function(s) {
			$$(s).each(function(elem) {
			if (elem == null) return true;
			elem.hide();
		});
	});


	var elem="span.mandatory"+type;
	$$(elem).each(function(i) {
		if (i == null) return true;
		i.show();
	});
	var elem="span."+type+"error";
	$$(elem).each(function(i) {
		if (i == null) return true;
		i.show();
	});

}

function hideMandatory() {
	var mandatory=$A(["email","phone","post","fax"]);
	mandatory.each(function(s) {
		if (getCheckedValue(document.getElementsByName("contactform")) != s) {
			var span="span.mandatory"+s;
			$$(span).each(function(elem) {
				if (elem !== null) elem.hide();
				return true;
			});
		}
	});
}
document.observe("dom:loaded",hideMandatory);



function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


function HideFlash() {
	//alert ('hide');
	$('xmas').hide();
}


function hideProspektCheckbox() {
try
{

		if ($post==false) {
			hidePCheckbox();
		} else {
			showProspektCheckbox();
			var radio=document.prospekt.way;
			radio[1].checked=true;
		}
}
catch(err)
{
//do nothing
}

}
document.observe("dom:loaded",hideProspektCheckbox);


function hidePCheckbox() {
		$$('div[class="prospektcheckbox"]').each(function(i) {
			if (i == null) return true;
			i.hide();
		});
		$$('div[class="prospektdowload"]').each(function(i) {
			if (i == null) return true;
			i.show();
		});
		if ($('weiter')== null) return true;
		$('weiter').setOpacity(0.0);
}


function showProspektCheckbox() {
	$$('div[class="prospektcheckbox"]').each(function(i) {
		if (i == null) return true;
		i.show();
	});
	$$('div[class="prospektdowload"]').each(function(i) {
		if (i == null) return true;
		i.hide();
	});
	if ($('weiter')== null) return true;
	$('weiter').setOpacity(1.0);
}

function hideAnswer() {
		$$('div[class="closed"]').each(function(i) {
		if (i == null) return true;
		i.hide();
	});
}


document.observe("dom:loaded",hideAnswer);

var answer= {
    timeout : null,
    toggle : function(e){
        clearTimeout(this.timeout);
		var question = 'question_'+e;
		var answer = 'answer_'+e;
        if($(answer).style.display == 'none'){
            this.timeout = setTimeout(function(){new Effect.SlideDown(answer, {duration:.7, fps:100, queue: 'end'})},400);
			$(question).removeClassName('open');
			$(question).addClassName('close');
			$(question).addClassName('active');
        } else{
            this.timeout = setTimeout(function(){new Effect.SlideUp(answer, {duration:.7, fps:100,queue: 'front'})},300);
			$(question).removeClassName('close');
			$(question).removeClassName('active');
			$(question).addClassName('open');
			
        }
    }
}


/**
 * Fast Utility Function to parse a URL.
 *
 * This function creates a new anchor element and uses location
 * properties (inherent) to get the desired URL data. Some String
 * operations are used (to normalize results across browsers).
 *
 * Found at http://james.padolsey.com/javascript/parsing-urls-with-the-dom/
 * Usage: var myURL = parseURL('http://abc.com:8080/dir/index.html?id=255&m=hello#top');
 *
 */
function parseURL(url) {
    var a =  document.createElement('a');
    a.href = url;
    return {
        source: url,
        protocol: a.protocol.replace(':',''),
        host: a.hostname,
        port: a.port,
        query: a.search,
        params: (function(){
            var ret = {},
                seg = a.search.replace(/^\?/,'').split('&'),
                len = seg.length, i = 0, s;
            for (;i<len;i++) {
                if (!seg[i]) { continue; }
                s = seg[i].split('=');
                ret[s[0]] = s[1];
            }
            return ret;
        })(),
        file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1],
        hash: a.hash.replace('#',''),
        path: a.pathname.replace(/^([^\/])/,'/$1'),
        relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [,''])[1],
        segments: a.pathname.replace(/^\//,'').split('/')
    };
}

/**
 * PSYMA
 * 
 */
function addPsymaScript() {
	var u = parseURL(window.location);
	if (u.path.match(/(\/pages\/index\.html|\/pages\/modelle\/i30\/einfachdreifachbesser\.html|\/konfi\/|\/modelle\/(alle|ix35|i30|i20|i10|i30cw|santafe)\/index\.html|modelle\/ix35\/(aussen|innen|technik|varianten)\.html|\/beratung\/haendlersuche\/index\.html|\/dealersearch\/(index|search)|\/gebrauchtwagen\/autoboerse\/autoboerse\.html|\/modelle\/i30\/varianten\.html)/i) ) {
		var fileref=document.createElement('script')
		fileref.setAttribute("type","text/javascript")
		// fileref.setAttribute("defer","defer")
		fileref.setAttribute("src", "http://scripts.psyma.com/scripts/abde/hyundai.php")
		document.getElementsByTagName("body")[0].appendChild(fileref)
		// console.log(u.path);
		// alert("PSYMA Script aufgerufen: " + u.path);
	}
}
/** This doesn't work with Psyma ! See dev/html/header_full
document.observe("dom:loaded",addPsymaScript);
*/
/***
 * ALTE FUNKTIONEN
 *
 */
/**
 * toogle second nav - deprecated! See above.
 */
/*
function toggleSN() {
	var elem = $('sntog');
	if (elem == null) return true;
	elem.observe('click', function(event) {
		var image = elem.getElementsByTagName('img')[0];
		if (image.src.endsWith("sn_up.gif")) {
			Effect.SlideUp('snslide', { duration: 1.0 });
			image.src = "/_gfx/sn_down.gif";
		} else {
			Effect.SlideDown('snslide', { duration: 1.0 });
			image.src = "/_gfx/sn_up.gif";
		}
		return false;
	});
	return true;
}
document.observe("dom:loaded",toggleSN);
*/
/**
 * toogle second nav
 */
/*
function closeSN() {
	var elem = $('sntog');
	if (elem == null) return true;
	var image = elem.getElementsByTagName('img')[0];
	Effect.SlideUp('snslide', { duration: 1.0 });
	image.src = "/_gfx/sn_down.gif";
	return true;
}
*/
/**
 * toogle second nav
 */
/*
function openSN() {
	var elem = $('sntog');
	if (elem == null) return true;
	var image = elem.getElementsByTagName('img')[0];
	Effect.SlideDown('snslide', { duration: 1.0 });
	image.src = "/_gfx/sn_up.gif";
	return true;
}



function closeLayer() {
	$('xmaslayer').hide();
	$('xmaslayer').remove();
}

window.setTimeout(function() {
	try {
		playerVersion = swfobject.getFlashPlayerVersion();
		if (playerVersion.major != 0 ) exit();
		$('page').show();
		$('xmaslayer').remove();
	} catch(e) {};
}, 10000);


function layerLoaded() {
	$('page').show();
}
*/
