$(document).ready(function() {
	if(!$('body').hasClass('js')) {
		$('body')
			.addClass('js');
	}
	//custom dropdowns
	if($('#serviceSelect').length) {
		$('#serviceSelect').rocks({
			replace:	true,
			onChange:	function(){
			    window.location.href = $("#serviceSelect").val();
			}
		});
		if ($.browser.msie) {
			$(".rockdown ul.options button").hover(function() {
				$(this).addClass("hover");
			}, function() {
				$(this).removeClass("hover");
			})
		}
	}
	
	//layer navigation - hoverIntent
	var config = {    
		over: showNav, // function = onMouseOver callback (REQUIRED)    
		timeout: 500, // number = milliseconds delay before onMouseOut    
		out: hideNav // function = onMouseOut callback (REQUIRED)    
	};
	$navDivs = $('#mainnav-box .mainnav-box123pfad div:not(".pfadnavi")')
	$navDivs.filter(':last').addClass('lastDiv');
	$navDivs.eq(1).addClass('firstDiv');
	$kundenPortal = $('div.kundenportal');
	$navDivs
		.hoverIntent(config)
		.find('li:last')
		.css('border','none')
	function showNav() {
		var $this = $(this);	
		if($this.hasClass('firstDiv')) {
			 xpos = 3;
		} else {
			 xpos = 0;
		}
		$this
			.find('.subNavOuter')
			.css("left" , $(this).position().left - 10 + parseInt(xpos))
			.slideDown('fast');
	}
	function hideNav() {
		var $this = $(this);	
		$(this)
			.find('.subNavOuter')
			.slideUp('fast');
	}
	
	/* ------------ SERVICE ACCORDION -------------- */
	var serviceSubConfig = {    
		over: showSub, // function = onMouseOver callback (REQUIRED)    
		timeout: 300, // number = milliseconds delay before onMouseOut    
		out: foo // function = onMouseOut callback (REQUIRED)    
	};	
	$('#mod5 > li')
		.hoverIntent(serviceSubConfig)
		.find('.accordionBtn')
		.bind({
			click : function(e) {
				e.stopPropagation();
				$parentLi = $(this).closest('li');
				if($parentLi.hasClass('open')) {
					hideSub.apply($parentLi.get(0), arguments);	
				} else {
					showSub.apply($parentLi.get(0), arguments);		
				}
			},
			mouseover : function(e) {
				$(this)
					.addClass('accordionBtnHover');
			},
			mouseout : function(e) {
				$(this)
					.removeClass('accordionBtnHover');
			}
		});
	var serviceConfig = {    
		over: foo, // function = onMouseOver callback (REQUIRED)    
		timeout: 300, // number = milliseconds delay before onMouseOut    
		out: hideAllSubs // function = onMouseOut callback (REQUIRED)    
	};	
	$('#mod5')
		.hoverIntent(serviceConfig);
	
	$('#service-home-box')
		.find('li')
		.bind({
			mouseover : function(){
				$(this)
					.find('p,span')
					.show();
			},
			mouseout : function() {
				$(this)
					.find('p,span')
					.hide();
			},
			click : function() {
				$(this)
					.find('p,span')
					.attr('href');
			}
		});
	/* adjusts service-teaser height: equal column heights for all teasers */
	if($('#serviceHome').length) {
		$.each($('#serviceHome').find('div.serviceRow'),function(){
			$teasers = $(this).find('.teaser-service');
			teaserLength = $teasers.length;
			if(teaserLength && teaserLength>1) {
				var currHeight = 0;
				for(i=0,I=teaserLength;i<I;i++) {
					var itemHeight = $($teasers[i]).height();
					if(itemHeight>currHeight) {
						currHeight = itemHeight;
					}
				}
				$teasers.css('height',currHeight);
			}
		})
	}
		
	
});
function foo() {
	
}
function showSub() {
	var $sub = 	$(this).find('ul');
	if($sub.length) {
		$sub
			.slideDown('fast',function(){
				$(this).parent().addClass('open').removeClass('closed')	
			});
	}
}
function hideSub() {
	var $sub = $(this).find('ul');
	if($sub.length) {
		$sub
			.slideUp('fast',function(){
				$(this).parent().addClass('closed').removeClass('open');
			});
	}
}
function hideAllSubs() {
	$sub = 	$(this).closest('.serviceNew').find('ul');
	if($sub.length) {
		$sub
			.slideUp('fast',function(){
				$('#mod5 > li').removeClass('open').addClass('closed');
			});
	}
}
/* EOF */
