// charset=utf-8
// $Id: MainNavi_MegaDropdown.js 736 2011-12-19 10:42:43Z hebing $
// $HeadURL: svn://svnserver/lind/2011/autoloadmodules/MainNavi_MegaDropdown/scripts/MainNavi_MegaDropdown.js $
// +----------------------------------------------------------------------+
// | mcm autoload-module: MainNavi_MegaDropdown                           |
// | mcm version 5.6                                                      |
// | (c) 2002-2011 monsun media (http://www.monsun-media.com)             |
// +----------------------------------------------------------------------+
/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
*
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/;

$(document).ready(function(){
	var activeMenuArticle = null;
	var activeDropdown = null;
	$("ul#mainnavi li > a.mn").each(function(idx,elem){
		$(elem).click(function(evt){
			var dropdown;
			dropdown = $(elem).parent().children('div.naviDropdown').eq(0);
			if( activeDropdown && typeof activeDropdown=='object' ){
				// if( activeDropdown.attr('class')===dropdown.attr('class') ){
				// if( activeDropdown.get(0)===dropdown.get(0) ){
				if( activeDropdown.get(0)===dropdown.get(0) ){
					activeDropdown = null;
					return;
				}else{
					activeDropdown.hide();
					activeDropdown = null;
				};
			};
			if( dropdown && typeof dropdown=='object' ){
				dropdown.show();
				activeDropdown = dropdown;
				var subnaviLinks = activeDropdown.find('div.SubNavi ul li a');
				var subnaviArticles = activeDropdown.find('div.NavigationArticleElement');
				subnaviLinks.each(function(idx, elem){
					$(elem).mouseover(function(){
						var relatedArticle = subnaviArticles[idx];
						if(relatedArticle != activeMenuArticle){
							$(subnaviArticles).each(function(idx, elem){
								$(elem).fadeOut(200);
							});
							activeMenuArticle = relatedArticle;
							$(relatedArticle).fadeIn(200);
						}
					});
				});
			};
			evt.preventDefault();
		});				
		$(elem).mouseover(function(evt){
			if(activeDropdown){
				dropdown = $(elem).parent().children('div.naviDropdown').eq(0);
				var isEqual = !$(dropdown).not( $(activeDropdown) ).length;
				if(isEqual){
					var defaultElement = activeDropdown.find('div.NavigationArticleElementStandard');
					if(defaultElement){
						var subnaviArticles = activeDropdown.find('div.NavigationArticleElement');
						if($(defaultElement).not( $(activeMenuArticle) ).length){
								$(subnaviArticles).each(function(idx, elem){
									$(elem).fadeOut(200);
								});
								activeMenuArticle = defaultElement;
								$(defaultElement).fadeIn(200);
							}
					}
				}
			}
		});
	});
});
