function imagepopup (imageurl, width, height, title) {
	w = window.open('', 'big','location=no, menubar=no, status=no, toolbar=no, width='+width+', height='+height);
	w.document.write("<html><head><link rel=\"stylesheet\" href=\"../css/imagepopup.css\" type=\"text/css\"/><script language=\"javascript\" type=\"text/javascript\" src=\"../js/tools.js\"></script><title>"+title+"</title></head><body onload=\"imagepopup_onload();\"><a href=\"javascript:void;\" onclick=\"self.close();\"><img id=\"bild\" src=\""+imageurl+"\"></a><br/><a href=\"javascript:void;\" onclick=\"self.close();\" class=\"popuplink\">[Fenster schlie&szlig;en]</a></body></html>");
	w.document.close();
}

function imagepopup_onload() {
	node = document.getElementById("bild");
	if (node) {
		x=node.width;
		y=node.height;
		window.resizeTo(x+30, y+90);
	}

}


$().ready(function() {
	
	/* Intro */
	if ($('body').hasClass('welcome') == true) {
		
		$("#newsticker").css("display","block");		
		$("#newsticker").newsticker();
		$('#ssh').css("display","none");

		$('#ersatzhead').remove();

		test = ""; 
		function onBefore() { 
			if ($("div#beton").css("display") == "none"
			 && $("div#wasser").css("display") == "none"
			 && $("div#oberflaeche").css("display") == "none"
			 && $("div#strasse").css("display") == "none"
		     && $("div#rethmeier").css("display") == "none") {
				if (test != "") { 			
					$('li.scn' + test).removeClass(test + 'aktiv'); 
				} 
				test = this.id;
				$('li.scn' + this.id).addClass(this.id + 'aktiv');	
			}
		}
				
			
		$('#headerpic').cycle({ 
			fx: 'fade',
			speed: 'slow',
			timeout:'8000',
			pager: '#contentnavi',
			pagerEvent: 'mouseover', 
    		pauseOnPagerHover: true,
	        before: onBefore
	    });
	} else {
		$('#ssh').css("display","block");
	}
	
	if ($('body').hasClass('produktdetailseite') == true
	 || $('body').hasClass('systemedetailseite') == true) {
		$('#headerpic').css("display","none");
		$('#headerspacer').css("display","block");
	}
	
	/* Navigation */
	
	$("#navigation > ul > li").each(function() {
		$(this).mouseover(function(){					
			$(this).children("div").css("display","block");	
			$(this).addClass("aktiv");
		});
		$(this).mouseout(function(){					
			$(this).children("div").css("display","none");
			$(this).removeClass("aktiv");
		});
	});
	
	
	$("div#sprachauswahl").hover(
	  function () {
			$(this).children("div#sprachauswahldd").css("display","block");
			$(this).addClass("saaktiv");
	  }, 
	  function () {
			$(this).children("div#sprachauswahldd").css("display","none");
			$(this).removeClass("saaktiv");		
			$("ul.switch").css("display","none");
	  }
	);
	
	/* Content Navigation */
	
	if ($("body").hasClass("welcome")) {
	
		$("#contentnavi > ul > li").each(function() {
			$(this).mouseover(function(){					
				$(this).children("div.subcontentnavi").css("display","block");

				if ($(this).hasClass("scnblau")) {
					$(this).addClass("blauaktiv");
				}
				else if ($(this).hasClass("scnrot")) {
					$(this).addClass("rotaktiv");
				}
				else if ($(this).hasClass("scngruen")) {
					$(this).addClass("gruenaktiv");
				}
				else if ($(this).hasClass("scngelb")) {
					$(this).addClass("gelbaktiv");
				}
				else if ($(this).hasClass("scngrau")) {
					$(this).addClass("grauaktiv");
				}
			});
			$(this).mouseout(function(){					
				$(this).children("div.subcontentnavi").css("display","none");
				
				if ($(this).hasClass("blauaktiv")) {
					$(this).removeClass("blauaktiv");
				}
				else if ($(this).hasClass("rotaktiv")) {
					$(this).removeClass("rotaktiv");
				}
				else if ($(this).hasClass("gruenaktiv")) {
					$(this).removeClass("gruenaktiv");
				}
				else if ($(this).hasClass("gelbaktiv")) {
					$(this).removeClass("gelbaktiv");
				}
				else if ($(this).hasClass("grauaktiv")) {
					$(this).removeClass("grauaktiv");
				}
			});
		});
	
	} else {
	
		$("#contentnavi > ul > li > a").each(function() {
			$(this).click(function(){			
				removeall();
			
				if ( $(this).parent("li").children("div.subcontentnavi").attr("style") == "display: block;" ) {					
					$(this).parent("li").children("div.subcontentnavi").css("display","none");
				}
				else {
					$("#contentnavi > ul > li").children("div.subcontentnavi").css("display","none");										
					$(this).parent("li").children("div.subcontentnavi").css("display","block");	
				
					if ($(this).parent("li").hasClass("scnblau")) {
						$(this).parent("li").addClass("blauaktiv");
					}
					else if ($(this).parent("li").hasClass("scnrot")) {
						$(this).parent("li").addClass("rotaktiv");
					}
					else if ($(this).parent("li").hasClass("scngruen")) {
						$(this).parent("li").addClass("gruenaktiv");
					}
					else if ($(this).parent("li").hasClass("scngelb")) {
						$(this).parent("li").addClass("gelbaktiv");
					}
					else if ($(this).parent("li").hasClass("scngrau")) {
						$(this).parent("li").addClass("grauaktiv");
					}
				}
				return false;
			});
			
			function removeall() {			
				$("#contentnavi > ul > li").removeClass("blauaktiv");
				$("#contentnavi > ul > li").removeClass("rotaktiv");
				$("#contentnavi > ul > li").removeClass("gruenaktiv");
				$("#contentnavi > ul > li").removeClass("gelbaktiv");	
				$("#contentnavi > ul > li").removeClass("grauaktiv");	
			}
			
			$(this).siblings("div.subcontentnavi").hover(function(){
				  //$(this).addClass("hover");
			},function(){
				removeall();
				$(this).parent("li").children("div.subcontentnavi").css("display","none");
			});
			
		});
	
	}

	
	/* Infobox Links*/
	$("div.infobox > h4.iblink").each(function() {
		$(this).css("cursor","pointer");
	
		$(this).toggle(function(){
			$(this).parent("div").children("div.zusatzinfo").css("display","block");
			$(this).addClass("iblinkaktiv");
		},function(){
			$(this).parent("div").children("div.zusatzinfo").css("display","none");
			$(this).removeClass("iblinkaktiv");
		});
	});

	/* Infobox Links*/
	$("div.infobox > div#zi-downloads > div.datenblaetter > a").each(function() {
		$(this).css("cursor","pointer");
	
		$(this).toggle(function(){
			$(this).parent("div").children("div.zusatzinfo").css("display","block");
			$(this).addClass("iblinkaktiv");
		},function(){
			$(this).parent("div").children("div.zusatzinfo").css("display","none");
			$(this).removeClass("iblinkaktiv");
		});
		
	});
	

/* Sprachswitch */
	
	$("#switch-sprache ul").hide();
	
	$("#switch-sprache").click(function(){
		if ($("#switch-sprache ul").is(":visible")) {
			$("#switch-sprache ul").fadeOut("slow");
		}
		else {
			$("#switch-sprache ul").fadeIn("slow");
		}
		
		return false;
	});

	$("#switch-land ul").hide();

	$("#switch-land").click(function(){
		if ($("#switch-land ul").is(":visible")) {
			$("#switch-land ul").fadeOut("slow");
		}
		else {
			$("#switch-land ul").fadeIn("slow");
		}
		
		return false;
	});
	
	$("#switch-sprache ul li").each(function() {
		$(this).click(function(){
			// alert($(this).children("a").attr("class"));
			$("#switch-sprache > li > a").removeClass()
			$("#switch-sprache > li > a").addClass($(this).children("a").attr("class"));
			$("#switch-sprache > li > a").text($(this).children("a").text());			
		});
	});
	
	$("#switch-land ul li").each(function() {
		$(this).click(function(){
			// alert($(this).children("a").attr("class"));
			$("#switch-land > li > a").removeClass()
			$("#switch-land > li > a").addClass($(this).children("a").attr("class"));
			$("#switch-land > li > a").text($(this).children("a").text());			
		});
	});	
	
	/* Contentreiter */
	
	function hideall() {
		$('.cr-innercontent>div').css({ display: "none"});
		$('.cr-unternavi>ul>li').removeClass("aktiv");
		$('.cr-unternavi>ul>li>a').removeClass("aktiv");
		$('.cr-unternavi>ul>li').css({ backgroundColor: ""});
		$('.cr-unternavi>ul>li').css({ backgroundImage: "url(../images/relaunch/thermolut/pfeil-white.gif)"});
	}	
	hideall();	
	
	$('#crun1').css({ display: "block"});	
	$('.crun1').addClass("aktiv");	
	$('.crun1 > a').addClass("aktiv");	
	$('.crun1').css({ backgroundColor: "#dfd3c8"});
	$('.crun1').css({ backgroundImage: "url(../images/relaunch/thermolut/pfeil-brown.gif)"});
	
	$('.cr-unternavi>ul>li').click(function(){		
		hideall();	
		$foo = $(this).attr("class");		
		$('#'+$foo).fadeIn("slow",function(){});		
		$('.'+$foo).addClass("aktiv");
		$('.'+$foo+'>a').addClass("aktiv");
		$('.'+$foo).css({ backgroundColor: "#dfd3c8"});
		$('.'+$foo).css({ backgroundImage: "url(../images/relaunch/thermolut/pfeil-brown.gif)"});
		return false;
	});
	
	$('.cr-unternavi>ul>li').mouseover(function(){
		$foo = $(this).attr("class");
		$('.'+$foo).css({ backgroundColor: "#dfd3c8"});
		$('.'+$foo).css({ backgroundImage: "url(../images/relaunch/thermolut/pfeil-brown.gif)"});
	});
	
	$('.cr-unternavi>ul>li').mouseout(function(){
		$foo = $(this).attr("class");
		$('.'+$foo).css({ backgroundColor: ""});
		$('.'+$foo).css({ backgroundImage: "url(../images/relaunch/thermolut/pfeil-white.gif)"});
	});
	
	/*Routenplanerfunktion*/
	$('#routerechnen').click(function(){
		window.open("http://maps.google.de/maps?saddr="+$('#saddr').attr("value")+"&daddr="+$('#daddr').attr("value"));	
	});
	
	/*Länderauswahl bei der weltkarte*/
	$('#select_laender').change(function(){
		if ($("#select_laender option[@selected]").attr('value') != 0) {
			document.location.href = $("#select_laender option[@selected]").attr('value');
		} else {
			$(this).selectedIndex = 0;
		}
	});
	
	$('#btn_schnelleinstieg').click(function(){
		if ($("#select_schnelleinstieg option[@selected]").attr('value') != 0) {
			document.location.href = $("#select_schnelleinstieg option[@selected]").attr('value');
		} else {
			$(this).selectedIndex = 0;
		}
	});
	
	$('#suche_btn').click(function(){
		$("form#suchform").submit();
	});
	
	/*Händlersuche*/
	$('#haendler_suche').click(function(){	
		document.location.href = "Haendlersuche.html?query="+document.getElementById('haendler_query').value;
	});
	
	$("#subcontentnavi_linie").click(function(){
		if ($(this).parent("li").children("div.subcontentnavi").attr("style") == "display: block;" ) {
			$(this).parent("li").children("div.subcontentnavi").css("display","none");
		}
		else {
			$(this).parent("li").children("div.subcontentnavi").css("display","block");	
		}
	});
	
	
	/*Suche auf der CD*/
	$('#suche_cd').click(function(){	
		document.location.href = "suche.html"; 
	});
});





/*Historie.....noch überarbeiten*/
var linkactiv="";

function hison(var1, showpic) {
	if (linkactiv != "") {
		document.getElementById("link"+linkactiv).style.fontWeight = 'normal';
		document.getElementById("div"+linkactiv).style.visibility = 'hidden';
	}

	document.getElementById("link"+var1).style.fontWeight = 'bold';
	document.getElementById("div"+var1).style.visibility = 'visible';
	if (showpic) {
		document.getElementById("hispic").src = '../images/historie/leftpic_historie'+var1+'.jpg';
	} 

	linkactiv = var1;
}	

function WeltkarteHover(nmode,srcname) {
   if (nmode == 'over') {
      document.getElementById('Weltkarte').src = '../images/kontinente/' + srcname + '.gif';
   } else {
      document.getElementById('Weltkarte').src = '../images/standorte_weltkarte.gif';
   }
}

function LaenderHover(titel, id, mode, src) {
	document.getElementById('current_land_'+id).innerHTML = titel;
	
	if (mode == 'over') {
	   document.getElementById('land_'+id).src = '../images/kontinente/laender/'+ id +'/'+ src +'.gif';
	} else {
	   document.getElementById('land_'+id).src = '../images/kontinente/'+id+'_einzeln.gif';
	}
}

function showAdresse (land, titel, id) {
	last = document.getElementById('last_land_'+id).innerHTML;
	if (last != "") {
		document.getElementById(last+' '+id).style.display = 'none';
	} 
	document.getElementById('land_name_'+id).innerHTML = '';
	
	if (document.getElementById(land+' '+id)) {
		last = land;		
		document.getElementById(land+' '+id).style.display = "";
		document.getElementById('land_name_'+id).innerHTML = titel;		
		document.getElementById('last_land_'+id).innerHTML = last;
	}
}
