var shown = -1;

function hidem() {
	$('#s'+shown+' span').remove();
	$('#s'+shown).hide();
	$('#n'+shown+' a').removeClass('on');
	$('#detailsPop').hide();
	$('#ovr').hide();
	shown = -1;
}

function drop(i) {
	if(shown > -1) { hidem(); }
	shown = i;
	$('#s'+i)
		.prepend('<span></span>')
		.show();
	$('#n'+i+' a').addClass('on');
	$('#ovr').show();
}

function spaJetsOn() {
	$(this).children('img').attr('src','../images/jets/on/'+$(this).children('img').attr('src').substr(15));
	$('#jets-feature .jets-info').html($(this).next().html());
	$('#jets-feature .jets-info').prepend('<h2>'+$(this).children('b').html()+'</h2>');
	$('#jets-feature .def-inside').hide();
	$('#jets-feature .jets-info').show();
}
function spaJetsOff() {
	$(this).children('img').attr('src','../images/jets/'+$(this).children('img').attr('src').substr(18));
	$('#jets-feature .jets-info').empty().hide();
	$('#jets-feature .def-inside').show();
}

function detailOver(link) {
	$('#detailsPop a').empty();
	var img = $(link).children("img");
	var pos = $(link).attr('href');
	var meta = $(link).next();
	$("#det-s").html($(".s", meta).html());
	$("#det-d-en").html($(".d .en", meta).html());
	$("#det-d-m").html($(".d .m", meta).html());
	$("#det-j").html($(".j", meta).html());
	pos = pos.substr(0,pos.length -5);
	if(pos.indexOf('InGround') < 0) {
		pos = 'images/' + pos.substr(0,3) + '-series' + pos.substr(9).toLowerCase() + '-small.jpg';
	} else {
		pos = 'images/880-series/in-ground-' + img.attr("alt").toLowerCase() + '-small.jpg';
	}
	$('#detailsPop img').attr('src', pos);
	$('#detailsPop img').attr('alt',img.attr("alt"));
	$('#detailsPop a')
		.attr('href', $(link).attr('href'))
		.attr('class',img.attr("alt"))
		.append($(img).clone());
	pos = $(img).offset();
	$('#detailsPop')
		.css({left: (pos.left - 18), top: (pos.top -161)})
		.show();
	$('#ovr').show();
}
var tmpclk;
var popX; var popY; var minX; var maxX; var minY; var maxY;
$(function(){
	$('body').append('<a href="" id="ovr"></a>');
	$('input').blur(function() {
		if($(this).val() == "") {
			$(this).val($(this).attr('title'));
			if($(this).attr('title')) {
				$(this).attr('title','');
			}
		}
	});
	$('input').focus(function() {
		tmpclk = $(this).val();
		if((!($(this).attr('title'))) && (tmpclk == '')) {
			$(this).attr('title',tmpclk).val("");
		}
	});
	$('#nav a').each(function(i){ $(this).mouseover(function() { drop(i); }); });
	$('#ovr').mouseover(hidem);
	var st = $('#n0 a').attr('href');
	var ps = st.indexOf('spas.html');
	st = st.substr(0,ps);
	$('#hdr form#dealer-finder').attr('method','post').attr('action',st + 'LocateDealer/LocateDealer.php');
	$('#compare a').mouseover(function() { detailOver(this); });
	$('#compare a[href$="Series.html"]').unbind('mouseover').css('margin','0').children().css('margin','0');
	$('#detailsPop a').mouseout(hidem);
	//add submenus

	str = '<a href="' + st;
	$('#nav').after(
	    '<div id="s0">'+str+'whirlpools.php">Whirlpool-Modelle</a>'+str+'whirlpools_ausstattung.php">Whirlpool-Ausstattung</a>'+str+'whirlpools_zubehoer.php">Whirlpool-Zubehör</a>'+str+'whirlpools_gewerblich.php">Whirlpool gewerblich</a>'+str+'whirlpools_sonderangebote.php">Outlet-Center</a>'+str+'whirlpools_thermocoverslide.php">Innovative Abdeckung<br> Thermo-Cover-Slide</a>'+str+'whirlpools_wasserpflege.php">Wasserpflege</a>'+str+'whirlpools_fragen_antworten.php">Fragen & Antworten</a>'+str+'whirlpools_probebaden.php">kostenloses Probebaden</a>'+str+'armstark_service.php">ARMSTARK Service</a>'+str+'whirlpools_galerie.php">Bilder-Galerie</a><br>'+str+'kontakt.php">Infomaterial anfordern</a>'+str+'http://www.armstarkshop.com" target="_blank">Online-Shop</a></div>' +
	    '<div id="s1">'+str+'swimspas_modelle.php">SwimSpa-Modelle</a>'+str+'swimspas_video.php">NEU: SwimSpa Film </a>'+str+'swimspas_probebaden.php">kostenloses Probebaden</a>'+str+'armstark_service.php">ARMSTARK Service</a>'+str+'whirlpools_thermocoverslide.php">Innovative Abdeckung<br>Thermo-Cover-Slide</a><br>'+str+'kontakt.php">Infomaterial anfordern</a>'+str+'http://www.armstarkshop.com" target="_blank">Online-Shop</a></div>' +
		'<div id="s2">'+str+'infrarotkabinen_ds.php">Modelle Daily Sun&reg;</a>'+str+'infrarotkabinen_hm.php">Modelle Healthmate&reg;</a>'+str+'infrarotkabinen_farblichttherapie.php">Farblicht-Therapie</a>'+str+'infrarotkabinen_aromatherapie.php">Aroma-Therapie</a>'+str+'infrarotkabinen_soleinhalation.php">Sole-Inhalation</a>'+str+'infrarotkabinen_umwelt.php">Qualität & Umweltschutz</a>'+str+'infrarotkabinen_zubehoer.php">Zubehör</a>'+str+'infrarotkabinen_fragen_antworten.php">Fragen & Antworten</a>'+str+'armstark_service.php">ARMSTARK Service</a>'+str+'infrarotkabinen_sonderangebote.php">Outlet-Center</a><br>'+str+'kontakt.php">Infomaterial anfordern</a>'+str+'http://www.armstarkshop.com" target="_blank">Online-Shop</a></div>' +
				'<div id="s3">'+str+'natursteine_brunnen.php">Brunnen</a>'+str+'natursteine_grander.php">Grander</a>'+str+'natursteine_troege.php">Tröge</a>'+str+'natursteine_moebel.php">Gartenmöbel</a>'+str+'natursteine_saeulen.php">Säulen</a>'+str+'natursteine_figuren.php">Figuren</a>'+str+'natursteine_platten.php">Platten</a>'+str+'natursteine_sonstiges.php">sonstiges aus Granit</a>'+str+'natursteine_marmor.php">Marmor-Produkte</a>'+str+'natursteine_sandstein.php">Sandstein-Produkte</a>'+str+'natursteine_zubehoer.php">Zubehör</a>'+str+'natursteine_galerie.php">Bilder-Galerie</a><br>'+str+'kontakt.php">Infomaterial anfordern</a>'+str+'http://www.armstarkshop.com" target="_blank">Online-Shop</a></div>' +
		'<div id="s4">'+str+'whirlpools_thermocoverslide.php">Innovative Abdeckung<br>Thermo-Cover-Slide</a>'+str+'gasgriller.php">Gasgriller</a>'+str+'weitere_produkte_metallobjekte.php">Wasserspiele</a>'+str+'weitere_produkte_gusseisen.php">Gusseisen-Produkte</a>'+str+'weitere_produkte_bronze.php">Bronze-Skulpturen</a><br>'+str+'kontakt.php">Infomaterial anfordern</a>'+str+'http://www.armstarkshop.com" target="_blank">Online-Shop</a></div>'
	);
	$('#s0,#s1,#s2,#s3,#s4').addClass('sub');
	$('.sub').wrapInner('<ul></ul>');
	$('.sub a').wrap('<li></li>');
	if($.browser.msie && (jQuery.browser.version < 7.0)) {
		$('head').append('<link rel="stylesheet" href="includes/ie6.css" />');
	}

	// jets tab in spa pages
	$("#jets-links .jet a")
		.mouseover(spaJetsOn)
		.mouseout(spaJetsOff)
		.click(function() { return false; });
	if($('#spaDetails_colors')) {
		popX = $('#spaDetails_colors').offset();
		$('#spaDetails_colors').append('<span id="cpop"><span></span></span>');
		$('#cpop').hide();
		$('#spaDetails_colors div p ~ img')
			.mouseover(function() {
				popX = $(this).offset();
				minX = popX.left + 2; maxX = minX + $(this).width() - 2; minY = popX.top + 2; maxY = minY + $(this).height() - 3;
			}).mousemove(function(event) {
				popX = event.pageX -2;
				popY = event.pageY;
				moveCPop($(this).attr('alt'));
			});
		$('#cpop').mousemove(function(event) {
				popX = event.pageX -2;
				popY = event.pageY;
				moveCPop(false);
		});
	}

	// enlarge view on spa pages
	$('#spaDetails_spaPic a:first').click(function() {
		window.open($(this).attr('href'), 'SpaBig', 'width=600, height=620, location=no, menubar=no,resizeable=1,scrollbars=yes,toolbar=0,top=10,left=100');
		return false;
	});

	if($('#difference_sub')) {
		$('#difference_sub div:last').css('border-bottom','none');
	}
});
function moveCPop(imgALT) {
	if((popX > minX) && (popX < maxX) && (popY > minY) && (popY < maxY)) {
		$('#cpop').css({left: popX + 1, top: popY - 27});
		if(imgALT) {
			$('#cpop').show().children('span').html(imgALT);
		}
	} else {
		$('#cpop').hide();
	}
}