function getRandom( min, max ) {
	if( min > max ) {
		return( -1 );
	}
	if( min == max ) {
		return( min );
	}
	var r = parseInt( Math.random() * ( max+1 ) );
	return( r + min <= max ? r + min : r );
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function randomBackground()
{

	var x = readCookie ( "lastRandomImg" );
	var basepath = "/fileadmin/images/backgrounds/";
	var random = getRandom( 1,5 );

	while( x == random) {
		random = getRandom( 1,5 );
	}
	var randomBackgroundFile = basepath +"bg"+random+".jpg";

	createCookie ( "lastRandomImg", random, 5 );
	document.getElementById("contentWrapTd").style.backgroundImage = "url( " + randomBackgroundFile+" )" ;
}

/*  rollover content */
function mouseOverFunc(  element )
{
	element.className = "MouseOver";

}

function mouseOutFunc(  element )
{

	element.className = "MouseOut";

}

var fadeOutTime = 2000;
var fadeInTime = 2000;
var rotateTime = 3000;
var overlapTime = 1000;

function fadeOut ( id )
{
	new Effect.Opacity(id , { from: 0.9, to: 0.1, duration: (fadeOutTime/1000) });
	//currentPic.style.display = "none";
	setTimeout('currentPic = document.getElementById("'+id+'"); currentPic.style.display = "none";', fadeOutTime);
}

function fadeIn ( id )
{
	setTimeout('currentPic = document.getElementById("'+id+'"); currentPic.style.display = "block";', 40);
	new Effect.Opacity(id , { from: 0.01, to: 0.9, duration: (fadeInTime/1000) });
}

/* gallery */
function rotatePics( current, numPics )
{
	fadeIn("changePic"+current);
	setTimeout('fadeOut("changePic'+current+'");', fadeInTime+rotateTime);

	var nextPic = current +1;
	if( nextPic > numPics ){
		nextPic = 1;
	}

	setTimeout('rotatePics( '+nextPic+', '+numPics+' );', fadeOutTime + fadeInTime + rotateTime - overlapTime);
}
