
function number_format (number, decimals, dec_point, thousands_sep)
{
  var exponent = "";
  var numberstr = number.toString ();
  var eindex = numberstr.indexOf ("e");
  if (eindex > -1)
  {
    exponent = numberstr.substring (eindex);
    number = parseFloat (numberstr.substring (0, eindex));
  }
  
  if (decimals != null)
  {
    var temp = Math.pow (10, decimals);
    number = Math.round (number * temp) / temp;
  }
  var sign = number < 0 ? "-" : "";
  var integer = (number > 0 ? 
      Math.floor (number) : Math.abs (Math.ceil (number))).toString ();
  
  var fractional = number.toString ().substring (integer.length + sign.length);
  dec_point = dec_point != null ? dec_point : ".";
  fractional = decimals != null && decimals > 0 || fractional.length > 1 ? 
               (dec_point + fractional.substring (1)) : "";
  if (decimals != null && decimals > 0)
  {
    for (i = fractional.length - 1, z = decimals; i < z; ++i)
      fractional += "0";
  }
  
  thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ? 
                  thousands_sep : null;
  if (thousands_sep != null && thousands_sep != "")
  {
	for (i = integer.length - 3; i > 0; i -= 3)
      integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
  }
  
  return sign + integer + fractional + exponent;
}

//MENU

$(document).ready(function(){
	window.killEvent = false;
	rolloutTimer='';
	var mySubId = '';
	var menuDropDownOnClickStack = false;
	var left = true;
	$('#nav ul.n li.h_menu').each(function(){	
		$('#'+this.id).click(function () {				
			left = false;		
			myID = this.id;		
			drop('#'+myID,myID.replace('N','D'));		
			menuDropDownOnClickStack = true;
		});
	});			
	$("#menuDropDown").mouseenter(function(){
		left = false;
		window.killEvent = true;
		if (rolloutTimer){
			clearTimeout(rolloutTimer);
		}
	});
	$('#menuDropDown').click(function () {
        menuDropDownOnClickStack = true;
		left = false;
    });
    $(document).click(function () {
        if (!menuDropDownOnClickStack) {
            window.dropShowing = false;					
			if(!ie7){			
				$('#menuDropDown').animate({
					opacity: 0				
				  }, 300);	
			}else{
				$('#menuDropDown').hide();	
			}	
			$('#nav ul.n li.h_menu').each(function(){	
				$('#'+this.id).removeClass("hover");
			});
        }
        menuDropDownOnClickStack = false;
    });
	$("#menuDropDown").mouseleave(function () {	
		left = true;
		setTimeout(function(){	
			if(left){
				window.dropShowing = false;		
				if(!ie7){			
					$('#menuDropDown').animate({
						opacity: 0				
					  }, 300);	
				}else{
					$('#menuDropDown').hide();	
				}
				$('#nav ul.n li.h_menu').each(function(){	
					$('#'+this.id).removeClass("hover");
				});
			}
		},800);
	});
	$("#menuDropDown  ul li a").each(function(){	
		$(this).mouseenter(function () {	
			$(this).css("background","#444");	
		});
		$(this).mouseleave(function () {	
			$(this).css("background","#6f6f6f");	
		});
	});
});
function drop(id,subId) {
	
	mySubId = subId;
	$(window.currentSection).removeClass("hover");
	window.currentSection = id;
	$(id).addClass("hover");	
	window.dropShowing = true;
	var itemOffset = $(id).offset();
	var itemH = $(id).height();
	var itemW = $(id).width();	
	if(document.lastId != undefined){		
		$('#'+document.lastId).css('display','none');
	}
	document.lastId=subId;	
	if(!ie7){
		$('#menuDropDown').animate({
		  opacity: 1.00				
		}, 300);
	}else{
		$('#menuDropDown').show();
	}
	
	$('#'+subId).css('display','block');
	$('#'+subId).css('opacity','1.00');
	$("this a").css("background","url(images/nav_over.gif) repeat-x left");
	$("this a").css("color","#fff");
	$("this span").css("background","url(images/nav_div_selected.gif) no-repeat right"); 
}

//BANNER
window.onload = function(){
	var animate_banner = !$('body').hasClass('unterseite');	
	setTimeout(function(){	
		if(animate_banner){	
			$('#banner').animate(
				{backgroundPosition: '0 -170px'}, 
				{    duration: 1000,
					 easing: 'easeInOutQuad',
					 complete: function(){
						 $('#over_banner').animate(
							 {left: 0}, 
							 {
								 duration: 1000,
								 easing: 'easeInOutQuad'
							 }
						 );	
					 }
				}
			);			 
		}
	},800);
	var timer = setInterval( function(){
		co2_g = parseFloat($('#co2_quota').text().replace(' kg','').replace(',','.'));
		co2_g += co2_sec;
		//alert(co2_g+' kg');		
		co2_g = number_format(co2_g,4,',','');
		$('#co2_quota').text(co2_g+' kg');		
	}, 1000);	
}
