// JavaScript Document
APage = "";
HighQuality = false;
var scrspeed = 450; 
var scrloop = 0;
var scrlooperl = 50;
	
function Authenticate()
{
	$("#LoginMessage").fadeOut(500);	 
	$("#Login").fadeOut(500, function() {
	
		$("#LadenAuthent").fadeIn(200, function() {
			
			$.post("Includes/System/Authentication.php", 
			{ 	
				"AJAX"		: "true", 
				"Name"		: $("input#Name").attr("value"), 
				"Passwort"	: hex_sha1($("input#Passwort").attr("value")) 
			}, 
			function(Ergebnis)
			{	
				$("#LadenAuthent").fadeOut(1000, function() {		
					switch(Ergebnis)
					{
						case "Bestaetigt":
								StartPage();
							break;
						case "Falscher Login":
								LoginErrorMessage("Falscher Benutzername oder falsches Passwort");
							break;
						case "Felder leer":
								LoginErrorMessage("Bitte alle Felder ausfüllen");
							break;
						default:
								LoginErrorMessage("Ein unbekannter Fehler ist aufgetreten.<br />Bitte versuchen Sie es später erneut.");	
							break;
					}
				});
			});
			
		});
	
	});
}

function LoginErrorMessage(Text)
{
	$("#LoginMessage p").html(Text);
	$("#Login").fadeIn(500, function() {
		$("#LoginMessage").fadeIn(500);		
	});
}
function StartPage()
{
	LoadPage('Bewerbung');	
	$("#Page").fadeIn(1500);	
}

$(document).ready(function(){
	highqual("")
	// Register AJAX Events
	$("#Main").ajaxSend(function() {
		top = 0;						 
		$("#Laden").fadeIn(200);	
		scrspeed = 450;
		scrlooperl = 50;
		scrloop	= 0;
	});
	var GeladeneBilder = 0;	// Thumbnails erstellen
	var GeladeneFrames = 0;	// Thumbnails erstellen
	$("#Main").ajaxSuccess(function() {
		$("div.ToolTp label").css("display", "none");
		$("#Main").css("width", "0px");
		$("#Main").css("height", "0px");
		GeladeneBilder = 0;
		GeladeneFrames = 0;
		$("#Main").show(function(){ 										 
			$("div#Steuerung div#Up").css("display", "none");		
			$("div#Steuerung div#Down").css("display", "block");
			if(scrlooperl <= scrloop)
			{
				$("div#Steuerung div#Down").css("display", "none");
			}
			if($("div.Page img.zoom").size() == 0)
				ShowMain();
			else
			$("div.Page img.zoom").each(function() {
				var NewSrc = "Includes/PHPTHUMB/phpThumb.php?src=../../" + $(this).attr("alt") + "&q=100&f=png";
				
				if($(this).attr("width"))
					NewSrc = NewSrc + "&w=" + $("#Main img.zoom").attr("width");	
				
				GeladeneBilder += 1;
				$(this).attr("src", NewSrc).load(function() {
					GeladeneBilder -= 1;
					if(GeladeneBilder == 0)
						ShowMain();
				});						  
			});
		});	
	});	
	function ShowMain()
	{
		$("#Main").hide();
		$("#Main").css("width", "700px");
		$("#Main").css("height", "465px");
		$("#Main").fadeIn('slow', function() { ActivateContentEvents(); });						 
		$("#Laden").fadeOut(200);
		$(".NavItem").each(function() {
			var Str = $(this).attr("onclick") + "ABC";
			if(Str.search(APage) > 0)
				$(this).attr("src", "Style/Scripts/Font/ImageHover.php?Text=" + $(this).attr("id")); 				
		});
	}
	

	
	// Navigation
	// Intro
	 
	// Hover
	$(".NavItem").hover(
	function()
	{
		$(this).attr("src", "Style/Scripts/Font/ImageHover.php?Text=" + $(this).attr("id")); 	
	},
	function()
	{
		var Str = $(this).attr("onclick") + "ABC";
		if(Str.search(APage) <= 0)
			$(this).attr("src", "Style/Scripts/Font/Image.php?Text=" + $(this).attr("id"));		
	});
	
	var top = 0;
	
	// Steuerung Content
	$("div#Steuerung div").click(function() {
		
		switch($(this).attr("id"))
		{
			case 'Up':
				if(top < 0)	
				{
					top += scrspeed;						
					scrloop -= 1;
				}
				break;
			case 'Down':	
				if(scrlooperl > scrloop)
				{
					top -= scrspeed;	
					scrloop += 1;
				}	
				break;
		}
		if(scrloop > 0)	
		{
			$("div#Steuerung div#Up").css("display", "block");
		}	
		if(scrloop <= 0)	
		{
			$("div#Steuerung div#Up").css("display", "none");
		}		
		if(scrlooperl > scrloop)
		{
			$("div#Steuerung div#Down").css("display", "block");
		}	
		if(scrlooperl <= scrloop)
		{
			$("div#Steuerung div#Down").css("display", "none");
		}
		//$("#Main #Content").css("top", top);
		if(top <= 0)
			$("#Main #Content").animate({ 'top': top }, 500);
	});
	

	/*$("div#Steuerung img").hover(
	function()
	{
		$(this).attr("src", "Style/Images/Button_" + $(this).attr("id") + "_I.png"); 
	},
	function()
	{
		$(this).attr("src", "Style/Images/Button_" + $(this).attr("id") + ".png"); 	
	});*/
	$("div#Steuerung").slideDown(1000);		
});
function LoadPage(Page)
{	
	window.location.hash = "#"+Page;
	
	if($("#Page").css("display") == 'none')
		$("#Page").fadeIn(1500);
		
	if(Page != "")
	{
		APage = Page;
		Zufall = Math.round(Math.random()*100000000000000000000000+1);
		$("#Main").fadeOut('normal', function() {
			$("#Main #Content").css("top", 0);
			$("div#Main div#Content").load("Includes/Content/Get.php?rnd=" + Zufall, { page: Page });
			$(".NavItem").each(function() {
				$(this).attr("src", "Style/Scripts/Font/Image.php?Text=" + $(this).attr("id"));
			});
		});
	}
}
haltflare = false;
function StopFlare()
{
	haltflare = true;
	$(".Flare").each(function() {
		$(this).css("display", "none");						  
	});
}
function MoveFlareRnd()
{
	if(!haltflare)
		$(".Flare").each(function() {
			var tTop = Math.round(Math.random()*115) - 105;	
			var Left = Math.round(Math.random()*1000) - 111;	
			var Del = Math.round(Math.random()*5000);
			if(Del < 3000) Del = 3000;
			
			$(this).animate({ "top": tTop, left: Left }, Del, "", function() { if(!haltflare) MoveFlareRnd(); });
		});	
}
function SubmitForm(FormID)
{	
	//$("#Main").fadeOut('normal', function() {
		top = 0;
		$("#Main #Content").css("top", 0);
		var cback = {target: "div#Main div#Content"};
		$("form").ajaxSubmit(cback);
	//});
}
function highqual(Sender)
{
	if(!HighQuality)
	{
		HighQuality = true;
		/*$(Sender).children("img").each(function() {
			$(this).unbind();
			$(this).removeClass();
			$(this).css("cursor", "none");
			$(this).attr("src", "Style/Scripts/Font/ImageHover.php?Text=HQ");										
		});*/
		haltflare = false;
		MoveFlareRnd();
	}
}
function ActivateContentEvents()
{
	$("div.ToolTp").hover(
		function() { $(this).children("label").fadeIn("slow"); },
		function() { $(this).children("label").fadeOut("slow"); });
	
	$("img.zoom").click(function(object) { ImageZoom($(this)); });
}
function ImageZoom(object)
{		
	$("#Page").fadeOut(500, function() { 						 
		$("#LadenImg").fadeIn(200, function() {
			$("div#ImgZoom img").attr("src", $(object).attr("alt")).load(function() {					 
				$("#LadenImg").fadeOut(200, function() {
					$("div#ImgZoom p#AltTag").html($(object).attr("title"));
					$("div#ImgZoom").fadeIn(200);
				});
			});	
		});
	});	
}
function ImageZoomOut()
{
	$("div#ImgZoom").fadeOut(200, function() {
		$("#Page").fadeIn(500);								   
	});
}
