Shadowbox.init();
$(document).ready(function(){

	$('ul.menu').suckerfish();
	$('ul#navSub').suckerfish();

	//Prevent links from being clicked when has subs
	$('ul#navMain > li > span > a').click(function(e) {
		e.preventDefault();
		//if($(this).parent().parent().find('ul').length > 0) 
			//e.preventDefault();
	});
	$('ul#navSub').find('a').click(function(e) {
		if($(this).parent().find('ul').length > 0)
			e.preventDefault();
	});

	var baseSearch = 'Ihre PLZ...';
	$('#plzi').focus(function() {
		if($(this).val() == baseSearch)
			$(this).val('');
	});

	$('#plzi').blur(function() {
		if($(this).val() == '')
			$(this).val(baseSearch);
	});

	/* BEN&MICHI: From 150 lines to 5 */
	/* Entfernt: HDNET Mantis: 13976 */
	/*$('#navMain>li').hover(
		function() { $(this).siblings().addClass('opacity'); },
		function() { $(this).siblings().removeClass('opacity'); }
	);

	$('#navMain li ul>li').hover (
		function() { $(this).parent().parent().find('a:first').addClass('over'); },
		function() { $(this).parent().parent().find('a:first').removeClass('over'); }
	);
	*/

		//over
		/*$(".mn1_li").mouseover(function(){ $(".mn1").addClass("over1"); });
		$(".mn1_li").mouseout(function(){ $(".mn1").removeClass("over1"); });

		$(".mn2_li").mouseover(function(){ $(".mn2").addClass("over2"); });
		$(".mn2_li").mouseout(function(){ $(".mn2").removeClass("over2"); });

		$(".mn3_li").mouseover(function(){ $(".mn3").addClass("over3"); });
		$(".mn3_li").mouseout(function(){ $(".mn3").removeClass("over3"); });

		$(".mn4_li").mouseover(function(){ $(".mn4").addClass("over4"); });
		$(".mn4_li").mouseout(function(){ $(".mn4").removeClass("over4"); });

		$(".mn5_li").mouseover(function(){ $(".mn5").addClass("over5"); });
		$(".mn5_li").mouseout(function(){ $(".mn5").removeClass("over5"); });

		$(".mn6_li").mouseover(function(){ $(".mn6").addClass("over6"); });
		$(".mn6_li").mouseout(function(){ $(".mn6").removeClass("over6"); });

		$(".mn7_li").mouseover(function(){ $(".mn7").addClass("over7"); });
		$(".mn7_li").mouseout(function(){ $(".mn7").removeClass("over7"); });

		$(".mn8_li").mouseover(function(){ $(".mn8").addClass("over8"); });
		$(".mn8_li").mouseout(function(){ $(".mn8").removeClass("over8"); });*/


	// Header Slide
	var elements = 0;
	$('.header-box').each(function(){ elements++; });
	var zIndexCounter = elements;
	var showCurrent = 0;

	if(elements > 1) {
		$(document).everyTime("10s", function(i) {
			showCurrent++;
			if(showCurrent > elements)
				showCurrent = 0;

			$('.header-box').each(function(count, obj){
				if(showCurrent == count) {
					$(this).hide();
					zIndexCounter++;
					$(this).css('z-index', zIndexCounter);
					$(this).fadeIn(2000);
				}
			});
		});
	}

});

jQuery.fn.suckerfish = function() {
	/* if ($.browser.msie && $.browser.version*1 < 7){ */
	/*if (true){
		this.find('li').click(function(){
			$(this).addClass('over');
		},
		function(){
			$(this).removeClass('over');
		});
	}*/
	var isOver = false;
	var timer;
	var obj = $(this);
	this.find('li')
		.click(function() {
			$(this).siblings().removeClass('over');
			$(this).siblings().find('li.over').removeClass('over');
			$(this).addClass('over');
		})
		.mouseover(function(){
			isOver = true;
			//console.log('isOver!(clearTimeout)');
			clearTimeout(timer);	
		})
		.mouseout(function(){
			isOver = false;
			//console.log('isNOTOver!');
			//var $t = $(this);
			//$t.removeClass('over');
			var timer = setTimeout(function() {
				if(isOver == false) {
					//console.log('timeout:isNOTOver!');
					obj.find('li.over').removeClass('over');	
				} else {
					//console.log('timeout:isOver!');
					// To be sure
					//clearTimeout(timer);	
				}
			},500);
			//$(this).removeClass('over');
		});

}

