var lastactiveImg;
var $j = jQuery.noConflict();
var direction;
var myTimer;
var actItemID;
var firstisactive;
var timeoutaktiv;
var isEven = function(someNumber){
return (someNumber%2 == 0) ? true : false;
};
var currentKVid = undefined;
jQuery(function() {
//start init jQuery


    //fade buttons Mainnavigation
	jQuery('.main_nav a.active').stop().animate(
		{backgroundPosition:"0px 0px"}, 
		{duration:500}
	);
	
	jQuery('.main_nav a:not(.active)')
	.css( {backgroundPosition: "-270px 0px"} )
	.mouseover(function(){
	
		jQuery(this).stop().animate(
			{backgroundPosition:"0px 0px"}, 
			{duration:500}
		)
	})
	.mouseout(function(){
		jQuery(this).stop().animate(
			{backgroundPosition:"-270px 0px"}, 
			{duration:500}
		)
	});
	
	
	
	//fade in out images
	//check if mouse out and no mouse in
	jQuery('.main_nav a')
	/*.mouseover(function(){
	    
		//clearTimeout(myTimer);
		direction = 'in';
		var nav = jQuery(this).parent().attr('id');
		var navID = nav.slice(5);
		if(navID){
		    jQuery('#kv-' + navID).css('z-index',10);
		    jQuery('#kv-' + navID).stop(false,true)
		    .css('z-index',10)
		    .fadeIn(1000, function(){
		        
		        
		    	if(navID != currentKVid){
		    	    if(navID != actItemID){
		    	    	jQuery('#kv-' + actItemID).hide();
		    	    	jQuery('#kv-' + currentKVid).hide();
		    	    }
		    	    
		    	}
		    	if(firstisactive && navID != actItemID){
		    		firstisactive = false;
		    		jQuery('#kv-' + actItemID).hide();
		    	}
		    	currentKVid = navID;
		    });
		    
		}
	})
	
	.mouseout(function(){
	    direction = 'out';
	    setTimeout( function(){
	    	if(direction == 'out'){
	    	    firstisactive = true;
	    		jQuery('#kv-' + actItemID).fadeIn(1000);
	    		
	    	}
	    	timeoutaktiv = true;
	    }, 10);

		var nav = jQuery(this).parent().attr('id');
		var navID = nav.slice(5);
		//alert(navID);
		//alert(currentKVid);
		if(actItemID == navID && currentKVid == navID){
		    jQuery('#kv-' + navID).css('z-index', 0);
			
		}else{
		if(navID){
			jQuery('#kv-' + navID).stop(true,true)
			.fadeOut(1000,function(){
				jQuery('#kv-' + navID).css('z-index', 0);
			});
		}
		}
		
	});
	*/
	
	
	
	
	
	//ticker news
	
	jQuery('#ticker-news').innerfade({
				animationtype: 'slide',
				speed: 750,
				timeout: 2000,
				type: 'sequence',
				containerheight: '1em'
	});
	
	
	//fade footer images
	jQuery('#footer .csc-textpic-imagewrap img').each(function(index){
	
		if(!isEven(index)){
		
			jQuery(this).hide();
		}
	
	});
	jQuery('#footer .teaser').hover(function(){
		jQuery('img', this).slice(0).stop(true,true).fadeOut(500);
		jQuery('img', this).slice(1).stop(true,true).fadeIn(500);
	},
	function(){
	    jQuery('img', this).slice(0).stop(true,true).show();
		jQuery('img', this).slice(1).stop(true,true).fadeOut(500);
		
	
	});
	

	//fade buttons Subnavigation
	jQuery('.sec_nav a.active').stop().animate(
		{backgroundPosition:"0px 0px"}, 
		{duration:500}
	);
	
	jQuery('.sec_nav a:not(.active)')
	.css( {backgroundPosition: "-270px 0px"} )
	.mouseover(function(){
		
		jQuery(this).stop().animate(
			{backgroundPosition:"0px 0px"}, 
			{duration:500}
		)
		
	})
	.mouseout(function(){
		jQuery(this).stop().animate(	
			{backgroundPosition:"-270px 0px"}, 
			{duration:500})
	});
	
	jQuery('.sec_nav a')
	/*.mouseover(function(){
	    
		//clearTimeout(myTimer);
		direction = 'in';
		var nav = jQuery(this).parent().attr('id');
		var navID = nav.slice(5);
		//alert(navID);
		if(navID){
		    jQuery('#kv-' + navID).css('z-index',10);
		    jQuery('#kv-' + navID).stop(false,true)
		    .css('z-index',10)
		    .fadeIn(1000, function(){
		        
		        
		    	if(navID != currentKVid){
		    	    if(navID != actItemID){
		    	    	jQuery('#kv-' + actItemID).hide();
		    	    	jQuery('#kv-' + currentKVid).hide();
		    	    }
		    	    
		    	}
		    	if(firstisactive && navID != actItemID){
		    		firstisactive = false;
		    		jQuery('#kv-' + actItemID).hide();
		    	}
		    	currentKVid = navID;
		    });
		    
		}
	})
	
	.mouseout(function(){
	    direction = 'out';
	    setTimeout( function(){
	    	if(direction == 'out'){
	    	    firstisactive = true;
	    		jQuery('#kv-' + actItemID).fadeIn(1000);
	    		
	    	}
	    	timeoutaktiv = true;
	    }, 10);

		var nav = jQuery(this).parent().attr('id');
		var navID = nav.slice(5);
		//alert(navID);
		//alert(currentKVid);
		
		if(navID){
			jQuery('#kv-' + navID).stop(true,true)
			.fadeOut(1000,function(){
				jQuery('#kv-' + navID).css('z-index', 0);
			});
		}
		
	});*/
	
	
	//init kv navi
	//get active menu and display kv
	var actNav = jQuery('.main_nav a.active').parent().attr('id');
	var actNavSec = jQuery('.sec_nav a.active').parent().attr('id');
	
	if(actNav){
		var actNavID = actNav.slice(5);
	    currentKVid = actNavID;
	    actItemID = actNavID;
	    //jQuery('#kv-' + actNavID).css('z-index',10);
		jQuery('#kv-' + actNavID).fadeIn('fast');
	}
	
	if(actNavSec){
		var actNavID = actNavSec.slice(5);
	    currentKVid = actNavID;
	    actItemID = actNavID;
	    //jQuery('#kv-' + actNavID).css('z-index',10);
		jQuery('#kv-' + actNavID).fadeIn('fast');
	}
	
	//get active menu and display kv
	var actsecNav = jQuery('.sec_nav a.active').parent().attr('id');
	
	if(actsecNav){
	    var actsecNavID = actsecNav.slice(5);
	    //currentKVid = actNavID;
	    //jQuery('#kv-' + actsecNavID).css('z-index',10);
		jQuery('#kv-' + actsecNavID).fadeIn('fast');
	}
	/*jQuery('#keyvisual > img').each(function(){jQuery(this).hide()});
	
	if(jQuery('#kv-' + actItemID).val() != undefined){
		jQuery('#kv-' + actItemID).show();
		}else{
		jQuery('.kv-image').first().show();
		
	}*/
	
	
		//alert(actNavID);
//end init jQuery
});
