// AUTOLOAD CODE BLOCK (MAY BE CHANGED OR REMOVED)
Slimbox.scanPage = function() {
	var links = $$("a").filter(function(el) {
		return el.rel && el.rel.test(/^lightbox/i);
	});
	$$(links).slimbox({/* Put custom options here */}, null, function(el) {
		return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
	});
};
window.addEvent("domready", Slimbox.scanPage);

var mailRegex = new RegExp();
mailRegex.compile(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/);

function testEmailFast(mailAddress)
{
	var addIndex = mailAddress.indexOf('@');
	var dotIndex = mailAddress.lastIndexOf('.');
	var minIndexDot = mailAddress.length - 5;
	var maxIndexDot = mailAddress.length - 3;
	return (   (addIndex > 0) && (addIndex < dotIndex)
	        && (dotIndex <= (maxIndexDot)) 
	        && (dotIndex >= (minIndexDot)) );
}

function testEmail(mailAddress)
{
	return mailRegex.test(mailAddress);
}

function colorToRed(node, change)
{
	if(!change)
		node.style.color = "red";
	else
		node.style.color = "";
}

function waitForImage(path, timeout)
{
	var prefetchImage = new Image();
	var stopTime = new Date().getTime() + timeout;
	prefetchImage.src = path;
	while((!prefetchImage .complete) && (new Date().getTime() < stopTime)){}
}

function prefetchImage(path)
{
	waitForImage(path, 50);
}

function changeBackgroundImg(node, to)
{
	waitForImage(to, 350);
	if((Browser.Engine.trident) && (Browser.Engine.version == 4))
	{
	}
	else
	{	
		node.style.backgroundImage = 'url(' + to + ')';
	}
}

function toggleQuestion(id)
{
    var currElement = document.getElementById(id).parentNode.nextSibling;
    if((!currElement.style) || (!currElement.style.display) || (currElement.style.display == "none"))
    {
       currElement.style.display = "block";
    }
    else
    {
       currElement.style.display = "none";
    }
}

function toggleElement(id)
{
    var currElement = document.getElementById(id);
    if((!currElement.style) || (!currElement.style.display) || (currElement.style.display == "none"))
    {
       currElement.style.display = "inline";
    }
    else
    {
       currElement.style.display = "none";
    }
}

function showHtmlObject(target) {
    var currElement = target;
    if ((!currElement.style) || (!currElement.style.display) || (currElement.style.display == "none")) {
        currElement.style.display = "inline";
    }
}

function toggleHtmlObject(target)
{
    var currElement = target;
    if((!currElement.style) || (!currElement.style.display) || (currElement.style.display == "none"))
    {
       currElement.style.display = "inline";
    }
    else
    {
       currElement.style.display = "none";
    }
}

function toggleContent(id, contentA, contentB)
{
   var currElement = document.getElementById(id);
   if(currElement.firstChild.nodeValue != contentB) // Ungleich ist Fehlertoleranter
   {
      currElement.firstChild.nodeValue = contentB; 
   }
   else
   {
      currElement.firstChild.nodeValue = contentA; 
   }
}

function toggleElementAndToggleContent(toggleID, changeID, contentA, contentB)
{
    toggleElement(toggleID);
    toggleContent(changeID, contentA, contentB);
}

var slideShow;

function createNewSlideShow(array, highResArray, delayInSeconds, imageElemId, controlBarId, startButtonId, stopButtonId) 
{
	slideShow = new ImageSlideShow("slideShow", array, highResArray, delayInSeconds, imageElemId, controlBarId, startButtonId, stopButtonId);
	Slimbox.closeCallBack = function(){slideShow.switchInternal(false)};
	registerMouseOver();
	registerMouseOut();

}

function registerMouseOver()
{
	if((slideShow.imageArray.length > 1) && (document.getElementById(slideShow.ctrlId)))
	{
		document.getElementById(slideShow.imgId).onmouseover = showControlBar;
		document.getElementById(slideShow.ctrlId).onmouseover = showControlBar;
	}
}
	
function registerMouseOut()
{
	if((slideShow.imageArray.length > 1) && (document.getElementById(slideShow.ctrlId)))
	{
		//document.getElementById(slideShow.imgId).onmouseout = hideControlBar;
		document.getElementById(slideShow.ctrlId).onmouseout = hideControlBar;
	}
}

function showControlBar()
{
	slideShow.showControlBar();
}

function hideControlBar()
{
	slideShow.hideControlBar();
}

function ImageSlideShow(aName, array, highResArray, delayInSeconds, imageElemId, controlBarId, startButtonId, stopButtonId) 
{

	this.imageArray = new Array();
	this.imageHighResArray = new Array();
	this.name = aName;
	this.currentIndex = 0;
	this.imgId = imageElemId;
	this.ctrlId = controlBarId;
	this.startCtrlId = startButtonId;
	this.stopCtrlId = stopButtonId;
	this.delay = delayInSeconds * 1000;
	this.intervalHandle = false;
	this.stoppedInternal = false;
	this.highResEnabled = false;
	var j=0;
        if(!(document.getElementById(this.imgId))) return;
	//Methods:
	this.getCurrentImage = function()
	{
		return this.imageArray[this.currentIndex];
	}
	
	this.setCurrentImage = function()
	{
		var currImg = this.imageArray[this.currentIndex];
		var img = document.getElementById(this.imgId);
		
		if(img)
		{
			img.src = currImg.src;
			if((isIE6)&&(img.complete))
			{
				img.width  = currImg.width;
				img.height = currImg.height;
				img.style.width  = "" + currImg.width + "px";
				img.style.height = "" + currImg.height+ "px";
			}
		}
	}	
    
	this.nextImage = function()
	{
		this.currentIndex++;
		this.currentIndex = this.currentIndex % this.imageArray.length;
		this.setCurrentImage();
	}
	this.prevImage = function()
	{
		this.currentIndex--;
		this.currentIndex = (this.currentIndex + this.imageArray.length) % this.imageArray.length;
		this.setCurrentImage();
	}

	this.hideStartShowStopButton = function()
	{
		if(document.getElementById(controlBarId))
		{
			document.getElementById(this.startCtrlId).style.display = "none";
			document.getElementById(this.stopCtrlId).style.display = "inline";
		}
	}
	
	this.showStartHideStopButton = function()
	{
		if(document.getElementById(controlBarId))
		{
			document.getElementById(this.startCtrlId).style.display = "inline";
			document.getElementById(this.stopCtrlId).style.display = "none";
		}
	}	
	
	this.stopSlideShow = function()
	{
		window.clearInterval(this.intervalHandle);
		this.intervalHandle = false;
		this.showStartHideStopButton();
		this.stoppedInternal = false; //Wird überschrieben falls nicht
	}

	this.startSlideShow = function()
	{
	    this.nextImage();
		this.intervalHandle = window.setInterval(this.name+".nextImage()", this.delay);
		this.hideStartShowStopButton();
		this.stoppedInternal = false;
	}
	
	this.switchInternal = function(always)
	{
		if(always == true)
		{
			if(this.intervalHandle == false)
			{
				this.startSlideShow();
			}
			else
			{
				this.stopSlideShow();
			}
		}
		else
		{
			if((this.intervalHandle == false) && (this.stoppedInternal == true))
			{
				this.startSlideShow();
			}
			else if(this.intervalHandle != false)
			{
				this.stopSlideShow();
				this.stoppedInternal = true;
			}
		}
	}
	
	this.switchSlideShow = function()
	{
		this.switchInternal(true);
	}
	
	this.showControlBar = function()
	{
		document.getElementById(this.ctrlId).style.display = "block";
	}
	
	this.hideControlBar = function()
	{
	   document.getElementById(this.ctrlId).style.display = "none";
	}
	
	this.showHighRes = function()
	{
		if(this.highResEnabled)
		{
			Slimbox.open(this.imageHighResArray[this.currentIndex].src, "");
			this.switchInternal(false);
		}
	}
	// end of Methods
	
	for(var i = 0; i < array.length; i++)
    {
         if(array[i] != '')
         {
			this.imageArray[j] = new Image();
			this.imageHighResArray[j] = new Image();
			this.imageArray[j].src = array[i];
			this.imageHighResArray[j].src = highResArray[i];
			j++;
         }
    }
	
	if(this.imageArray.length < 2)
	{
		this.stopSlideShow();
		if((this.imageArray[0].src == this.imageHighResArray[0].src) || (this.imageArray.length < 1))
		{
			var img = document.getElementById(this.imgId);
			img.removeAttribute("title");
			img.style.cursor = "auto";
			if(this.imageArray.length < 1)
			{
				img.src = '';
				img.style.visibility = "hidden";
			}
			else
			{
				this.setCurrentImage();
			}
		}
		else
		{
			this.highResEnabled = true;
			this.setCurrentImage();
		}
	}
	else
	{
		this.setCurrentImage();
		this.startSlideShow();
		this.highResEnabled = true;
	}
	

}

function setNewsArray(array, id)
{
	document.getElementById(id).firstChild.nodeValue = array[1];
}

//---------------------------------------------------------------------------------------------------------------------
/*IE Dummy Methoden siehe: ieAdjustments.js */

function ie6_hideElem(obj)
{
	//doNothing :)
}

function ie6_showElem(obj)
{
	//doNothing :)
}
//---------------------------------------------------------------------------------------------------------------------

