var sliding 			= 0;
var slideTime 			= '';
var panelHeight 		= 178;
var effectDuration 		= 500;
var idleTime 			= 600;
var kurz          = 0;
var Produkte;
var Laeden;
var UeberUns;

// Set is sliding value
function setSliding(a_ISliding){
	sliding = a_ISliding;
}

// Get is sliding value
function getSliding(){
	return sliding;
}


// Carry out accordian styled effect
function accordion() {
		
	kurz = 0;	
	var eldown = this.getNext();
	Produkte.style.backgroundImage = "url(http://ringelsuse.de/b/layout/Produkte.png)";
	//  If element is visible do nothing
	if ($('visible') == this) {
			return false;
	}
	if ($('visible')) {
	     //this.style.backgroundImage=this.style.backgroundImage.substr(0,36)+'2'+this.style.backgroundImage.substr(36,5);
	    //this.style.backgroundImage = 'url(http://ringelsuse.de/b/layout/Produkte.png)'; 
			if( getSliding() == 1 ){
					return false;
			}
		
			var elup = $('visible').getNext();

			setSliding( 1 );
			
			parellelSlide( elup, eldown );
			$('visible').id = '';
			
	}
	else{
			setSliding( 1 );
			singleSlide( eldown );
	}
	
	this.id = 'visible';
}

function accordion2() {
		
	kurz = 1;
  var eldown = this.getNext();
  //Laeden.style.paddingBottom = "3px";
  //Produkte.style.paddingBottom = "0px";
  //UeberUns.style.paddingBottom = "0px";
  Produkte.style.backgroundImage = "url(http://ringelsuse.de/b/layout/Produkte2.png)";
  //  If element is visible do nothing
	if ($('visible') == this) {
			return false;
	}
	if ($('visible')) {
	    //this.style.backgroundImage=this.style.backgroundImage.substr(0,36)+'2'+this.style.backgroundImage.substr(36,5);
      
      //$(panels[1].getElementsByTagName('h3')[0]).style.backgroundImage = 'url(http://ringelsuse.de/b/layout/Laeden2.png)';
      //this.style.backgroundImage = 'url(http://ringelsuse.de/b/layout/Laeden2.png)';
			
      if( getSliding() == 1 ){
					return false;
			}
		
			var elup = $('visible').getNext();

			setSliding( 1 );
			
			parellelSlide2( elup, eldown );
			$('visible').id = '';
			
	}
	else{
			setSliding( 1 );
			singleSlide2( eldown );
	}
	
	this.id = 'visible';
}

// Carry out accordian styled effect
function accordion3() {
		
	kurz = 0;	
	var eldown = this.getNext();
	Produkte.style.backgroundImage = "url(http://ringelsuse.de/b/layout/Produkte2.png)";
	//Laeden.style.paddingBottom = "0px";
  //Produkte.style.paddingBottom = "0px";
  //UeberUns.style.paddingBottom = "3px";
	//  If element is visible do nothing
	if ($('visible') == this) {
			return false;
	}
	if ($('visible')) {
	     //this.style.backgroundImage=this.style.backgroundImage.substr(0,36)+'2'+this.style.backgroundImage.substr(36,5);
	    //this.style.backgroundImage = 'url(http://ringelsuse.de/b/layout/Produkte.png)'; 
			if( getSliding() == 1 ){
					return false;
			}
		
			var elup = $('visible').getNext();

			setSliding( 1 );
			
			parellelSlide( elup, eldown );
			$('visible').id = '';
			
	}
	else{
			setSliding( 1 );
			singleSlide( eldown );
	}
	
	this.id = 'visible';
}


function invertieren() {
	this.src=this.src.substr(0,33)+'i'+this.src.substr(33,5); 
}

function normal() {
		
	this.src=this.src.substr(0,33)+this.src.substr(34,5);
  
}

function getElementsByClassNameFix(tag, className) {
		// This method of populating is used as Safari does use getElementsByClassName()
		var elements = [];
		var safariElements = $A(document.getElementsByTagName(tag));
		safariElements.each(function(safariElements){
			if(!safariElements.className.match(className)) return;
			elements.push(safariElements);
		});
		return elements;
}

// Setup accordian initial state
function init() {
		
		var bodyPanels 			= getElementsByClassNameFix('div', 'panel_body');
		var panels 					= getElementsByClassNameFix('div', 'panel_container');
		var noPanels 				= panels.length;
		var percentageWidth = 100 / noPanels;
		var position 				= 0;
				
		//  Loop through body panels and panels applying required styles and adding event listeners
    bodyPanels[0].style.height = '0px';
		panels[0].style.width = '130px';
		panels[0].style.position = 'absolute';
		panels[0].style.left = '350px';
					
    Produkte=document.getElementById('Produkte');
    $('Produkte').addEvent('mouseover', accordion);
		$('Produkte').addEvent('mouseover', accordion);
    //$(panels[0].getElementsByTagName('h3')[0]).addEvent('mouseover', accordion);
		//$(panels[0].getElementsByTagName('h3')[0]).addEvent('mousemove', accordion);
		$(document.body).addEvent('mousemove', resetIdle);
		
		bodyPanels[1].style.height = '0px';
		panels[1].style.width = '130px';
		panels[1].style.position = 'absolute';
		panels[1].style.left = '480px';
			
		//$(panels[1].getElementsByTagName('h3')[0]).addEvent('mouseover', accordion2);
		//$(panels[1].getElementsByTagName('h3')[0]).addEvent('mousemove', accordion2);
		Laeden=document.getElementById('Laeden');
    $('Laeden').addEvent('mouseover', accordion2);
		$('Laeden').addEvent('mouseover', accordion2);
    
    bodyPanels[2].style.height = '0px';
		panels[2].style.width = '130px';
		panels[2].style.position = 'absolute';
		panels[2].style.left = '610px';
			
		UeberUns=document.getElementById('UeberUns');
    $('UeberUns').addEvent('mouseover', accordion3);
		$('UeberUns').addEvent('mouseover', accordion3);
    		
		if( $('visible') ){
		//  Set panel with id of visible to be initial displayed
			var vis = $('visible').parentNode.id+'-body';
			$(vis).style.height = '150px';
		}
		setIdle();
}

// Next sibling method to work around firefox issues
function getNextSibling(startBrother){
	var endBrother=startBrother.nextSibling;
  while(endBrother.nodeType!=1){
    endBrother = endBrother.nextSibling;
  }
  return endBrother;
}

function parellelSlide( elup, eldown ){
	
	
	new Fx.Tween(elup).start('height', 108, 0);
	new Fx.Tween(eldown).start('height', 0, 175);
	
  setSliding( 0 );	
}

function parellelSlide2( elup, eldown ){
	new Fx.Tween(elup).start('height', 175, 0);
	new Fx.Tween(eldown).start('height', 0, 108);
	setSliding( 0 );
}

function singleSlide( eldown ){
	
	new Fx.Tween(eldown).start('height', 0, 175);
	setSliding( 0 );
}

function singleSlide2( eldown ){
	
		new Fx.Tween(eldown).start('height', 0, 108);
		setSliding( 0 );
	
}

function resetTabs(){
	
	var resetEl = $('visible').getNext();
	
	setSliding( 1 );
	
	if(kurz) {
  new Fx.Tween(resetEl).start('height', 108, 0);
	}
	else {
  new Fx.Tween(resetEl).start('height', panelHeight, 0);
  }

	
	$('visible').id = '';
}

function resetIdle(){
		window.clearTimeout( slideTime );
		setIdle()
}

function setIdle(){
	if( $('visible') ){
		slideTime = window.setTimeout( "resetTabs()", idleTime );
	}
}

window.addEvent('load', init);
