var hideMenu = function() {
	$('div.navigation_overlay_parent').hide();
	/*$('a.activ').children('span').css('background','url("../../../images/fotopoint.storefront/de/imagesonline/layout/navigation_backgr.jpg") no-repeat');*/
	$('a.activ').children('span').removeClass('activ');
	$('a.activ').removeClass('activ');
}

var hideMenuItem = function(item) {
	$(item).children('div.navigation_overlay_parent').hide();
	/*$(item).children('a.activ').children('span').css('background','url("../../../images/fotopoint.storefront/de/imagesonline/layout/navigation_backgr.jpg") no-repeat');*/
	$(item).children('a.activ').children('span').removeClass('activ');
	$(item).children('a.activ').removeClass('activ');
}

function crossSellingShowMoreSwitch(target){
	if ($.browser.msie && $.browser.version == '8.0'){
		//alert("Target: " +  target +" IE:"+$.browser.msie+ " Version: "+$.browser.version);
		$(".c" + target).each(function(i, elem) {
			$(elem).css('display', 'block' );
	     });
		$(".b" + target).each(function(i, elem) {
			$(elem).css('display','none');
	     });


	} else {
		$(".c" + target).slideDown("slow"); 
		$(".b" + target).slideUp("slow");
	}
	
	return false;
}

$(document).ready(function() {


	var timer;
	var hoverTimer;
	var activMenuItem;
	var wait;
	
	$('#navigation > li').hover(
		function() {
			
			var that = $(this);

			// Delay setzen, erst 500 Ms öffnet sich das entsprechende Menü
			wait = window.setTimeout( function() {
			
				activMenuItem = $(that).attr('id');
			
				$('#navigation > li ').each(function() {
					
					if($(this).attr('id') != activMenuItem) {
						hideMenuItem($(this));
					} 
				})
			
				

				var overlay = $(that).children('div.navigation_overlay_parent');
				$(that).children('a').addClass('activ');
				
				clearTimeout(timer);
				
				
				var offset_left = $(that).children('a').children('span').position().left;
				var offset_left_start = $(that).children('a').children('span').position().left;
				var width = $(that).children('div.navigation_overlay_parent').width();
				
				
				
				// der vorletzte NaviReiter
				if(offset_left >= 620 && offset_left < 775)
				{
					if(width > 310) // Wenn die Klappnavi mehr als 2 Spalten hat nach links aufklappen
						offset_left = offset_left - (width-155);
				}
				// der letzte NaviReiter -- die klappnavi immer nach links aufklappen
				else if(offset_left >= 775)
				{
						offset_left = offset_left - (width-155);
				}
				
				/*$('#debug').text('breite: '+width+' -- offset_start: '+offset_left_start+' -- offset: '+offset_left);*/
				
				$(overlay).css('left',offset_left+'px');
                
				
				/*$(this).children('a.activ').children('span').css('background','url("../../../images/fotopoint.storefront/de/imagesonline/layout/navigation_backgr_activ.jpg") no-repeat');*/
				$(this).children('a.activ').children('span').addClass('activ');
				
				
				$(that).children('div.navigation_overlay_parent').slideDown(300);//fadeIn(500); // steuert die Zeit, in der der große Block erscheint
			}, 500);
		},
		function() {
			
			timer = window.setTimeout(hideMenu,500); // steuert die Zeit, in der das Menü komplett wieder verschwindet
			clearTimeout(wait);
			
		}
	)



	$('div.sidebar_headline').click( function() {
		$(this).parent().children('ul').toggle();
	})
	
	$('span.navigation_top_right_basket_item').click( function() {
		$('div.navigation_top_right_basket').toggle();
	})
	
	$.ifixpng('../../../images/fotopoint.storefront/de/imagesonline/space.gif');
	$('img[@src$=.png]').ifixpng();
	
	$("a.tiplink").simpletooltip({
		effect: "fadeIn"
		
	});
	
	
	
	


	
	
	
	/**
	* Teaser image switch
	*/
	var activImage = 2;
	var timer_switcher;
	
	/*
	$('div.teaser-switch > ul').css('position','relative').css('z-index','0');
	
	$('div.teaser-switch > ul > li').css('position','absolute').css('z-index','0');
	*/
	
	$('div.teaser-switch > ul').height($('div.teaser-switch > ul > li:first a img').height());
	$('div.teaser-switch > ul').each(function() {
		
		$('div.teaser-switch > ul > li').each(function(i,item) {


			var titel = $(this).children('a').attr('title');

			var li = $('<li><a href=""><span>'+titel+'</span></a></li>');

			if(i == 0) {
				$(this).show();
				li.addClass('activ');
			}

			var that = $(this);
			li.children('a').click(function() {
			
				$('div.teaser-switch > ul > li').slideUp(2000);
				//$(that).fadeIn('slow');
				$(that).show();
				$('div.switch-menu > ul > li').removeClass('activ');
				$(this).parent().addClass('activ');

				window.clearTimeout(timer_switcher);

				return false;
				
			});
			$('div.switch-menu > ul').append(li);
			
		});
	})

	function teaserTimeSwitcher() {

		var item = $('div.teaser-switch > ul > li:nth-child('+activImage+')');

		if(item.length != 0) {
			$('div.teaser-switch > ul > li').slideUp(2000);
			
			$(item).slideDown(1000);
			$('div.switch-menu > ul > li').removeClass('activ');
			$('div.switch-menu > ul > li:nth-child('+activImage+')').addClass('activ');


			if(activImage == $('div.teaser-switch > ul > li').length) {
				activImage = 1;
			} else {
				activImage+=1;
			}


		}

		timer_switcher = setTimeout(teaserTimeSwitcher, 6000);
	}
	timer_switcher = setTimeout(teaserTimeSwitcher, 6000);
	
});
