// jQuery

$(document).ready(function () {	
	
	// GET Parameter auslesen - ähnlich wie in PHP werden nun alle GET Parameter im Array "get" gespeichert; Bsp.: get['l']
	var s = window.location.search.substring(1).split('&');
	get = {}; 
	if(s.length){
		for(var i  = 0; i < s.length; i++) {
			var parts = s[i].split('=');
			window.get[unescape(parts[0])] = unescape(parts[1]);
		}//for
	}//if
	
	$("#accordion").accordion({
		navigation: true,
		navigationFilter: function(){
			var search;
			var loc = location.href.toLowerCase();
			var href = this.href.toLowerCase();
			var pre = 'acc';
			var pos_acc = href.indexOf(pre);
			if(pos_acc != -1){ search = href.substring(pos_acc+pre.length+1); }//if
			if(search == get['tipp']){ return true; }//if
		}//navFilt
	});
	
	$("#accordion_merkliste").accordion({
		navigation: true,
		navigationFilter: function(){
			var search;
			var loc = location.href.toLowerCase();
			var href = this.href.toLowerCase();
			var pre = 'acc';
			var pos_acc = href.indexOf(pre);
			if(pos_acc != -1){ search = href.substring(pos_acc+pre.length+1); }//if
			if(search && loc.indexOf(search) != -1){ return true; }//if
		}//navFilt
	});	
		
	/* Kochschule Bildaustausch */
	$("#kochschule").hover(function (){
		$("#kochschule").attr("src", "images/kochschule-no-1-mo.jpg" );
	}, function(){
		$("#kochschule").attr("src", "images/kochschule-no-1.jpg" );
	});
	/* Drucken Bildaustausch */
	$("#drucken").hover(function (){
		$("#drucken").attr("src", "images/merkliste-drucken-mo.jpg" );
	}, function(){
		$("#drucken").attr("src", "images/merkliste-drucken.jpg" );
	});
	/* Einbaugeräte Berater Features */
	$("#einbaugeraete-berater").hover(function (){
		$("#einbaugeraete-berater").attr("src", "images/einbaugeraete-berater-mo.png" );
	}, function(){
		$("#einbaugeraete-berater").attr("src", "images/einbaugeraete-berater.png" );
	});
	/* Merkliste Features */
	$("#features-merkliste-setzen").hover(function (){
		$("#features-merkliste-setzen").attr("src", "images/merkliste-features-mo.png" );
	}, function(){
		$("#features-merkliste-setzen").attr("src", "images/merkliste-features.png" );
	});
	/* features-produktangebot */
	$("#features-produktangebot").hover(function (){
		$("#features-produktangebot").attr("src", "images/features-produktangebot-mo.png" );
	}, function(){
		$("#features-produktangebot").attr("src", "images/features-produktangebot.png" );
	});
	/* Dynamische Leere Btn Features */
	$(".video_buehne_links_button_leer").hover(function (){
		$(".leere_button_blau").css("background", "url(images/button-leer-mo.png) no-repeat" );
	}, function(){
		$(".leere_button_blau").css("background", "url(images/button-leer.png) no-repeat");
	});
	/* weitere Technologien Btn Features */
	$("#weiteretechno_mo").hover(function (){
		$("#weiteretechno_mo").attr("src", "images/weitere_Technologien_MO.png" );
	}, function(){
		$("#weiteretechno_mo").attr("src", "images/weitere_Technologien.png");
	});
	
	
	
	/* Features MO */
	$(".features_mo").each(function (i) {
		$(".features_mo").eq(i).mouseover(function (){
			$(".features_mo").eq(i).attr("src", "images/features/"+$(this).attr('alt')+"_MO.png");
		});
		$(".features_mo").eq(i).mouseout(function (){
			$(".features_mo").eq(i).attr("src", "images/features/"+$(this).attr('alt')+".png");
		});
	});
	
	
	/* video verlinkung mouseover bildaustausch */
	/*$('.video_link_wrapper').die();
	$('.video_link_wrapper').live({
		mouseover: function(){
			$(".video_link_wrapper"+$(this).attr('id')).stop(true,true).hide();
			$(".video_link_wrappermo"+$(this).attr('id')).stop(true,true).show();
		}
	});
	$('.video_link_wrappermo01').die();
	$('.video_link_wrappermo01').live({
		mouseout: function(){
			$(".video_link_wrappermo"+$(this).attr('popupid')).stop(true,true).hide();
			$(".video_link_wrapper"+$(this).attr('popupid')).stop(true,true).show();
		}
	});
	$('.video_link_wrappermo02').die();
	$('.video_link_wrappermo02').live({
		mouseout: function(){
			$(".video_link_wrappermo"+$(this).attr('popupid')).stop(true,true).hide();
			$(".video_link_wrapper"+$(this).attr('popupid')).stop(true,true).show();
		}
	});
	$('.video_link_wrappermo03').die();
	$('.video_link_wrappermo03').live({
		mouseout: function(){
			$(".video_link_wrappermo"+$(this).attr('popupid')).stop(true,true).hide();
			$(".video_link_wrapper"+$(this).attr('popupid')).stop(true,true).show();
		}
	});
	
	$('.video_link_wrappermo01').live({
		click: function(){
			var id = $(this).attr("popupid");
			var content = $(this).attr("rel");
			var title = $(this).attr("title");
			$("#pos_video_buehne").stop(true,true).show();
			$("#pos_overlay").stop(true,true).show();
			$('#pos_video_mitte').append(content);
			$('span.video_title').append(title);
		}
	});
	$('.video_link_wrappermo02').live({
		click: function(){
			var id = $(this).attr("popupid");
			var content = $(this).attr("rel");
			var title = $(this).attr("title");
			$("#pos_video_buehne").stop(true,true).show();
			$("#pos_overlay").stop(true,true).show();
			$('#pos_video_mitte').append(content);
			$('span.video_title').append(title);
		}
	});
	$('.video_link_wrappermo03').live({
		click: function(){
			var id = $(this).attr("popupid");
			var content = $(this).attr("rel");
			var title = $(this).attr("title");
			$("#pos_video_buehne").stop(true,true).show();
			$("#pos_overlay").stop(true,true).show();
			$('#pos_video_mitte').append(content);
			$('span.video_title').append(title);
		}
	});*/
	
	/* bosch infoline */
	$('#bosch_infoline').live({
		click: function(){
			$("#pos_bosch_infoline_buehne").stop(true,true).show();
			$("#pos_overlay").stop(true,true).show();
		}
	});
	
	/* click bei dots auf detailsseiten */
	$('.video_link_dot').live({
		click: function(){
			var id = $(this).attr("popupid");
			var content = $(this).attr("rel");
			var title = $(this).attr("title");
			$("#pos_video_buehne").stop(true,true).show();
			$("#pos_overlay").stop(true,true).show();
			$('#pos_video_mitte').append(content);
			$('span.video_title').append(title);
		}
	});
	
	/* allgemein video layer schließen*/
	$('#video_close').live({
		click: function(){
			$("#pos_bosch_infoline_buehne").stop(true,true).hide();
			$("#pos_video_buehne").stop(true,true).hide();
			$("#pos_overlay").stop(true,true).hide();
			$('#pos_video_mitte').empty();
			$('span.video_title').empty();
		}
	});
	
	
	$('.berater_menu').mouseover(function(){
		$(this).css('background','#e1e1e2');
	});
	$('.berater_menu').mouseout(function(){
		$(this).css('background','');
	});
		
		
	// Tooltip für Küchenübersicht
	showToolTip();
	function showToolTip () {
		var content = '';
		var hotspot = '.hotspot';
		var tooltip = '.tooltip';
		var tooltipContent = '.tooltipcontent';
		var htmlcontent = 'content';
		var speedIn = 200;
		var speedOut = 300;
		var delaySpeed = 200;
		var hotspotCoord = Array();
		var tooltipMargin = Array();
		tooltipMargin['x'] = +18;
		tooltipMargin['y'] = +55;

		$(hotspot).live({
		    mouseover: function(){
				content = '';
				hotspotCoord['x'] = $(this).css('left');
				hotspotCoord['y'] = $(this).css('top');
				$(tooltip).css('left',parseInt(hotspotCoord['x'].substring(0,hotspotCoord['x'].length-2))+tooltipMargin['x'] + 'px');
				$(tooltip).css('top',parseInt(hotspotCoord['y'].substring(0,hotspotCoord['y'].length-2))+tooltipMargin['y'] + 'px');
			
					content += '<table id="table_tooltip_picto" border="0" cellpadding="0" cellspacing="0"><tr><td>';
					content += $(this).attr(htmlcontent);
					content += '</td></tr></table>';
					
				$(tooltipContent).html(content);
				$(tooltip).stop(true,true).delay(delaySpeed).fadeIn(speedIn);
			}
		});
		$(hotspot).live({
		    mouseout: function(){
				content = '';
				$(tooltip).stop(true,true).fadeOut(speedOut, function(){
					$(tooltipContent).html(content);
				});
			}
		});
	}//f
	
	
	/* Tooltip für Produktdetailseiten */
	showToolTipDetail();
	function showToolTipDetail () {
		var content = '';
		var hotspot = '.hotspot_detail';
		var tooltip = '.tooltip';
		var tooltipContent = '.tooltipcontent';
		var htmlcontent = 'content_detail';
		var picto = 'picto';
		var pictopath = 'images/picto/';
		var pictotype = 'png';
		var speedIn = 200;
		var speedOut = 300;
		var delaySpeed = 200;
		var hotspotCoord = Array();
		var tooltipMargin = Array();
		tooltipMargin['x'] = +18;
		tooltipMargin['y'] = +55;

		$(hotspot).live({
		    mouseover: function(){
				content = '';
				hotspotCoord['x'] = $(this).css('left');
				hotspotCoord['y'] = $(this).css('top');
				$(tooltip).css('left',parseInt(hotspotCoord['x'].substring(0,hotspotCoord['x'].length-2))+tooltipMargin['x'] + 'px');
				$(tooltip).css('top',parseInt(hotspotCoord['y'].substring(0,hotspotCoord['y'].length-2))+tooltipMargin['y'] + 'px');
				if($(this).attr(picto)){
					content += '<table id="table_tooltip_picto" border="0" cellpadding="0" cellspacing="0"><tr><td><img src="' + pictopath + $(this).attr(picto) + '.' + pictotype + '" alt="picto-'+$(this).attr(picto)+'" /></td><td style="padding: 0 5px;">';
					content += $(this).attr(htmlcontent);
					content += '</td></tr></table>';
				}else{
					content += '<table id="table_tooltip_picto" border="0" cellpadding="0" cellspacing="0"><tr><td>';
					content += $(this).attr(htmlcontent);
					content += '</td></tr></table>';
				}//if
				$(tooltipContent).html(content);
				$(tooltip).stop(true,true).delay(delaySpeed).fadeIn(speedIn);
			}
		});
		$(hotspot).live({
		    mouseout: function(){
				content = '';
				$(tooltip).stop(true,true).fadeOut(speedOut, function(){
					$(tooltipContent).html(content);
				});
			}
		});
	}//f
	
	// Extern Link Teaser
	MOExternLinkTeaser();
	function MOExternLinkTeaser () {
		var brWidth = null;
		var brHeight = null;
		var xtl = '.extern_link_teaser';
		var xtlbox = '.externlinkteaserbox';
		var xtlboxcontent = '.externlinkteaserboxcontent';
		var xtlboxhtml = $(xtlbox).html();
		var boximagepath = 'images/produktdetails/';
		var speedIn = 200;
		var speedOut = 0;
		var speedDelay = 200;
		var mouseMargin = Array();
		mouseMargin['x'] = -25;
		mouseMargin['y'] = -70;
		var mouseMarginBoxImage = Array();
		mouseMarginBoxImage['x'] = -20;
		mouseMarginBoxImage['y'] = -157;
		
		$(xtl).mouseover(function(){
			var boxcontent = $(this).attr('boxcontent');
			var boximage = $(this).attr('boximage');
			if(boximage){
				$(xtlbox).html('<img src="' + boximagepath + boximage + '" />');
				$(document).mousemove(function(e){
					brWidth = $(window).width(); brHeight = $(window).height();
					$(xtlbox).css('left',e.pageX+mouseMargin['x']+(brWidth-1000)/-2);
					$(xtlbox).css('top',e.pageY+mouseMarginBoxImage['y']);
				});
			}else{
				$(xtlboxcontent).html(boxcontent);
				$(document).mousemove(function(e){
					brWidth = $(window).width(); brHeight = $(window).height();
					$(xtlbox).css('left',e.pageX+mouseMarginBoxImage['x']+(brWidth-1000)/-2);
					$(xtlbox).css('top',e.pageY+mouseMargin['y']);
				});
			}//if else
			
			$(xtlbox).stop(true,true).delay(speedDelay).slideToggle(speedIn);
		});
		$(xtl).mouseout(function(){
			$(xtlbox).stop(true,true).fadeOut(speedOut, reset);
			function reset () {
				$(xtlbox).html(xtlboxhtml);
			}//f
		});
	}//f
	
	// Einbau-Berater Infos wechseln auf Mouseover
	switchPmInfos();
	function switchPmInfos () {
		var pmMOButton = '.berater_menu';
		var speedIn = 0;
		var speedOut = 0;
		$(pmMOButton).mouseover(function(){
			var name = $(this).attr('name');
			name = name.replace('+','plus');
			$('.pos_berater_spalte2_inhalt').stop(true,true).fadeOut(speedOut, function(){
				$('.berater_pm_info_' + name).stop(true,true).fadeIn(speedIn);
			});
			//alert(title);
		});
		$(pmMOButton).mouseout(function(){
			var radios = $('input[type=radio]');
			for(var i = 0; i < radios.length; i++){
				if(radios[i].checked){
					var div = radios[i].parentNode.parentNode;
					var name = div.getAttribute('name');
					name = name.replace('+','plus');
					$('.pos_berater_spalte2_inhalt').stop(true,true).fadeOut(speedOut, function(){
						$('.berater_pm_info_' + name).stop(true,true).fadeIn(speedIn);
					});
				}//if
			}//for
		});
	}//f
	
	// AJAX
	// Auf Merkliste setzen
	saveOnMl();
	function saveOnMl(){
		var speedOut = 300;
		var ml = $('.merkliste-link-anzahl').text();
		ml = parseInt(ml)+1;
		
		// Ajax
		var section = get['l'];
		$('.berater_end_aufmerklistesetzen').click(function(){
			$.post('includes/session_save_ajax.php?l_ajax=' + section, { ajaxcall: 'fb_saveOnMl' }, function(){
				$('.berater_end_aufmerklistesetzen').fadeOut(speedOut);
				$('#pos_berater_seiten').animate({opacity: 0}, speedOut, function(){
					$('#pos_berater_seiten').html('')
				});
				$('.pos_editsave').fadeOut(speedOut);
				$('.merkliste-link-anzahl').text(ml);
			});
		});
	}//f
	saveFeatureonMl();
	function saveFeatureonMl () {
		var speedOut = 300;
		var ml = $('.merkliste-link-anzahl').text();
		ml = parseInt(ml)+1;
		
		var section = window.location.href.split('/'); 
		section = section[section.length-2];
		var ft = window.location.href.split('/');
		ft = ft[ft.length-1].substring(ft[ft.length-1].length-6,ft[ft.length-1].length-5);
		
		$('#features-merkliste-setzen').click(function(){
			$.post('includes/session_save_feature_ajax.php?l_ajax=' + section + '&ft_ajax=' + ft, function(data){
				$('.leere_button_blau').fadeOut(speedOut);
				$('.merkliste-link-anzahl').text(ml);
			});
		});
	}//f
	
	// weiter Button einfärben
	colorNextBtn();
	function colorNextBtn() {
		var href = window.location.href;
		var seite = href.substring(href.length-1);
		var radios = $('input:checked');
		var weiter = $('input[name=submit_pm_berater_weiter]');
		var weiterPfeil = $('.pfeile_grau_rechts_weiter');
		
		// Dunstabzugshauben Berechnung
		var da_ber_luefterleistung = $('#da_ber_luefterleistung').val();
		
		$('input').click(function(){
			if((!$('.da_ber_inp').eq(0).val() || !$('.da_ber_inp').eq(1).val() || !$('.da_ber_inp').eq(2).val()) && get['l'] == 'dunstabzuege' && get['bp'] == 3){
				
			}else{
				colorNextBtn();
			}//if
		});
		
		$('.da_ber_inp').eq(2).keydown(function(){
			if($('.da_ber_inp').eq(0).val() && $('.da_ber_inp').eq(1).val()){
				colorNextBtn();
			}//if
		});
		
		if(radios.length || da_ber_luefterleistung > 0){
			weiter.css({
				'color': '#215f8b',
				'cursor': 'pointer'
				});
			weiter.removeAttr('disabled');
			weiterPfeil.css('backgroundImage', 'url(../images/Linkpfeil.png)');
			$('input[name=submit_pm_berater_weiter]').mouseover(function(){weiter.css('color', '#00142a');});
			$('input[name=submit_pm_berater_weiter]').mouseout(function(){weiter.css('color', '#215f8b');});
			
			var navi = $('input[name*=submit_pm_berater_navi_]');
			for(var i = 0; i < navi.length; i++){
				var value = navi.eq(i).attr('value');
				if((value-1) <= seite){
					navi.eq(i).css({
						'color': '#215f8b',
						'cursor': 'pointer'
						});
					navi.eq(i).removeAttr('disabled');
				}//if
			}//for
		}else{
			weiter.css({
				'color': '#a5a6a7',
				'cursor': 'default'
				});
			weiter.attr('disabled', 'disabled');
			weiterPfeil.css('backgroundImage', 'url(../images/Linkpfeil-hellgrau.png)');
			
			var navi = $('input[name*=submit_pm_berater_navi_]');
			for(var i = 0; i < navi.length; i++){
				var value = navi.eq(i).attr('value');
				if(value > seite){
					navi.eq(i).css({
						'color': '#a5a6a7',
						'cursor': 'default'
						});
					navi.eq(i).attr('disabled', 'disabled');
				}else{
					navi.eq(i).css({
						'color': '#215f8b',
						'cursor': 'pointer'
						});
					navi.eq(i).removeAttr('disabled');
				}//if
			}//for
				
		}//if else
		
		
	}//f
	
	// Tipps ein- und ausfahren
	var posLeftTeaser = parseInt($('#pos_allgtipps_wrapper').css('left'));
	var posLeftTipps = parseInt($('#pos_allgtipps_wrapper_active').css('left'));
	hideTeaser();
	function hideTeaser () {
		var speedHideTeaser = 800;
		if(get['tipp'] >= 1 && get['bp'] == 1){
			$('#pos_allgtipps_wrapper').css({
				left: posLeftTeaser+50
			});
			showTipps();
		}//if
		$('#pos_allgtipps_wrapper').click(function(){
			$('#pos_allgtipps_wrapper').animate({
				left: posLeftTeaser+50
			}, speedHideTeaser, 'swing', showTipps);
		});
	}//f
	function showTipps (){
		var speedShowTeaser = 300;
		$('#pos_allgtipps_wrapper_active').animate({
				left: 0
			}, speedShowTeaser, 'swing');
	}//f
	
	hideTipps();
	function hideTipps () {
		var speedHideTipps = 800;
		$('#pos_allgtipps_close').click(function(){
			$('#pos_allgtipps_wrapper_active').animate({
				left: posLeftTipps
			}, speedHideTipps, 'swing', showTeaser);
		});
	}//f
	function showTeaser (){
		var speedShowTipps = 800;
		$('#pos_allgtipps_wrapper').animate({
				left: posLeftTeaser
			}, speedShowTipps, 'swing');
	}//f
		
	
	hoverLinks();
	function hoverLinks () {
		$('a.ml_hover').mouseover(function(){$(this).css('color', '#00142a')});
		$('a.ml_hover').mouseout(function(){$(this).css('color', '#215f8b')});
	}//f
	
	
	
	/*Fallback lösung für no flash Features videos*/
//	if (navigator.mimeTypes ["application/x-shockwave-flash"] != undefined) {
//		$("#html5player").hide();
//		var tmp_src = $("#flashplayer").attr("videoattr");
//		var tmp_url = "http://www.youtube.com/v/";
//		$("#flashplayer").attr("src", tmp_url+tmp_src);
//		$("#flashplayer").show();
//		
//	} else { 
//		<!-- flash ist nicht installiert! -->
//		$("#flashplayer").hide();
//		$("#html5player").show();
//	} 
	
	
});


// Javascript

function openDetailseiten (url) {
	window.location.href = url;
}//f

function submitEditPmForm () {
	document.forms[0].submit();
}//f

/* flash intro ausfaden */
/*fadeIntroOut();*/
function fadeIntroOut () {
	$('#pos_auswahl_wrapper_intro').fadeOut('slow');
	$('#flashcontent').fadeOut('slow');
	$('#pos_auswahl_wrapper_startzuerst').hide();
	$('#pos_auswahl_wrapper_start').show();
}// f
