/**
 * PRODYNA ContentNavigation.
 * This class depends on jQuery.
 * @author Bertram Beyer PRODYNA AG
 * 
 */
var ContentNavigation = (function(){
	
	
	return{
		/**
		 * Initializes all JavaScript behavior. It is called at the end of the concerning Web Content.
		 * @param ns name space (portlet ID) to ensure that only the calling Web Content is affected.
		 * @returns void
		 */
		init : function(ns){
			
			var nabuccoItems     = ns + " .pd-nab-item, "+ns+" .pd-nab-sub-item";
			var nabuccoMainItem  = ns + " .pd-nab-item";
			var nabuccoSubItems  = ns + " .pd-nab-sub-item";
			var prodynaMainItems = ns + " .pd-nav-main-item";
			var prodynaSubItems  = ns + " .pd-nav-sub-item";
			
			/**
			 * Fade In Animation.
			 * Fades opacity to 1 for all items matching selector
			 * @param selector
			 * @returns void
			 */
			var fadeIn = function(selector){
				jQuery(selector).animate({
					opacity: 1
				},{
					duration: 200,
					queue: false
				});
			};
			
			/**
			 * Fade Out Animation
			 * Fades opacity to 0.5 for all items matching selector
			 * @param selector
			 * @returns void
			 */
			var fadeOut = function(selector){
				jQuery(selector).animate({
					opacity: 0.5
				},{
					duration: 200,
					queue: false
				});
			};
			
			/**
			 * PRODYNA Navigation Table
			 */
			
			jQuery(ns + " .pd-nav").hover(
				function(){
					fadeOut(nabuccoMainItem);
				}, 
				function(){
					fadeIn(nabuccoMainItem);
				}
			);
			
			/**
			 * PRODYNA Sub Navigation Hover
			 */
			jQuery(prodynaSubItems).css("opacity",0.5);
			
			
			
			jQuery(ns + " .pd-nav-sub-td").hover(
				
				function(){
					var id = jQuery(this).attr("id");
					var idNo = id.substr("pd-nav-sub-td-".length);
					fadeIn(ns + " #"+id+" .pd-nav-sub-item");
					var selectorMain = ns + " .pd-nav-main-item:not(#pd-nav-main-item-"+idNo+")";
					fadeOut(selectorMain);
				}, 
				
				function(){
					var id = jQuery(this).attr("id");
					var idNo = id.substr("pd-nav-sub-td-".length);
					fadeOut(ns + " #"+id+" .pd-nav-sub-item");
					var selectorMain = ns + " .pd-nav-main-item:not(#pd-nav-main-item-"+idNo+")";
					fadeIn(selectorMain);
				}

			);
			/**
			 * PRODYNA Main Navigation Hover
			 */
			jQuery(prodynaMainItems).hover(
				function(){
					var id = jQuery(this).attr("id");
					var idNo = id.substr("pd-nav-main-item-".length);
					
					var prefix = " #pd-nav-sub-td-";
					var selectorSub = ns + prefix+idNo+" .pd-nav-sub-item";
					fadeIn(selectorSub);
					
					var selectorMain = ns + " .pd-nav-main-item:not(#"+id+")";
					fadeOut(selectorMain);
					
				},
				function(){
					var id = jQuery(this).attr("id");
					var idNo = id.substr("pd-nav-main-item-".length);
					
					var prefix = " #pd-nav-sub-td-";
					var selectorSub = ns + prefix+idNo+" .pd-nav-sub-item";
					fadeOut(selectorSub);
					
					var selectorMain = ns + " .pd-nav-main-item:not(#"+id+")";
					fadeIn(selectorMain);
					
				}

			);
			/**
			 * NABUCCO Navigation Hover
			 */
			jQuery(nabuccoSubItems).css("opacity",0.5);
			
			jQuery(ns + " .pd-nab-table").hover(
					function(){			
						fadeOut(ns + " .pd-nav-main-item");
						fadeIn(ns+" .pd-nab-sub-item");
					},
					function(){
						fadeIn(ns + " .pd-nav-main-item");
						fadeOut(ns+" .pd-nab-sub-item");
					}	
			);
			
			
			/**
			 * Slide Down Animation
			 */
			jQuery(ns + " .pd-nav-slide-down").delay(500).slideDown(700);
			
		}
	};
	
	
})();

