function IsNumeric(sText){
   var ValidChars = "0123456789.,";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}
   
window.addEvent('domready', function(){	
	
	if($("berechnen")){
		$("berechnen").addEvent('click', function(){
			if( IsNumeric($("h").value) && IsNumeric($("t").value) && IsNumeric($("b").value) ){
				$("result").innerHTML = Math.round(($("h").value.replace(",", '.') * $("b").value.replace(",", '.') * $("t").value.replace(",", '.')) / 1000 * 1.6);
			}else{
				alert("Bitte nur Zahlen eingeben!");
			}
		});
	}

	
	var stageHeight = function (buehne, img){
		if(!img){return;}
		var hb = buehne.getSize().y;
		var h = img.getSize().y;
		//	console.log(h)
		
		if(h>20 && hb && h!=hb){
			buehne.setStyle('height', h+'px');
			return;
		}else {
			//buehne.style.height=h+'px';
		}
		return;
	}
	
	var buehne = $('header');
	var images;
	if(buehne){
		images = buehne.getElements('img');
	}
	
	if(buehne && images.length > 1){
		stageHeight(buehne,images[0]);
		
		for(var i=0; i < images.length; i++){
			images[i].setStyle('position', 'absolute');
			images[i].setStyle('z-index', images.length-i);
		}
		var counter = 0;

					
		(function(){
		  var fx = new Fx.Morph(images[counter], {duration: 2000, transition: Fx.Transitions.linear, fps: 30});
		  images[counter].setStyle('opacity', 1);
		  fx.start({'opacity': ['1' , '0']});
		  fx.addEvent('complete', function(e){
		  	
		  	//alert("FX complet");
		  	e.setStyle('z-index', 0);
		  	e.setStyle('opacity', 1);		  	
		  	this.images.each(function(img){ img.setStyle('z-index', img.getStyle('z-index').toInt() +1); });	  	
		  }.bind({'images':images}));			
		  counter++;
		  if(counter >= images.length) counter = 0;			
	  	 					
		}).periodical(7000);
	}
});
