var tweenerOpen  = function() {
	
	
	//ELEMENTE EINER BESTIMMMTEN KLASSE ZÄHLEN
	var count = new Array();
	var amount = 0;
	var elements = document.getElementsByTagName("div");
	for (var i = 0; i < elements.length; i++){
		if (elements[i].className == "axlanguagemenu_l"){
			amount = amount + 1;
		}
	}
	//1 wegzählen, da ja auch der derzeit aktuelle Eintrag mitgerechnet wird - dann mal 24 (zeile ist lt. css 24 hoch)
	amount = (amount - 1)*24;
	amount = amount + 'px';
	
	
	
	
	var myFx = new Fx.Tween($('axlanguagemenu_choose'), {
            'duration': 250
        }); 
	
	//BEI START FARBE ÄNDERN
	myFx.addEvent('start', function(){
       $('axlanguagemenu_container').style.backgroundColor = '#FFFFFF';
    });
	
	
	if(!$('axlanguagemenu_choose').style.height || $('axlanguagemenu_choose').style.height=='0px') {
		myFx.start('height', '0px', amount);
		
		
	} else {
		myFx.start('height', $('axlanguagemenu_choose').style.height, '0px');
	}
	
}

var tweenerClose = function() {
	var myFx2 = new Fx.Tween($('axlanguagemenu_choose'), {
            'duration': 250
        }); 
	
	//BEI COMPLETE FARBE ÄNDERN
	myFx2.addEvent('complete', function(){
       $('axlanguagemenu_container').style.backgroundColor = '#F8F7F6';
    });
	
		
	myFx2.start('height', $('axlanguagemenu_choose').style.height, '0px');
}

var pf = '';

var parent = false;

window.addEvent('domready', function() {
	
	
	startPulse();
	
	
	//$('jobmenu_link').addEvent('mouseenter', stopFading()); 
	//$('jobmenu_link').addEvent('mouseleave', startFading());
	
	
	$('axlanguagemenu_container').addEvent('mouseenter', tweenerOpen); //MOUSEENTER IST EIGENES MOOTOOL ELEMENT - WIE MOUSEOVER ABER will not be fired again if the mouse crosses over children of the Element (unlike mouseover).
	$('axlanguagemenu_container').addEvent('mouseleave', tweenerClose); //MOUSELEAVE IST EIGENES MOOTOOLS ELEMENT - WIE MOUSEOUT ABER will not be fired if the mouse crosses over children of the Element (unlike mouseout).		
});





function startPulse() {
  pf = new PulseFade('fade_image_2',{
    min: 0,
    max: 1,
    duration: 2500    
  })
  
  if(parent == false) {
	 pf.start();
  }
  //$('stop-link').addEvent('click',function(e) { e.stop(); pf.stop(); });
  //$('start-link').addEvent('click',function(e) { e.stop();  });
}




function setMouseover() {
	$('jobmenu_link').addEvent('mouseenter', stopFading()); 
	$('jobmenu_link').addEvent('mouseleave', startFading());
}

function menuParent() {
	//window.setTimeout("pf.stop();",500);
	//pf.stop();
	
	parent = true;
	
	//$('jobmenu_link').removeEvent('mouseenter', stopFading()); 
	//$('jobmenu_link').removeEvent('mouseleave', startFading());
		
	$("jobmenu_link").addClass("menuparent");
}


function stopFading() {	
	//clearInterval(interval_id);
	pf.stop(); 
	
	//$("fade_image_1").fade('hide');
	//$("fade_image_2").fade('show');
}

function startFading() {
	pf.start();
	
	/*$("fade_image_1").fade('show');
	$("fade_image_2").fade('hide');
	current_image = "fade_image_1";
	
	interval_id = window.setInterval("imgSwitch()",1000);*/
}

var PulseFade = new Class({
      
  //implements
  Implements: [Options,Events],

  //options
  options: {
    min: 0,
    max: 1,
    duration: 200,
    times: 5
  },
  
  //initialization
  initialize: function(el,options) {
    //set options
    this.setOptions(options);
    this.element = $(el);
    this.times = 0;
  },
  
  //starts the pulse fade
  start: function(times) {
    if(!times) times = this.options.times * 2;
    this.running = 1;
    //this.fireEvent('start').run(times -1);
	this.fireEvent('start').run(times+1);
  },
  
  //stops the pulse fade
  stop: function() {
    this.running = 0;
    this.fireEvent('stop');
  },
  
  //runs the shizzle
  run: function(times) {
    //make it happen
    var self = this;
    var to = self.element.get('opacity') == self.options.min ? self.options.max : self.options.min;
    self.fx = new Fx.Tween(self.element,{
      duration: self.options.duration / 2,
      onComplete: function() {
        self.fireEvent('tick');
		
		
		/*if( times%2 == 0 ) {
			$('jobmenu_link').style.color = '#6F6F6F';	
		} else {			
			$('jobmenu_link').style.color = '#FFFFFF';
		}*/
		
		/*if($('jobmenu_link').style.color == '#6F6F6F')	  {		
			$('jobmenu_link').style.color = '#FFFFFF';
		} else if($('jobmenu_link').style.color == '#FFFFFF') {
			$('jobmenu_link').style.color = '#6F6F6F';	
		} */	
		
        if(self.running && times)
        {
          //self.run(times-1);
		  self.run(times+1);
		  
        }
        else
        {
          self.fireEvent('complete');
        }
      }
    }).start('opacity',to);
  }
});



