/* NEWS Control --------------------------------------------------------------- */
// Show Next News Information
//showNewsId = 1;
idToShow = 1;
lastid=1;
countOfNews = 10; // Read from Mysql-DB

function checkNewsId(id,countOfNews)
{
	//alert(countOfNews);
	if(id>countOfNews) { id=1; }
	if(document.getElementById('news'+id))
	{
		//alert("existiert"+id);
		return id;
	}
	else
	{
		id++;
		//if(id<13) { alert("hier"+id); }
		checkNewsId(id,countOfNews);
	}
}

function nextNewsInfo () {
	//idToShow = showNewsId+1;
	/*idToHide = showNewsId;
	*/
	idToShow++;
	//if (showNewsId == countOfNews) idToShow = 1;

	idToShow = checkNewsId(idToShow,countOfNews);
	if(idToShow==undefined || !idToShow) { idToShow = 1; }

	//alert(idToShow);
	//idToHide = showNewsId;
	idToHide = idToShow-1;
	if(!document.getElementById('news'+idToHide)) { idToHide=lastid; }
	
	
	if(idToShow!=idToHide)
	{
		new Effect.Appear (
		'news'+idToShow+'', 
		{
			duration:0.5
		}
		);
		new Effect.Fade (
			'news'+idToHide+'', 
			{
				duration:0.1
			}
		);
	}
	lastid=idToShow;
	//document.getElementById('news'+idToHide+'').style.display = "none";
	//document.getElementById('news'+idToShow+'').style.display = "block";
	//showNewsId++;
	//if (showNewsId > countOfNews) showNewsId = 1;
}// nextImg
// Play the News Animation
function playNews () {
	nextNewsInfo();
	setTimeout ("playNews()", 4000);
}


/* SLIDESHOW Control ---------------------------------------------------------- */
// Vars
countOfSlides = 1;
showImgId = 1;
playit = false;
stopit = false;
restartit = false;
dfolder = '';
timoutstarted = false;
timeSpeed = 3000; // Zeitabstand in Milisekunden
// Set Count Of
function setCountOfSlides (pInt) {
	countOfSlides = pInt;
}// setCountOfSlides
// Set Default Folder
function setDefaultFolder (pFolder) {
	dfolder = pFolder;
}// setDefaultFolder
// Show First Image
function firstImg () {
	showStopButton ();
	stop ();
	Effect.Fade ( // Fade
		'slide'+showImgId+'', 
		{
			duration:0,
			fps:50
		}
	);
	Effect.Appear (
		'slide1', 
		{
			duration:0,
			fps:50
		}
	);
	showImgId = 1;
	if (!timoutstarted) setTimeout ('restart (); play ();', timeSpeed);
	timoutstarted = true;
}
function startNext () {
	showPlayButton ();
	stop ();
	nextImgHard ();
}
function startPrev () {
	showPlayButton ();
	stop ();
	preImgHard ();
}
// Show Next Image
function nextImg () {
	idToShow = showImgId+1;
	idToHide = showImgId;
	if (showImgId == countOfSlides) idToShow = 1;
	Effect.Appear (
		'slide'+idToShow+'', 
		{
			duration:1.6,
			fps:50
		}
	);
	Effect.Fade ( // Fade
		'slide'+idToHide+'', 
		{
			duration:1.6,
			fps:50
		}
	);
	showImgId++;
	if (showImgId > countOfSlides) showImgId = 1;	
}// nextImg
// Show Next Image Hard
function nextImgHard () {
	idToShow = showImgId+1;
	idToHide = showImgId;
	if (showImgId == countOfSlides) idToShow = 1;
	document.getElementById('slide'+idToShow).style.display = 'block';
	document.getElementById('slide'+idToHide).style.display = 'none';
	showImgId++;
	if (showImgId > countOfSlides) showImgId = 1;
}// Show Next Image Hard
// Show Previous Image Hard
function preImgHard () {
	idToShow = showImgId-1;
	idToHide = showImgId;
	if (showImgId == 1) idToShow = countOfSlides;
	document.getElementById('slide'+idToShow).style.display = 'block';
	document.getElementById('slide'+idToHide).style.display = 'none';
	showImgId--;
	if (showImgId < 1) showImgId = countOfSlides;
}// Show Prev Image Hard
// Show Previous Image
function preImg (pShow, pHide) {
	if (pShow) idToShow = pShow;
	else idToShow = showImgId-1;
	if (pHide) idToHide = pHide;
	else idToHide = showImgId;
	if (showImgId == 1) idToShow = countOfSlides;
	Effect.Appear (
		'slide'+idToShow+'', 
		{
			duration:0.8,
			fps:50
		}
	);
	Effect.Fade ( // Fade
		'slide'+idToHide+'', 
		{
			duration:0.8,
			fps:50
		}
	);
	showImgId--;
	if (showImgId < 1) showImgId = countOfSlides;
}// preImg
// Play Slideshow
function play () {
	if (!stopit || restartit) {
		showStopButton ();
		timoutstarted = false;
		nextImg ();
		setTimeout ('play();', timeSpeed);
	}
}// play
// Play Slideshow Hard
function playHard () {
	document.getElementById('slide').src = dfolder+'/bild'+showImgId+'.jpg';
	showImgId++;
	if (showImgId > countOfSlides) showImgId = 1;
	setTimeout ('playHard();', 2000);
}// play
// Stop Slideshow
function stop () {
	stopit = true;
	restartit = false;
	playit = false;
}
// Restart Slideshow
function restart () {
	restartit = true;
}
// Show Play/Break Control
function showPlayButton () {
  if(document.getElementById('stop') && document.getElementById('play')) {
    document.getElementById('play').style.display = "inline";
    document.getElementById('stop').style.display = "none";
  }
}
function showStopButton () {
  if(document.getElementById('stop') && document.getElementById('play')) {
    document.getElementById('stop').style.display = "inline";
    document.getElementById('play').style.display = "none";
  }
}


/* Element Controls ----------------------------------------------------------- */


var ie6Minus=false;
 var userAgent = window.navigator.userAgent;

  if (userAgent.indexOf('MSIE 5.0') != -1) 
  {
     // ie6Minus=true;
  }
  if (userAgent.indexOf('MSIE 5.5') != -1) 
  {
     ie6Minus=true;
  }
  if (userAgent.indexOf('MSIE 6.0') != -1) 
  {
    ie6Minus=true;
  }


var actualElement=-1;
var actualMouseOutElement=-1;

	function mouseOutEnd()
        {
           if (actualElement==-1)
           {
              // blende starterbild ein
              var elementx=document.getElementById("startPic");
              elementx.style.display="block";
           } 
        }

function initElements (id) {

        if (ie6Minus)
        {
          var elementx=document.getElementById("element"+id);
          elementx.style.display="none";

	  actualMouseOutElement=id;
          actualElement=-1;
	  setTimeout("mouseOutEnd();",50);
  
       }

        if (!ie6Minus)
        {
	  var el = getElementsByClass("elementPics");
	  for (i=0 ; i<el.length ; i++) el[i].style.display = "none";
	  document.getElementById('element'+id+'').style.display = "none"; //IE 5.5 Hack! Ansonsten wird die Grafik nicht mehr ausgeblendet.
	  document.getElementById('startPic').style.display = "block";
	}

	
}// initElements

function showElementDetails (id) {

        actualElement=id;

	var el = getElementsByClass("elementPics");
	for (i=0 ; i<el.length ; i++) el[i].style.display = "none";
	document.getElementById('startPic').style.display = "none";
	document.getElementById('element'+id+'').style.display = "block";


}// showElementDetails

/*function initElements (id) {
	var el = getElementsByClass("elementPics");
	for (i=0 ; i<el.length ; i++) el[i].style.display = "none";
	document.getElementById('element'+id+'').style.display = "none"; //IE 5.5 Hack! Ansonsten wird die Grafik nicht mehr ausgeblendet.
	document.getElementById('startPic').style.display = "block";
	
	
}// initElements

function showElementDetails (id) {
	var el = getElementsByClass("elementPics");
	for (i=0 ; i<el.length ; i++) el[i].style.display = "none";
	document.getElementById('startPic').style.display = "none";
	document.getElementById('element'+id+'').style.display = "block";
}// showElementDetails
*/

/*
function initElements(id)
{
	document.getElementById('startPic').style.display = "block";
	document.getElementById('element1').style.display = "none";
	document.getElementById('startPic').innerHTML = '<img src="start.jpg" alt="" />';

}

function showElementDetails (id) 
{
	document.getElementById('startPic').innerHTML = '';
	document.getElementById('startPic').style.display = "none";
	document.getElementById('element1').style.display = "block";
	document.getElementById('element1').innerHTML = '<div class="sublayer1" style="padding:0;"><img src="bild'+id+'.jpg" alt="" /></div>';
	
}*/

/* EditMode Functions --------------------------------------------------------- */
function getElementsByClass(searchClass,node,tag) {
  var classElements = new Array();
  if (node == null)
    node = document;
  if (tag == null)
    tag = '*';
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
  for (i = 0, j = 0; i < elsLen; i++) {
    if (pattern.test(els[i].className) ) {
      classElements[j] = els[i];
      j++;
    }
  }
  return classElements;
}
function init (colId) {
	var el = getElementsByClass('sprache'+colId);
	for (i=0 ; i<el.length ; i++) { el[i].style.display = "none"; }
	var el2 = getElementsByClass('active'+colId);
	for (i=0 ; i<el2.length ; i++) { el2[i].className = ""; }
}
function changeLang (idToShow, tabId, colId) {
	init (colId);
	document.getElementById(''+idToShow+'').style.display = "block";
	document.getElementById(''+tabId+'').className = "active"+colId;
}// changeLang

function init2(colId) { 
	var el = new Array();
	var el2 = new Array();
	el[0] = document.getElementById(colId+'_de');
	el[1] = document.getElementById(colId+'_fr');
	el[2] = document.getElementById(colId+'_en');

	el2[0] = document.getElementById(colId+'_tab_de');
	el2[1] = document.getElementById(colId+'_tab_fr');
	el2[2] = document.getElementById(colId+'_tab_en');

	for (i=0 ; i<el.length ; i++) { 
		if(el[i] && el[i].style.display) {
			el[i].style.display = "none"; 
			el2[i].className = ""; 
		}
	}
	
	
}

function changeLang2 (idToShow, tabId, colId) {
	init2(colId);
	document.getElementById(''+idToShow+'').style.display = "block";
	document.getElementById(''+tabId+'').className = "active_1";
}// changeLang

/* Länderlisten-Popup */
function openWindow(filename,params) {
	if(!(params)) {
		params='width=524,height=362'
	}
	window.open(filename,'',params);
}

/* für Playtool-Link (AGB akzeptieren, dann erscheint der Link) */
function showInstallLink() {
	
	if(document.getElementById("agb").checked ==true) {
		document.getElementById("installLink").style.display = "block";
	} else {
		document.getElementById("installLink").style.display = "none";
	}
}
