var nItems = 0;
jQuery.noConflict();
 
jQuery(document).ready(function(){
	goActive(5000);
	fadeList(0.3,350, true);
});

function goActive(nDelay){
	var ActiveFound = false;
	jQuery('#head_navi ul li').each(function(index){
		if(jQuery(this).attr('class') == "activeLink"){
			navigateSlider(this,nDelay);
			ActiveFound = true;	}
			});
			
	if(!ActiveFound)
		navigateSlider(jQuery("#head_navi ul li"),nDelay);
}

jQuery('#head_navi ul').hover(
	function(){
		jQuery("#head_navi_slider").attr("class", "slider_active");
		fadeList(1.0);
	},
	function(){
		jQuery("#head_navi_slider").attr("class", "slider_passive");
		goActive();
		fadeList(0.3);
	}
);

jQuery('#activeLink').hover(
	function(){
		jQuery("#head_navi_slider").attr("class", "slider_passive");
	},
	function(){
		jQuery("#head_navi_slider").attr("class", "slider_active");
	}
);

jQuery('#head_navi ul li').mouseenter(function(){
	navigateSlider(this);
});

function navigateSlider(listElement,nDelay){
	if(typeof(nDelay)=="undefined"){ nDelay = 0;}
	var liHeight = jQuery(listElement).css("height").replace('px','');
	var liIndex = jQuery('li').index(listElement) + 1;
	var	slidHeight = jQuery('#head_navi_slider').css("height").replace('px','');	
	var marTop = liHeight * liIndex - liHeight/2 - slidHeight/2 + 1 + "px";
	jQuery('#head_navi_slider').delay(5000).animate({marginTop : marTop}, {queue:false, duration: "slow"});
}

function fadeList(fadeValue, fduration, fqueue){
	if(typeof(fduration)=="undefined"){ fduration = 600;}
	if(typeof(fqueue)=="undefined"){ fqueue = false;}
	
	var currDuration = 100;
	var Durationadd = 200;
	jQuery('#head_navi ul li').each(function(index) {
		var realFade = fadeValue;
		if(jQuery(this).attr('class') == "activeLink"){ realFade = 1.0;	}		
		jQuery(this).delay(currDuration += Durationadd).fadeTo({queue:fqueue, duration: fduration}, realFade);
	});	
	
	//jQuery('#head_navi_slider').delay(currDuration += Durationadd ).fadeTo("fast", fadeValue);
}

