$(document).ready(function(){
	// Ueberschriften mit "groesser als" Zeichen
	//$("h1").prepend("&gt;&gt;&nbsp;");
	//$("h2").prepend("&gt;&gt;&nbsp;");
	
	if ($.browser.msie && $.browser.version=="6.0") {
		// IE6: Einblenden der Subnav, da kein li:hover unterstuetzt wird
		$("div#nav-main ul li").hover(
			function () {
				$(this).addClass("jqaktiv");
				$(this).children("ul").addClass("subnavaktiv");
			},
			function () {
				$(this).removeClass("jqaktiv");
				$(this).children("ul").removeClass("subnavaktiv");
			}
		);
	}
		
	// Mouseover Firmenbereiche Startseite
	$("ul#firmenbereiche li").hover(
		function () {
			$(this).children("span.bereich-details").toggleClass("bereich-aktiv");
			showBuilding($(this).children("a").attr("rel"));
		},
		function () {
			$(this).children("span.bereich-details").toggleClass("bereich-aktiv");
			showBuilding('simon-luftbild');
		}
	);
	
	// Bildvergroesserung
	if ($("ul.bildliste-rahmen a").length || $(".resize a").length) {
		$('ul.bildliste-rahmen a, .resize a').zoomimage({
			//beforeZoomIn: img_clear,
			controls: false,
			hideSource: false,
			caption : false,
			border: 1
		});
	}
	
	// Automatischer Bildwechsel im Header
	if ($("#bilderstapel").length > 0) {
		setInterval( "daumenKino()", 4500 );
	}
	
	// Seite oeffnen in Sitemap
	$('body.Sitemap ul#firmenbereiche a').click (
		function() {
			var url = $(this).attr('href');
			opener.parent.location.href = url;
			window.close();
			return false;
		}
	);
	
});


// E-Mail Adressen
function getMail (key, id) {
	var mail;
	var adresse = "";
	var ausgabe = "";
	
	mail = (uncryptMail(key)).split(':');
	
	if (mail[1]) {
		adresse = mail[1].replace('@','&#064;');
		ausgabe = '<a href="javascript:link_uncryptMail(\'' + key + '\');">' + adresse + '<\/a>';
		
		$("#"+id).replaceWith(ausgabe);
	}
}

function uncryptMail( s ) {
	var n = 0;
	var r = "";
	for( var i = 0; i < s.length; i++) {
		n = s.charCodeAt( i );
		if( n >= 8364 ) {
			n = 128;
		}
		r += String.fromCharCode( n - 1 );
	}
	return r;
}

function link_uncryptMail( s ) {
	location.href=uncryptMail( s );
}


// Startseite
function showBuilding (company) {
	// Generiert das neue Bild ...
	var newimg = document.createElement("img");
	newimg.src = '../media/images/home/' + company + '.jpg';
	//var geladen = 0;
		
	// .. und tauscht es nach dem Laden aus
	//$(newimg).load(function() {
		$('#luftbild').html(newimg);
	//});
}


// Schliesst zoomimage Bilder
function img_clear () {
	$(".resize a").zoomimageClear();
}


// Automatischer Bildwechsel

function daumenKino() {
  var $alt = $('#bilderstapel IMG.obersteebene');

  if($alt.next().length)
    var $neu = $alt.next();
  else
    var $neu = $('#bilderstapel IMG:first');

  $alt.addClass('mittlereebene');
  $alt.removeClass('obersteebene');
  $neu.css({opacity: 0.0});
  $neu.addClass('obersteebene');

  $neu.animate({opacity: 1.0}, 1500, function() {
    $alt.removeClass('mittlereebene');
  });
}


// Anzeige von Flash Dateien
function ReWriteFlashExtended (id, url, width, height, version) {
	version = (version=='')?4:version;
	var flash = "";
	if (document.getElementById) {	
		if (document.getElementById(id)) {	
			flash += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + version + ',0,2,0" width=' + width + ' height=' + height + '">';
			flash += '<param name="movie" value=' + url + '>';
			flash += '<embed src="' + url + '" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"></embed>';
			flash += '</object>';
			document.getElementById(id).innerHTML = flash;
		}
	}
}


// Druckfunktion
function drucken(langdir) {
	var page = window.location.href;
	var dirzusatz = '';
	if(langdir=='ru') dirzusatz = '/ru/sitek';
	var mypath = "http://www.simon.de"+dirzusatz+"/drucken.php?ld="+langdir+"&page="+page;
	Fenster = window.open(mypath, "", "width=700, height=700, top=10, left=10, scrollbars=1, resizable=1");
	if (Fenster){
		Fenster.moveTo(screen.width/2-(700/2),screen.height/2-(700/2));
		Fenster.focus();
  	}
}


// Sitemap und Impressum in neuem Fenster
function popup (url,name,breite,hoehe,x,y){
 	var MyWindow =0;
 	MyWindow = window.open(url,name,'toolbar=0,location=0,directories=0,statusbar=0,menubar=0,scrollbars=1,resizable=yes,width='+breite+',height='+hoehe);
 	if (MyWindow){
		MyWindow.moveTo(screen.width/2-(breite/2+x),screen.height/2-(hoehe/2+y));
		MyWindow.focus();
  	}
}


// Mini-Galerie (Bsp: Sinter)
function setgalerie(img) {
	var bild = img;	
	$("div#galerie-gross").children("img").attr("src", bild);
}


// Pop-Up
function newWin(which, breite, hoehe){
 var NewWindow =0;
  NewWindow = window.open(which,"new",'width='+breite+',height='+hoehe+',toolbar=0,menubar=0,directories=0,statusbar=0,location=0,resizable=no,scrollbars=no'); 
   if (NewWindow){
    NewWindow.moveTo(screen.width/2-(breite/2),screen.height/2-(hoehe/2));
    NewWindow.focus();
  }
}

// Mouseover Texte Fertigungsprozess

var aktiv = "";

function showdetails (text) {
	if (document.getElementById(text)) {
		document.getElementById(text).style.display = 'block';
	}	
	aktiv = text;
}

function hidedetails () {
	if (document.getElementById(aktiv)) {
		document.getElementById(aktiv).style.display = 'none';
	}
}

// Geschaeftsfelder Sinter / Galvano

var active_index = 0;

function setIcon (index, top, left, extraicons, schaubild) {
	// Wechselt das Schaubild, falls erforderlich
	setBlueprint (schaubild);
	
	// Blendet gelben Punkt ein, wenn Koordinaten durchgegeben werden
	if (top > 0) {
		$('img#leuchtpunkt').css('margin-top', top);
		$('img#leuchtpunkt').css('margin-left', left);
		$('img#leuchtpunkt').show();
	}
	// Zusatz-Icons
	if (extraicons == 'haushalt-1')	{
		$('img#leuchtpunkt').after('<img id="leuchtpunkt-zusatz" src="../../media/images/sinter/leuchtpunkt-haushalt-1.gif" alt="Highlight" />');
		$('img#leuchtpunkt-zusatz').css('margin-top', top);
		$('img#leuchtpunkt-zusatz').css('margin-left', left-20);
	}
}

function hideIcon (index) {
	// Blendet den gelben Punkt aus, wenn nichts aktiv ist
	if (active_index != index) {
		$('img#leuchtpunkt').hide();
		$('img#leuchtpunkt-zusatz').hide();
	}	
}

function setContent (index, schaubild) {
	hideContent (index);
	
	// Wechselt das Schaubild, falls erforderlich
	setBlueprint (schaubild);
	
	// Blendet die Zusatz-Inhalte ein
	$('div#geschaeftsfelder-details').show();
	$(('p#text-' + index)).show();
	$(('p#bild-' + index)).show();
	
	// Setzt die "active" Variable und aktiv Klassen
	$(('li#link-' + index)).addClass('aktiv');
	$(('li#picto-' + index)).addClass('aktiv');
	active_index = index;
}

function hideContent (index, schaubild) {
	// Wechselt das Schaubild, falls erforderlich
	setBlueprint (schaubild);
	
	// Blendet die Zusatz-Inhalte aus	
	$('div#geschaeftsfelder-details').hide();
	$(('p#text-' + active_index)).hide();
	$(('p#bild-' + active_index)).hide();
	
	// Entfernt die "active" Variable und aktiv Klassen
	$(('li#link-' + active_index)).removeClass('aktiv');
	$(('li#picto-' + active_index)).removeClass('aktiv');
}

// Wechselt das Schaubild, falls erforderlich
function setBlueprint (schaubild) {
	if (schaubild != "") {
		if (document.getElementById('blaupause')) {
			document.getElementById('blaupause').src = "../../media/images/sinter/" + schaubild;
		}
	}
}

