/* STARS */
var HEIGHTCHANGESTEP=1 //pix
var HEIGHTCHANGESPEED = 10 //ms
var actualrotationnewsitem=1;
var starQuenue = new Array ();
var hIncreasing = false;
var hDecreasing = false;
var INCDELAY = 0;
var DECDELAY = 1500;
var xIntDec, xIntInt;
var isIE = (navigator.appName == 'Microsoft Internet Explorer');
/* place -1 to disable */



starQuenue['news_box1'] = 0;

starQuenue['news_box2'] = 0;



function changeNews(srcObj){

    var newsArr = srcObj.parentNode.parentNode.getElementsByTagName('DIV');

    var contId = new String ( srcObj.parentNode.id);

	contId = contId.split('_');

	contId.pop();

	contId = contId.join('_')

    starQuenue[contId] = -1;

    var newsBox = newsArr[0]; 

    var stars = srcObj.parentNode.getElementsByTagName('A');

    for(var i=0; i < stars.length; i++){

        stars[i].className = '';

    }

    newsBox.className = srcObj.rel;

    srcObj.className = 'active';

}





function autoRotateNews(id) {

  var newsBox=document.getElementById(id);

  var tclassName='pos'+actualrotationnewsitem;

  actualrotationnewsitem=actualrotationnewsitem+1; 

  if (actualrotationnewsitem>5)

      actualrotationnewsitem=1;   

  //activate

  newsBox.className = tclassName;  

  window.setTimeout(function(){autoRotateNews(id)}, 3000); 

}



function ParentLink(srcObj){

window.location.href=srcObj.parentNode.href;

}





function StarMover ()

{

	NextStar('news_box2');

	//NextStar('news_box2');

	window.setTimeout(function(){StarMover()}, 3000);

}



function NextStar (obj){

	var cur = starQuenue[obj];
	if (cur > -1 && document.getElementById(obj)){
		var parentDiv = document.getElementById(obj);
		var starDiv = document.getElementById(obj+'_links');
		var hrefs = starDiv.getElementsByTagName('A');
		hrefs[cur].className = '';
		cur++;
		if (cur >= hrefs.length){
			cur = 0;
		}

		hrefs[cur].className = 'active';
		starQuenue[obj] = cur;
		parentDiv.className = 'pos' + (cur+1);
	}
}



function cursorFollow(){

	var canvas=document.getElementById('cursorcanvas');

	var cursorF=document.getElementById('cursorfollow');

	if(canvas && cursorF){

		  dX = 7;

		  dY = 7;

		  imageMap = canvas;

		  imageMap.onmouseover = getCoords;

		  mapWdt = imageMap.offsetWidth - dX;

		  mapHgt = imageMap.offsetHeight - dY;

		  myDot = cursorF;

	}

}



function findPosX(obj) {

  var currleft = 0;

  if (obj.offsetParent)

    while (obj.offsetParent) {

      currleft += obj.offsetLeft

      obj = obj.offsetParent;

    }

  else if (obj.x) currleft += obj.x;

  return currleft;

}



function findPosY(obj) {

  var currtop = 0;

  if (obj.offsetParent)

    while (obj.offsetParent) {

      currtop += obj.offsetTop

      obj = obj.offsetParent;

    }

  else if (obj.y) currtop += obj.y;

  return currtop;

}



function getCoords() {

  imageMapX = findPosX(imageMap);

  imageMapY = findPosY(imageMap);

  imageMap.onmousemove = moveDot;

  imageMap.onmouseover = moveDot;

  imageMap.onmouseout = function (){

    myDot.style.display="none";

    };

}



function moveDot(cursor) {

if(myDot){

	  myDot.style.display="block";

	  if(!cursor) var cursor = window.event;



	  var x = 0;

	  var y = 0;

	  if (cursor.pageX || cursor.pageY) {

	    x = cursor.pageX;

	    y = cursor.pageY;

	  }

	  else if (cursor.clientX || cursor.clientY) {

	    x = cursor.clientX + document.body.scrollLeft;

	    y = cursor.clientY + document.body.scrollTop;

	  }

	  x -= imageMapX;

	  y -= imageMapY;

	  x -= dX;

	  y -= dY;



	  if (x > 0 && y > 0 && x < mapWdt && y  < mapHgt) {

	    myDot.style.left = x+"px";

	    myDot.style.top = y+"px";

	  }

  }

}

var goUp, goDown, messCounter='content_0';

function incHeight(){
	var pobj=document.getElementById('floatpanel');
	if(pobj.offsetHeight < 95 && goUp && !goDown){
		pobj.style.height='' + eval(HEIGHTCHANGESTEP + pobj.offsetHeight) + 'px';
		xInc = setTimeout('incHeight()',HEIGHTCHANGESPEED);
		if(pobj.offsetHeight <= 94){
			messCounter='content_0';
			toggleComment();
		}
	}else{
		goUp=false;
	}
}

function decHeight(){
	var pobj=document.getElementById('floatpanel');
	if(pobj.offsetHeight > 36 && goDown && !goUp){
		pobj.style.height='' + eval(pobj.offsetHeight - HEIGHTCHANGESTEP) + 'px';
		xDec = setTimeout('decHeight()',HEIGHTCHANGESPEED);
		clearLinks();
	}else{
		goDown=false;
	}
}

function toggleComment(commentObj){
	clearLinks();
	if(messCounter){
		commentID=messCounter;messCounter=false;
	}else{
		commentID=commentObj.rel;
		commentObj.parentNode.className='highlighted';
	}
	var commentsArr=document.getElementById('floatpanelcontent').getElementsByTagName('DIV');
	for (var cIdx = 0; cIdx < commentsArr.length; cIdx ++){
		commentsArr[cIdx].className=(commentsArr[cIdx].id == commentID)?'vsbl':'hdn';
	}
}

function clearLinks(){
	var subLinks=document.getElementById('fpanelnav').getElementsByTagName('LI');
	for (var lnIdx = 0; lnIdx < subLinks.length; lnIdx ++){
		subLinks[lnIdx].className='';
	}
}

function floatMenuPanel(){
	if(document.getElementById('floatpanel')){

		var subObjs=document.getElementById('floatpanel').getElementsByTagName('*');
		for(var lIdx = 0; lIdx < subObjs.length; lIdx ++){
			subObjs[lIdx].onmouseover=function(){
				goDown=false;
				if(this.tagName=='A' && this.rel != ''){
					toggleComment(this);
				}
			}
			subObjs[lIdx].onmouseout=function(){
				goDown=true;
			}			
		}
	
		document.getElementById('floatpanel').onmouseover=function(){
			goUp=true; goDown=false;
			setTimeout('incHeight()',INCDELAY);
			//messCounter = 'content_0';
		}
		
		if (isIE) {
			document.getElementById('floatpanel').onmouseleave=function(){
				goDown=true; goUp=false;
				setTimeout('decHeight()',DECDELAY);
			}	
		}else{
			document.getElementById('floatpanel').onmouseout=function(e){
				doDown=true; goUp=false;
				setTimeout('decHeight()',DECDELAY);
			}			
		}
	}
}

function checkCheckBox(){

	if (!document.getElementById('nutzungsbedingungen').checked) {

		alert('Bitte Nutzungsbedingungen akzeptieren.');

		return false;

	}

	return true;

}

var initLaunched=false;

function cInit(){
	if(!initLaunched){
		window.setTimeout(function(){StarMover()}, 1500);
		floatMenuPanel();
		cursorFollow();		
	}
	initLaunched=true;
}

window.onload=cInit;

function _addEvent(obj, evType, fn){
	if (obj.addEventListener) {
	    obj.addEventListener(evType, fn, false);
    	return true;
	}else if (obj.attachEvent) {
		var r = obj.attachEvent('on'+evType, fn);
	    return r;
    }else{
    return false;
  }
}

function cancel(e) {
  if (e && e.preventDefault)
    e.preventDefault(); // DOM style
  return false; // IE style
}