$(document).ready( function() {

	$("a[rel='navigation'][class!='aNavigation']").css("font-weight","normal");
	
	// AJAX PAGE LOAD
	ajaxPageLoad_first();
	
	// --IMG ohne alt Text fuellen
	$("img[alt='']").attr('alt','eam');
	
	// --BLANK DIV CORRECTION
	var wWin = $(window).width();
	if(wWin<1007) {
		wWin=1007;
	}
	$('#content').width(wWin-277);
	
	// --SLIDEMENU EBENE 1
	$('ul#navigationInner > li > a').click( function() {
		$(this).next('ul').show().animate({height:'150px'}, 700);
	});

	// --SLIDEMENU EBENE 2
	$('ul.navigation > li > a').click( function() {
		$('ul.navigationSub > li > a').css('font-weight','normal');
		if($.browser.msie) {
			$('ul.navigationSub:visible').animate({height:'1px'}, 700).hide();
			$(this).parent().next('ul').show().animate({height:'58px'}, 700);
		} else {
			$('ul.navigationSub:visible').animate({height:'1px'}, 700).hide();
			$(this).parent().next('ul').show().animate({height:'58px'}, 700);
		}
		$('ul.navigation > li > a').css('font-weight','normal');
		$(this).css('font-weight','bold');
	});

	// --SLIDEMENU EBENE 3
	$('ul.navigationSub > li > a').click(function() {
		$('ul.navigationSub > li > a').css('font-weight','normal');
		$(this).css('font-weight','bold');
	});

	// --LIGHTBOX
	$("a.lightbox").lightBox();

	// --FIRST COME FIRST OPEN
	$("ul.navigation:eq(0)").show().animate({height:'150px'}, 700);

	// if hash => goto link
	if(window.location.hash.length>2) {
		var goto = window.location.hash;
		goto = goto.substr(1);
		$("#navigation a[title*='"+goto+"']").trigger("click");
	}
});

// --AJAX PAGE LOAD FIRST
function ajaxPageLoad_first() {

	// --BLANK DIV CORRECTION
	var wWin = $(window).width();
	if(wWin<1007) {
		wWin=1007;
	}
	$('#content').width(wWin-277);
	if($(".innerfade").size()>0) {
				var eq = Math.floor(Math.random()*1.99);
				$(".innerfade a:eq("+eq+")").hide();
	}
	$("a[title*='/eam'], div.iWindow, div.newsShot, a[title='/_index.php'][href*='#']").click(function() {

		var url = $(this).attr('title');

		if(url.indexOf('/eam/')==0 || url.indexOf('/eamSystems/')==0 || url.indexOf('/_index.php')==0 || url.indexOf('/eamJobs')==0) {
			$("#navigation").animate({backgroundColor:"#FFCC00"}, 750);
		}
		if(url.indexOf('/eamControls/')==0) {
			$("#navigation").animate({backgroundColor:"#FF8800"}, 750);
		}
		if(url.indexOf('/_index.php')==0) {
			$('ul.navigation:visible').animate({height:'1px'}, 700);
			$('ul.navigationSub:visible').animate({height:'1px'}, 700);
		}

		if(url.indexOf('/eamControls/controls_kontakt.php')==0) {
			unboldNavigation();
			$('ul.navigation:visible').animate({height:'1px'}, 700);
			$('ul.navigationSub:visible').animate({height:'1px'}, 700).hide();
			$('ul.navigation:eq(3)').show().animate({height:'150px'}, 700);
		}
		if(url.indexOf('/eamSystems/kontakt.php')==0) {
			unboldNavigation();
			$('ul.navigation:visible').animate({height:'1px'}, 700);
			$('ul.navigationSub:visible').animate({height:'1px'}, 700).hide();
			$('ul.navigation:eq(2)').show().animate({height:'150px'}, 700);
		}
		if(url.indexOf('/eamJobs/eamjobs.php')==0 || url.indexOf('/eamJobs/recruiting.php')==0) {
			unboldNavigation();
			$('ul.navigation:visible').animate({height:'1px'}, 700);
			$('ul.navigationSub:visible').animate({height:'1px'}, 700).hide();
			$('ul.navigation:eq(1)').show().animate({height:'150px'}, 700);
		}

		if($(this).hasClass('iWindow')) {
			$('ul.navigation:eq(0)').show().animate({height:'150px'}, 700);
			$('ul.navigationSub:eq(1)').show().animate({height:'58px'}, 700);
			var select = $(this).attr('title');
		}

		if(url=='/_index.php') {
			$("a[rel='navigation'][class!='aNavigation']").css("font-weight","normal");
		}

		var rev = $(this).attr("rev");
		$('#content').html("<img src='/_include/css/img/ajax-loader.gif' />");
		pageTracker._trackPageview(url);

		$('#load').load(url, {data:rev}, function() {
			window.location.hash = url;
			if($(".innerfade").size()>0) {
				var eq = Math.floor(Math.random()*1.99);
				$(".innerfade a:eq("+eq+")").hide();
			}
			$('#jScroll').jScrollPane({showArrows:false, scrollbarWidth:9});
			var wWin = $(window).width();
			$('#content').width(wWin-277);
			$("a[href$='jpg'],a[href$='jpeg'],a[href$='gif'],[href$='png']").lightBox();
			if(url=='/_index.php') {$("a[rel='navigation'][class!='aNavigation']").css("font-weight","normal");}
			ajaxPageLoad();
			$("a[title='"+url+"']").each(function() {$(this).css('font-weight','bold');});
		});
	});
}

// --AJAX PAGE LOAD
function ajaxPageLoad() {
		$('#printIt').show().click(function() {printPage();});

			// --BLANK DIV CORRECTION
			var wWin = $(window).width();
			if(wWin<1007) {
				wWin=1007;
			}
			$('#content').width(wWin-277);

	$("a[rel!='navigation'][title!='/'][target!='_blank'][class!='lightbox'][href*='#'], div.iWindow, div.newsShot,a[href*='/eamJobs/']").click(function() {
		hrefCheck = $(this).attr('href');
		if(hrefCheck.indexOf('/eamJobs/')==0) {
			var url = $(this).attr('href');
			unboldNavigation();
		} else {
			var url = $(this).attr('title');
		}
		var ifText = $(this).text();
		window.location.hash = url;
		$('#content').width(wWin-277);
		if(url.indexOf('/eam/')==0 || url.indexOf('/eamSystems/')==0 || url.indexOf('/_index.php')==0 || url.indexOf('/eamJobs/')==0) {
			$("#navigation").animate({backgroundColor:"#FFCC00"}, 750);
		}
		if(url.indexOf('/eamControls/')==0) {
			$("#navigation").animate({backgroundColor:"#FF8800"}, 750);
		}
		if(url.indexOf('/_index.php')==0) {
			$('ul.navigationSub:visible').animate({height:'1px'}, 700);
		}
		if(url.indexOf('/eamControls/controls_kontakt.php')==0 || ifText=='EAM Control') {
			unboldNavigation();
			$('ul:visible').animate({height:'1px'}, 700);
			$('ul.navigationSub:visible').animate({height:'1px'}, 700);
			$('ul.navigation:eq(3)').show().animate({height:'150px'}, 700);
		}
		if(url.indexOf('/eamSystems/kontakt.php')==0 || ifText=='EAM Systems') {
			unboldNavigation();
			$('ul:visible').animate({height:'1px'}, 700);
			$('ul.navigationSub:visible').animate({height:'1px'}, 700);
			$('ul.navigation:eq(2)').show().animate({height:'150px'}, 700);
		}
		if(url.indexOf('/eamJobs/eamjobs.php')==0 || ifText=='eam Jobs') {
			unboldNavigation();
			$('ul:visible').animate({height:'1px'}, 700);
			$('ul.navigationSub:visible').animate({height:'1px'}, 700);
			$('ul.navigation:eq(1)').show().animate({height:'150px5px'}, 700);
		}

		if($(this).hasClass('iWindow')) {
			$('ul.navigation:eq(0)').show().animate({height:'135px'}, 700);
			$('ul.navigationSub:eq(1)').show().animate({height:'58px'}, 700);
		}
		$("a[title='"+url+"']").css('font-weight','bold');
		if(url=='/_index.php') {
			unboldNavigation();
			$('ul:visible').animate({height:'1px'}, 700);
			$('ul.navigationSub:visible').animate({height:'1px'}, 700);
			$('ul.navigation:eq(0)').show().animate({height:'150px'}, 700);
		}
		
		$("a[title='"+url+"']").each(function() {$(this).css('font-weight','bold');});
		
		$('#content').html("<img src='/_include/css/img/ajax-loader.gif' id='ajaxLoader' />");
		pageTracker._trackPageview(url);
		$('#load').load(url, 0, function() {
			$('#printIt').show().click(function() {printPage();});
			$('#jScroll').jScrollPane({showArrows:false, scrollbarWidth:9});
			var wWin = $(window).width();
			$('#content').width(wWin-277);
			$("a.lightbox").lightBox();
			$("a[href$='jpg'],a[href$='jpeg'],a[href$='gif'],[href$='png']").lightBox();
			ajaxPageLoad();
			// --BLANK DIV CORRECTION
			var wWin = $(window).width();
			if(wWin<1007) {
				wWin=1007;
			}
			$('#content').width(wWin-277);
		});
		if(hrefCheck.indexOf('/eamJobs/')==0) {return false;}
	});
}

// --UNBOLD NAVIGATION
function unboldNavigation() {
	$("a[rel='navigation'][class!='aNavigation']").css("font-weight","normal");
}

// --PRINT FUNCTION
function printPage() {
	var generator=window.open('','name','height=600,width=800,scrollbars=yes');
	var htmlInner = $('#contentInner').find('iframe').remove().end().html();
	//$.htmlInner.find('iframe').remove().end;
	generator.document.write('<html><head><title>Printversion</title>');
	generator.document.write('<link href="/_include/css/reset.css" type="text/css" rel="stylesheet"></link>');
	generator.document.write('<link href="/_include/css/print.css" type="text/css" rel="stylesheet"></link>');
	generator.document.write('</head><body>');
	generator.document.write('<a href="javascript:" onclick="window.print()"><img src="/_include/css/img/print.gif" /></a>');
	generator.document.write(htmlInner);
	generator.document.write('<img alt="EAM Logo" src="/_include/css/img/eam.gif" />');
	generator.document.write('<div class="footer">'+$('#kontaktSystems').html()+'');
	generator.document.write('<div class="footer">'+$('#kontaktControls').html()+'');
	generator.document.write('</body></html>');
	generator.document.close();
	generator.print();
}

// --BLANK DIV CORRECTION
$(window).resize(function(){
	var wWin = $(window).width();
	if(wWin<1007) {
		wWin=1007;
	}
	$('#content').width(wWin-277);
});

// --KONTAKTFORMULAR
function contact(form, url) {
	var formData = $(form).serialize();
	$('#flashContent').load(url, ({data: formData}));
}
