/****************\
* Formularfelder leeren 
\*'**************/
function clearValue(feld,formname) {
	document.forms[formname].elements[feld].value = "";
	return true;
}

/****************\
 * DropDownNavi  - Hilfsmethoden für IE6
\*'**************/
function showItem(element){
	$(element).addClassName('hover');
	//$(element).down('ul').appear({ duration: 0.5 });
}

function hideItem(element){
		$(element).removeClassName('hover');
		//$(element).down('ul').fade({ duration: 0.5 });
}

function triggerNavigationMenu(element){
	Element.addClassName(element, 'hover');
	
	Event.observe(Element.down(element,'ul'), 'mouseout', function(e) {
		if(!Position.within(Element.down(element,'ul'),Event.pointerX(e),Event.pointerY(e))) {
			$(element).removeClassName('hover');
		}
	});
}

function showProductItem(element){
	if(BrowserDetect.browser == "Explorer" && BrowserDetect.version < 7)
		$(element).addClassName('hover');
	
	var container = $(element).down('.scroll_right').next('.scrollcontainer').down('.bigscrollbox');

	var children = $(container).childElements();
    var childcount = children.length;

    if(childcount <=3){  
    	$(element).down('.scroll_right').addClassName('scroll_r_grey');
	   }
}
function hideProductItem(element){
	if(BrowserDetect.browser == "Explorer" && BrowserDetect.version < 7)
		$(element).removeClassName('hover');
}

function displayOverlay() {
	var browser = (function x(){})[-5]=='x'?'FF3':(function x(){})[-6]=='x'?'FF2':/a/[-1]=='a'?'FF':'\v'=='v'?'IE':/a/.__proto__=='//'?'Saf':/s/.test(/a/.toString)?'Chr':/^function \(/.test([].sort)?'Op':'Unknown'
	$('overlay').setStyle({display:'block'});
	$('overlay').setStyle({width:'965px'});
	$('mainnavi').setStyle({zIndex:'999999'});
	
	if (browser == 'IE')
		$('overlay').setStyle({margin:'33px 0 0 -603px'});
	else
		$('overlay').setStyle({margin:'33px 0 0 -17px'});
}

function displayProductOverlay() {
	var browser = (function x(){})[-5]=='x'?'FF3':(function x(){})[-6]=='x'?'FF2':/a/[-1]=='a'?'FF':'\v'=='v'?'IE':/a/.__proto__=='//'?'Saf':/s/.test(/a/.toString)?'Chr':/^function \(/.test([].sort)?'Op':'Unknown'
	$('overlay').setStyle({display:'block'});
	$('overlay').setStyle({width:'775px'});
	$('mainnavi').setStyle({zIndex:'0'});
	
	if (browser == 'IE')
		$('overlay').setStyle({margin:'125px 0 0 -413px'});
	else
		$('overlay').setStyle({margin:'125px 0 0 173px'});
		
		
		
}


function hideOverlay() {
	$('overlay').setStyle({display:'none'});
}

/****************\
 * Standorte 
\*'**************/

var activePlace = 1;

/*Weltkarte zeigen*/
function showplacescard(){
	$('places').addClassName('plactive');
	
	$('plcard').setStyle({
		  display: 'block'
		});
	
	/*das muss versteckt, werden, da diese Elemente relativ positioniert sind*/
	if($('quicklinks'))
		$('quicklinks').hide();
	if($('ptsuebersicht'))
		$('ptsuebersicht').hide();
}

/*Karte zurücksetzen*/
function resetPlaceCard() {
	//Liste aktivieren
	$('c1').addClassName('copen');
	$('c1').show();
	
	if (1 < activePlace) {
		$('c'+activePlace).removeClassName('copen');		
		$('c'+activePlace).hide();		
	}	
}

/*Weltkarte schließen*/
function closeplacescard(){
	//Liste aktivieren
	resetPlaceCard();
	
	$('places').removeClassName('plactive');
	
	$('plcard').setStyle({
		  display: 'none'
		});
	

	/*wieder zeigen, siehe oben*/
	if($('quicklinks'))
		$('quicklinks').show();
	if($('ptsuebersicht'))
		$('ptsuebersicht').show();
}

/*Inhalt eines Standorts anzeigen*/
function showplace(element){
	
	var idnr = element.id.substr(1);
	
	if(idnr == 1){
		$('o1').removeClassName('plgroup');	
		$('o1').addClassName('plgroup_active');
		Element.writeAttribute($('o1'),'value','open');
	}
	
	if ($('c'+idnr) && 'close' == $('o1').getAttribute('value')) {
		/*container schließen*/
		if($('c'+idnr).previous('.copen')){
			$('c'+idnr).previous('.copen').hide();
			$('c'+idnr).previous('.copen').removeClassName('copen');
		}else{
			$('c'+idnr).next('.copen').hide();
			$('c'+idnr).next('.copen').removeClassName('copen');
		}
		
		/*container öffnen*/
		$('c'+idnr).show();
		$('c'+idnr).addClassName('copen');	
		activePlace = idnr;
	}
}


/*Europa Übersicht schließen*/
function closeeurope(evt){
	if(!evt) evt = window.event;
	var body = (window.document.compatMode && window.document.compatMode == "CSS1Compat") ? window.document.documentElement : window.document.body;
	var x = evt.pageY ? evt.pageY : evt.clientY + body.scrollTop - body.clientTop;
	var y = evt.pageX ? evt.pageX : evt.clientX + body.scrollLeft  - body.clientLeft;
	
	if ((x < 465 || x > 270) && (y < 166 || y > 438)) {	
		$('o1').removeClassName('plgroup_active');
		$('o1').addClassName('plgroup');
		Element.writeAttribute($('o1'),'value','close');
	}
}

/****************\
 * Kategorienavigation
\*'**************/
/*function showCat(element){
	var myArray = document.getElementsByClassName('subnavigation3c');
	for (var index = 0; index < myArray.length; ++index) {
		  var item = myArray[index];
		  item.hide();
		}

	$(element).down('div').appear({ duration: 0.5 });
}

function hideCat(element){
}*/

/*Klasse der letzten Box verändern, damit die Breite passt*/
function changescrollbox(element){
	var container = $(element).down('.subnavigation3');
	if(container != null){
		$(container).removeClassName('subnavigation3');
		$(container).addClassName('subnavigation3b');
	}
}

/*Scrollfunktionen - wird für Navigation und Produktübersicht verwendet
 * links rum
 * */
function ml(element,mode) {   
	var scroll = $(element).next('.scroll_right').next('.scrollcontainer');
	var scrollCount = $(scroll).readAttribute('value');
	if (!scrollCount) {
		scrollCount = 0;
	}else {
		scrollCount = parseInt(scrollCount);
	}
	var container = $(scroll).down('.bigscrollbox');
	var moveby;
	if(mode == 'navi'){
		if($(element).up('.greycontainer').up('div').hasClassName('subnavigation3b')){
			moveby = 110;
		}else{
			moveby = 135;
		}
	}else{
		moveby = 130;
	}
    
    var children = $(container).childElements();
    var childcount = children.length;

    if(childcount > 3){
	    if (scrollCount < 1) {
	    	$(element).addClassName('scroll_l_grey');
	    	
	    	//scrollCount = parseInt(childcount);
	    	//$(container).style.left = '-'+(moveby * parseInt(childcount-1))+'px';
		} else {
			$(element).next('.scroll_right').removeClassName('scroll_r_grey');
	    	
			scrollCount--;
			$(scroll).writeAttribute('value',scrollCount);
		   	new Effect.MoveBy(container, 0, moveby,
		   	{
		   		duration: 0.4,
		   		fps: 25,
		   		transition: Effect.Transitions.sinoidal,
		   		queue: 'end'
		   	});
	   	}     	
    }else{
    	$(element).addClassName('scroll_l_grey');    	
    }
}
/*Scrollfunktionen - wird für Navigation und Produktübersicht verwendet
 * rechts rum
 * */
function mr(element,mode) {    
	var scroll = $(element).next('.scrollcontainer');
	var scrollCount = $(scroll).readAttribute('value');
	if (!scrollCount) {
		scrollCount = 0;
	} else {
		scrollCount = parseInt(scrollCount);
	}
    	var container = $(scroll).down('.bigscrollbox');
    	var moveby;
    	if(mode == 'navi'){
			if($(element).up('.greycontainer').up('div').hasClassName('subnavigation3b')){
				moveby = 110;
			}else{
				moveby = 135;
			}
		}else{
			moveby = 130;
		}

		var children = $(container).childElements();
	    var childcount = children.length;

	    if(childcount > 3){	  
		    if (scrollCount+3 >= parseInt(childcount)) {
		    	//scrollCount = 0;
	    		//$(container).style.left = '0';
		    	$(element).addClassName('scroll_r_grey');
	    	} else {
	    		$(element).previous('.scroll_left').removeClassName('scroll_l_grey');
		    	scrollCount++;
			$(scroll).writeAttribute('value',scrollCount);
		    	new Effect.MoveBy(container, 0, -moveby,
		    	{
		    		duration: 0.4,
		    		fps: 25,
		    		transition: Effect.Transitions.sinoidal,
		    		queue: 'end'
		    	});  
	    	}      	
	    }else{
	    	$(element).addClassName('scroll_r_grey');
	    }
}

/*Mouseover für Produktslider*/
function makeLOrange(element){
	if(!$(element).hasClassName('scroll_l_grey')){
		$(element).addClassName('scroll_l_orange');
	}
}

function makeLBlue(element){
	if($(element).hasClassName('scroll_l_orange')){
		$(element).removeClassName('scroll_l_orange');
	}
}
function makeROrange(element){
	if(!$(element).hasClassName('scroll_r_grey')){
		$(element).addClassName('scroll_r_orange');
	}
}

function makeRBlue(element){
	if($(element).hasClassName('scroll_r_orange')){
		$(element).removeClassName('scroll_r_orange');
	}
}

/****************\
 * Produktübersicht
\*'**************/
/*Inhalt der Produktbeschreibung wird angezeigt*/
function showptcontent(element){
	if($('showptcontent').down('.ptteaser'))
		$('showptcontent').down('.ptteaser').hide();
	
	if($('showptcontent').down('.ptdescr'))
		$('showptcontent').down('.ptdescr').remove();
	
	$(element).addClassName('ptsitemact');
	
	var clonedNode = $(element).down('.ptsdescr').cloneNode(true);
	$('showptcontent').insert(clonedNode.show());
}

/*Klasse verändern, um aktives Produkt hervorzuheben*/
function hideptcontent(element){
	$(element).removeClassName('ptsitemact');
	
	if($('showptcontent').down('.ptteaser'))
		$('showptcontent').down('.ptteaser').show();
	
	if($('showptcontent').down('.ptdescr'))
		$('showptcontent').down('.ptdescr').remove();
}

/****************\
 * Downloadformular
\*'**************/
/*zweite Kategorie in rechter Spalte*/
function getSecCat(){
	var current = window.location.href;
	var category1 =$('cat1').options[$('cat1').selectedIndex].value;
	location.replace(current+'&no_cache=1&tx_damdownloads_pi1[cat][0]='+category1);
}

/*zweite Kategorie in Highslidewindow*/
function getSecCatHs(){
	var category1 =$('cat2').options[$('cat2').selectedIndex].value;
	location.replace('index.php?id=2490&no_cache=1&tx_damdownloads_pi1[cat][0]='+category1);
}



/****************\
 * Browserdetect
\*'**************/
var BrowserDetect = {
		init: function () {
			this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
			this.version = this.searchVersion(navigator.userAgent)
				|| this.searchVersion(navigator.appVersion)
				|| "an unknown version";
			this.OS = this.searchString(this.dataOS) || "an unknown OS";
		},
		searchString: function (data) {
			for (var i=0;i<data.length;i++)	{
				var dataString = data[i].string;
				var dataProp = data[i].prop;
				this.versionSearchString = data[i].versionSearch || data[i].identity;
				if (dataString) {
					if (dataString.indexOf(data[i].subString) != -1)
						return data[i].identity;
				}
				else if (dataProp)
					return data[i].identity;
			}
		},
		searchVersion: function (dataString) {
			var index = dataString.indexOf(this.versionSearchString);
			if (index == -1) return;
			return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
		},
		dataBrowser: [
			{
				string: navigator.userAgent,
				subString: "Chrome",
				identity: "Chrome"
			},
			{ 	string: navigator.userAgent,
				subString: "OmniWeb",
				versionSearch: "OmniWeb/",
				identity: "OmniWeb"
			},
			{
				string: navigator.vendor,
				subString: "Apple",
				identity: "Safari",
				versionSearch: "Version"
			},
			{
				prop: window.opera,
				identity: "Opera"
			},
			{
				string: navigator.vendor,
				subString: "iCab",
				identity: "iCab"
			},
			{
				string: navigator.vendor,
				subString: "KDE",
				identity: "Konqueror"
			},
			{
				string: navigator.userAgent,
				subString: "Firefox",
				identity: "Firefox"
			},
			{
				string: navigator.vendor,
				subString: "Camino",
				identity: "Camino"
			},
			{		// for newer Netscapes (6+)
				string: navigator.userAgent,
				subString: "Netscape",
				identity: "Netscape"
			},
			{
				string: navigator.userAgent,
				subString: "MSIE",
				identity: "Explorer",
				versionSearch: "MSIE"
			},
			{
				string: navigator.userAgent,
				subString: "Gecko",
				identity: "Mozilla",
				versionSearch: "rv"
			},
			{ 		// for older Netscapes (4-)
				string: navigator.userAgent,
				subString: "Mozilla",
				identity: "Netscape",
				versionSearch: "Mozilla"
			}
		],
		dataOS : [
			{
				string: navigator.platform,
				subString: "Win",
				identity: "Windows"
			},
			{
				string: navigator.platform,
				subString: "Mac",
				identity: "Mac"
			},
			{
				   string: navigator.userAgent,
				   subString: "iPhone",
				   identity: "iPhone/iPod"
		    },
			{
				string: navigator.platform,
				subString: "Linux",
				identity: "Linux"
			}
		]

	};
	BrowserDetect.init();

/****************\
 * FCE Java Bühne
\*'**************/
function initSlider() {
	setInterval(function(){
		var items = $$('.item img');
		var h = $$('.item h1');
		var p = $$('.item p');

		visible = items.findAll(function(item){ 
			return item.visible(); 
		});

		hv = h.findAll(function(h){ 
			return h.visible(); 
		});
		
		pv = p.findAll(function(p){ 
			return p.visible(); 
		});
		
		if(visible.length>1) {
			visible.last().fade({ duration: .6 });
			hv.last().fade({ duration: .6 });
			pv.last().fade({ duration: .6 });
		} else {
			items.last().appear({ duration: .6, afterFinish: function(){ 
					items.slice(0,items.length-1).invoke('show');
				}
			});
			h.last().appear({ duration: .6, afterFinish: function(){ 
					h.slice(0,h.length-1).invoke('show');
				}
			});
			p.last().appear({ duration: .6, afterFinish: function(){ 
					p.slice(0,p.length-1).invoke('show');
				}
			});
		}
	}, 7000);
}
