// JavaScript Document
try
{
	Shadowbox.init
	(
		{
			language: 'de-DE',
			players:  ['img', 'html', 'iframe', 'qt', 'wmp', 'swf', 'flv'],
			autoplayMovies: true,
			overlayColor: '#000',
			overlayOpacity: 0.8,
			continuous: true
		}
	);
}catch(e){}

function input_focus()
{
	if(this.name == this.value)
	{
		this.value = "";
	}
}
function input_blur()
{
	if(this.value == "")
	{
		this.value = this.name;
	}
}
function pageStart()
{
	
	//Resizer Hintergrundbild
	try
	{
		get_new_dimension();
		document.getElementById('bg_image').style.display = 'block';
		window.onresize = get_new_dimension;
		ContentObj = new Content('ContentObj');
	}catch(e){}
	//Be A Pirate Video
	try
	{
		hurra_addEvent(document.getElementById('skull'),'click',show_be_a_pirate_video);
		hurra_addEvent(document.getElementById('video_close'),'click',hide_be_a_pirate_video);
	}catch(e){}
	//Sponsor Slider
	try
	{
		var AniElements = hurra_getElementsByTagAndClassName('homepage_sponsor_ani_container', 'div');
		for(var i = 0; i < AniElements.length; i++)
		{
			AniSliderObs[i] = new AniSlider(AniElements[i], i);
			AniSliderObs[i].construct();
		}
		//hurra_addEvent(document.getElementById('change_content'), 'click', show_next_content);
	}catch(e){}	
	// Kontzaktformular
	try
	{
		hurra_addEvent(document.getElementById('contact_name'), 'focus', input_focus);
		hurra_addEvent(document.getElementById('contact_phone'), 'focus', input_focus);
		hurra_addEvent(document.getElementById('contact_email'), 'focus', input_focus);
		hurra_addEvent(document.getElementById('contact_message'), 'focus', input_focus);
		
		hurra_addEvent(document.getElementById('contact_name'), 'blur', input_blur);
		hurra_addEvent(document.getElementById('contact_phone'), 'blur', input_blur);
		hurra_addEvent(document.getElementById('contact_email'), 'blur', input_blur);
		hurra_addEvent(document.getElementById('contact_message'), 'blur', input_blur);
		
		hurra_addEvent(document.getElementById('form_submit'), 'click', send_contact);
		
	}catch(e){}	
	// Kelag Banner
	try
	{
		Set_AC_FL_RunContent_GET('?clickTAG=http%3A%2F%2Fwww.kelag.at%2Fapplikationen%2Fformulare%2Fbanner%2Fpartner%2Fpiraten%2Fclick_banner.html');
		document.getElementById('kelag_banner').innerHTML = AC_FL_RunContent( "codebase","http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0","width","300","height","250","src","http://www.kelag.at/applikationen/formulare/banner/flash/kelag_300x250","quality","high","pluginspage","http://www.macromedia.com/go/getflashplayer","movie","http://www.kelag.at/applikationen/formulare/banner/flash/kelag_300x250", "wmode", "opaque" );
		Set_AC_FL_RunContent_GET('');
	}catch(e){}
}
hurra_registerOnLoad(pageStart);

var beAPirateVideoIsOpen = false;

var bodyHeight;
var bodyWidth;

var videoOriginalHeight = 544;
var videoOriginalWidth = 960;

var imgOriginalHeight = 1200;
var imgOriginalWidth = 1920;

function set_body_height()
{
	bodyHeight = document.body.offsetHeight;
}
function set_body_width()
{
	bodyWidth = document.body.offsetWidth;
}

function get_new_dimension()
{
	set_body_height();
	set_body_width();
	
	if(beAPirateVideoIsOpen === true)
	{
		var Video = document.getElementById('be_a_pirate_video_container');
		
		var newHeight;
		var newWidth;
		
		var diffHeight = videoOriginalHeight - bodyHeight;
		var diffHeightPerCent = diffHeight / (videoOriginalHeight/100);
		
		var diffWidth = videoOriginalWidth - bodyWidth;
		var diffWidthPerCent = diffWidth / (videoOriginalWidth/100);
		
		//Wenn das Bild schmäler aber Höher als die Seite ist
		if(diffWidthPerCent < 0 && diffHeightPerCent >= 0)
		{
			newWidth = bodyWidth;
			newHeight = Math.ceil
			(
				(videoOriginalHeight / 100)
				*
				(100 + (diffWidthPerCent*-1))
			);
		}
		//Wenn das Bild niedriger aber Breiter als die Seite ist
		else if(diffHeightPerCent < 0 && diffWidthPerCent >= 0)
		{
			newHeight = bodyHeight;
			newWidth = Math.ceil
			(
				(videoOriginalWidth / 100)
				*
				(100 + (diffHeightPerCent*-1))
			);
		}
		//Wenn das Bild schmäler und niedriger als die Seite ist
		else if(diffWidthPerCent < 0 && diffHeightPerCent < 0)
		{
			if(diffWidthPerCent < diffHeightPerCent)
			{
				newWidth = bodyWidth;
				newHeight = Math.ceil
				(
					(videoOriginalHeight / 100)
					*
					(100 + (diffWidthPerCent*-1))
				);
			}
			else
			{
				newHeight = bodyHeight;
				newWidth = Math.ceil
				(
					(videoOriginalWidth / 100)
					*
					(100 + (diffHeightPerCent*-1))
				);
			}
		}
		//Wenn das Bild Höher und Breiter als die Seite ist
		else if(diffWidthPerCent > 0 && diffHeightPerCent > 0)
		{
			if(diffWidthPerCent < diffHeightPerCent)
			{
				newWidth = bodyWidth;
				newHeight = Math.ceil
				(
					(videoOriginalHeight / 100)
					*
					(100 - (diffWidthPerCent))
				);
			}
			else
			{
				newHeight = bodyHeight;
				newWidth = Math.ceil
				(
					(videoOriginalWidth / 100)
					*
					(100 - (diffHeightPerCent))
				);
			}
		}
		Video.style.height = newHeight+'px';
		Video.style.marginTop = '-'+Math.ceil(newHeight/2)+'px';
		Video.style.width = newWidth+'px';
		Video.style.marginLeft = '-'+Math.ceil(newWidth/2)+'px';
	}
	else if(beAPirateVideoIsOpen === false)
	{
		var Img = document.getElementById('bg_image');
		
		var newHeight;
		var newWidth;
		
		var diffHeight = imgOriginalHeight - bodyHeight;
		var diffHeightPerCent = diffHeight / (imgOriginalHeight/100);
		
		var diffWidth = imgOriginalWidth - bodyWidth;
		var diffWidthPerCent = diffWidth / (imgOriginalWidth/100);
		
		//Wenn das Bild schmäler aber Höher als die Seite ist
		if(diffWidthPerCent < 0 && diffHeightPerCent >= 0)
		{
			newWidth = bodyWidth;
			newHeight = Math.ceil
			(
				(imgOriginalHeight / 100)
				*
				(100 + (diffWidthPerCent*-1))
			);
		}
		//Wenn das Bild niedriger aber Breiter als die Seite ist
		else if(diffHeightPerCent < 0 && diffWidthPerCent >= 0)
		{
			newHeight = bodyHeight;
			newWidth = Math.ceil
			(
				(imgOriginalWidth / 100)
				*
				(100 + (diffHeightPerCent*-1))
			);
		}
		//Wenn das Bild schmäler und niedriger als die Seite ist
		else if(diffWidthPerCent < 0 && diffHeightPerCent < 0)
		{
			if(diffWidthPerCent < diffHeightPerCent)
			{
				newWidth = bodyWidth;
				newHeight = Math.ceil
				(
					(imgOriginalHeight / 100)
					*
					(100 + (diffWidthPerCent*-1))
				);
			}
			else
			{
				newHeight = bodyHeight;
				newWidth = Math.ceil
				(
					(imgOriginalWidth / 100)
					*
					(100 + (diffHeightPerCent*-1))
				);
			}
		}
		//Wenn das Bild Höher und Breiter als die Seite ist
		else if(diffWidthPerCent > 0 && diffHeightPerCent > 0)
		{
			if(diffWidthPerCent < diffHeightPerCent)
			{
				newWidth = bodyWidth;
				newHeight = Math.ceil
				(
					(imgOriginalHeight / 100)
					*
					(100 - (diffWidthPerCent))
				);
			}
			else
			{
				newHeight = bodyHeight;
				newWidth = Math.ceil
				(
					(imgOriginalWidth / 100)
					*
					(100 - (diffHeightPerCent))
				);
			}
		}
		Img.style.height = newHeight+'px';
		Img.style.marginTop = '-'+Math.ceil(newHeight/2)+'px';
		Img.style.width = newWidth+'px';
		Img.style.marginLeft = '-'+Math.ceil(newWidth/2)+'px';
	}
}

/////
// Sponsor Slider
////
function show_next_AniSlider_content()
{
	var activeIndex = AniSliderObs[0].return_activeIndex();
	if(activeIndex < AniSliderObs[0].numViews-1)
	{
		AniSliderObs[0].show_page(activeIndex+1);
	}
	else
	{
		AniSliderObs[0].show_page(0);
	}
}
function show_last_AniSlider_content()
{
	var activeIndex = AniSliderObs[0].return_activeIndex();
	if(activeIndex > 0)
	{
		AniSliderObs[0].show_page(activeIndex-1);
	}
	else
	{
		AniSliderObs[0].show_page(AniSliderObs[0].numViews-1);
	}
}
var AniSliderObs = new Array();
function AniSlider(objContainer, outerIndex)
{
	this.objContainer = objContainer;
	this.outerIndex = outerIndex;
	this.objSlideContainer;
	this.objSliderLeft = 0;
	this.numViews = 0;
	
	
	this.moveDiffMin = 50;
	this.moveDiffMax = 100;
	this.moveDiff = 0;
	this.moveDiffGrowth = 10;
	
	this.objBttnList = new Array();
	this.elementWidth = 172;
	
	this.targetLeft = 0;
	this.targetLeftStart = 0;
	this.totalWayToGo = 0;
	this.increaseWayMoved = 0;
	this.Interval = false;
	
	this.Timeout = false;
	this.timeoutTime = 5000;
	
	this.construct = function()
	{
		for(var i = 0; i < this.objContainer.childNodes.length; i++)
		{
			if(this.objContainer.childNodes[i].className == 'homepage_sponsor_ani_window')
			{
				for(var z = 0; z < this.objContainer.childNodes[i].childNodes.length; z++)
				{
					if(this.objContainer.childNodes[i].childNodes[z].className == 'hompage_sponsor_ani_slide_container')
					{
						this.objSlideContainer = this.objContainer.childNodes[i].childNodes[z];
						
						for(var t = 0; t < this.objSlideContainer.childNodes.length; t++)
						{
							if(this.objSlideContainer.childNodes[t].className == 'hompage_sponsor_ani_content_container')
							{
								this.numViews ++;
							}
						}
						break;
					}
				}
			}
			if(this.objContainer.childNodes[i].className == 'homepage_sponsor_ani_back')
			{
				hurra_addEvent(this.objContainer.childNodes[i],'click',show_last_AniSlider_content);
			}
			if(this.objContainer.childNodes[i].className == 'homepage_sponsor_ani_next')
			{
				hurra_addEvent(this.objContainer.childNodes[i],'click',show_next_AniSlider_content);
			}
			if(this.Timeout === false)
			{
				this.Timeout = window.setTimeout('show_next_AniSlider_content()',this.timeoutTime);
			}
		}		
	}
	this.show_page = function(number)
	{
		window.clearTimeout(this.Timeout);
		this.Timeout = false;
		
		this.targetLeft = (number*this.elementWidth*-1);
		this.targetLeftStart = this.objSliderLeft;
		this.totalWayToGo = this.targetLeft - this.targetLeftStart;
		if(this.totalWayToGo < 0){this.totalWayToGo = this.totalWayToGo*-1;}
		if(this.Interval === false)
		{
			this.Interval = window.setInterval('AniSliderObs['+this.outerIndex+'].move()',10);
		}
	}
	this.move = function()
	{
		if(this.objSliderLeft != this.targetLeft)
		{
			var wayToGo = this.targetLeft - this.objSliderLeft - 1;
			if(wayToGo < 0){wayToGo = wayToGo * -1;}
			
			if((wayToGo > this.totalWayToGo/2) && (this.moveDiff < this.moveDiffMax))
			{
				var oldMoveDiff = this.moveDiff;
				if(this.moveDiff + this.moveDiffGrowth < this.moveDiffMax)
				{
					this.moveDiff += this.moveDiffGrowth;
				}
				else
				{
					this.moveDiff = this.moveDiffMax;
				}
				if(wayToGo+this.moveDiff > this.totalWayToGo/2)
				{
					this.increaseWayMoved += this.moveDiff;
				}
				else
				{
					this.moveDiff = oldMoveDiffoldMoveDiff;
				}
			}
			if((wayToGo <= this.increaseWayMoved) && (this.moveDiff > this.moveDiffMin))
			{
				if(this.moveDiff - this.moveDiffGrowth > this.moveDiffMin)
				{
					this.moveDiff -= this.moveDiffGrowth;
				}
				else
				{
					this.moveDiff = this.moveDiffMin;
				}
			}
			
			if(this.objSliderLeft < this.targetLeft)
			{
				if(this.targetLeft-this.objSliderLeft <= this.moveDiff)
				{
					this.objSliderLeft = this.targetLeft;
					this.objSlideContainer.style.left = this.objSliderLeft+'px';
					this.stop_move();
				}
				else
				{
					this.objSliderLeft += this.moveDiff;
					this.objSlideContainer.style.left = this.objSliderLeft+'px';
				}
			}
			else if(this.objSliderLeft > this.targetLeft)
			{
				if(this.objSliderLeft-this.targetLeft <= this.moveDiff)
				{
					this.objSliderLeft = this.targetLeft;
					this.objSlideContainer.style.left = this.objSliderLeft+'px';
					this.stop_move();
				}
				else
				{
					this.objSliderLeft -= this.moveDiff;
					this.objSlideContainer.style.left = this.objSliderLeft+'px';
				}
			}
		}
		else
		{
			this.objSlideContainer.style.left = this.objSliderLeft+'px';
			this.stop_move()
		}
	}
	this.stop_move = function()
	{
		window.clearInterval(this.Interval);
		this.Interval = false;
		this.moveDiff = 0;
		this.increaseWayMoved = 0;
		if(this.Timeout === false)
		{
			this.Timeout = window.setTimeout('show_next_AniSlider_content()',this.timeoutTime);
		}
	}
	this.return_activeIndex = function()
	{
		return activeIndex = Math.round((this.objSliderLeft*-1)/this.elementWidth);
	}
}

//Rückgabewert ist ein Array von passenden Elementen
function hurra_getElementsByTagAndClassName(className, tagName)
{
	var FoundElements = new Array();
	var elements = document.getElementsByTagName(tagName.toLowerCase());
	className = className.toLowerCase();
	for (var i = 0; i < elements.length; i++)
	{
		if(className == elements[i].className.toLowerCase())
		{
			FoundElements.push(elements[i]);
		}
	}
	return FoundElements;
}
//Rückgabewert ist ein Array von passenden Elementen
function hurra_getElementsByParentAndClassName(parentObjekt, className)
{
	var FoundElements = new Array();
	for (var i = 0; i < parentObjekt.childNodes.length; i++)
	{
		if(className == parentObjekt.childNodes[i].className)
		{
			FoundElements.push(parentObjekt.childNodes[i]);
		}
	}
	return FoundElements;
}
//--
// Move Content Left
//--
var ContentObj;
function showHide_content()
{
	ContentObj.showHide_content();
}

function Content(objName)
{
	this.objName = objName;
	
	this.contentHtmlObj = document.getElementById('content_left_outer_container');
	
	this.bttnShowHide = document.getElementById('content_left_show_hide');
	this.bttnShowHideOpenSrc = 'pix/hide_content_left.gif';	
	this.bttnShowHideCloseSrc = 'pix/show_content_left.gif';
	this.contentIsMoving = false;
		
	this.interval = false;
	this.contentCurrentLeft = -700;
	this.contentWidth = 700;
	this.intervalSpeed = 10;
	this.moveWidth = 50;
	
	hurra_addEvent(this.bttnShowHide, 'click', showHide_content);
	
	this.showHide_content = function()
	{
		if(this.contentIsMoving === false)
		{
			this.bttnShowHide.style.display = 'none';
			if(this.bttnShowHide.src.indexOf(this.bttnShowHideOpenSrc) == -1)
			{
				this.start_show_content();
			}
			else
			{
				this.start_hide_content();
			}
		}
	}
	this.start_show_content = function()
	{
		this.interval = window.setInterval(this.objName+'.move_content_open()' ,this.intervalSpeed);
		this.contentIsMoving = true;
	}
	this.move_content_open = function()
	{
		if(this.contentCurrentLeft+this.moveWidth < 0)
		{
			this.contentCurrentLeft += this.moveWidth;
			this.contentHtmlObj.style.left = this.contentCurrentLeft+'px';
		}
		else
		{
			window.clearInterval(this.interval);
			this.interval = false;
			
			this.contentCurrentLeft = 0;
			this.contentHtmlObj.style.left = this.contentCurrentLeft+'px';
			
			this.contentIsMoving = false;
			this.bttnShowHide.src = this.bttnShowHideOpenSrc;
			this.bttnShowHide.style.display = 'block';
		}
	}
	this.start_hide_content = function()
	{
		this.interval = window.setInterval(this.objName+'.move_content_close()' ,this.intervalSpeed);
		this.contentIsMoving = true;
	}
	this.move_content_close = function()
	{
		if(this.contentCurrentLeft-this.moveWidth > this.contentWidth*-1)
		{
			this.contentCurrentLeft -= this.moveWidth;
			this.contentHtmlObj.style.left = this.contentCurrentLeft+'px';
		}
		else
		{
			window.clearInterval(this.interval);
			this.interval = false;
			this.contentCurrentLeft = this.contentWidth*-1;
			this.contentHtmlObj.style.left = this.contentCurrentLeft+'px';
			
			this.contentIsMoving = false;
			this.bttnShowHide.src = this.bttnShowHideCloseSrc;
			this.bttnShowHide.style.display = 'block';
		}
	}
}

//Be a pirate video
function show_be_a_pirate_video()
{
	Set_AC_FL_RunContent_GET('');
	document.getElementById('be_a_pirate_video_container').innerHTML = AC_FL_RunContent( "codebase","http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0","width","100%","height","100%","src","flash/VideoGallery","quality","high","pluginspage","http://www.macromedia.com/go/getflashplayer","movie","flash/VideoGallery", "wmode", "transparent" );
	Set_AC_FL_RunContent_GET('');
	document.getElementById('be_a_pirate_video_outer_container').style.display = 'block';
	document.getElementById('scroll_container').style.display = 'none';
	document.getElementById('background_container').style.display = 'none';
	
	beAPirateVideoIsOpen = true;
	get_new_dimension();
}
function hide_be_a_pirate_video()
{
	document.getElementById('scroll_container').style.display = 'block';
	document.getElementById('background_container').style.display = 'block';
	document.getElementById('be_a_pirate_video_outer_container').style.display = 'none';
	document.getElementById('be_a_pirate_video_container').innerHTML = '';
	
	beAPirateVideoIsOpen = false;
	get_new_dimension();
}

function input_focus()
{
	if(this.name == this.value)
	{
		this.value = "";
	}
}
function input_blur()
{
	if(this.value == "")
	{
		this.value = this.name;
	}
}

function send_contact()
{
	var errorReport = '';
	
	postVars = "pass=jockl"
	errorReport = '';
	
	var subject = document.getElementById('contact_subject');
	postVars += "&Betreff="+subject.value;
	
	var name = document.getElementById('contact_name');
	if(!hurra_check_length(name.value, 2) || name.value == name.name)
	{
		errorReport += "Bitte füllen Sie das Feld Name aus!<br />";
	}
	postVars += "&Name="+name.value;

	var email = document.getElementById('contact_email');
	if(!hurra_check_length(email.value, 2) || email.value == email.name)
	{
		errorReport += "Bitte füllen Sie das Feld Email aus!<br />";
	}
	else if(!hurra_check_mail(email.value))
	{
		errorReport += "Bitte füllen Sie das Feld Email korrekt aus!<br />";
	}
	postVars += "&Email="+email.value;
	
	var phone = document.getElementById('contact_phone');
	postVars += "&Telefon="+phone.value;

	var message = document.getElementById('contact_message');
	if(!hurra_check_length(message.value, 2) || message.value == message.name)
	{
		errorReport += "Bitte füllen Sie das Feld Nachricht aus!<br />";
	}
	postVars += "&Nachricht="+message.value;


	if(errorReport.length > 0)
	{
		hurra_alert("Achtung", errorReport, "");
		return false;	
	}
	
	request = new Http(
		"send_mail.php",
		null,
		'POST',
		postVars,
		['Content-Type', 'application/x-www-form-urlencoded']
	);
	request.onreadyst = function()
	{
		if (requestQue.List[0].req.readyState == 4)
		{
			if (requestQue.List[0].req.status == 200)
			{
				document.getElementById('contact_name').value = document.getElementById('contact_name').name;
				document.getElementById('contact_email').value = document.getElementById('contact_email').name;
				document.getElementById('contact_phone').value = document.getElementById('contact_phone').name;
				document.getElementById('contact_message').value = document.getElementById('contact_message').name;
				hurra_alert("Vielen Dank für Ihre Anfrage!", "Wir werden uns gerne um Ihr Anliegen kümmern.", "");
				requestQue.requExecuted();
			}
			else
			{
				requestQue.requExecuted();
			}
		}
	}
	requestQue.add(request);
}
