var opencat = null;
var stopslide = '';

function opensubcat(id){
	if (opencat != null && document.getElementById("catchild" + opencat) != null){
		document.getElementById("catchild" + opencat).style.display = 'none';
		opencat = null;
	}
	if (document.getElementById("catchild" + id) != null){
		document.getElementById("catchild" + id).style.display = 'block';
		opencat = id;
		window.open(window.location.href + "#cat" + id, "_self");
	}
	
	return false;
}

function changepic(id, src, ahref){
	if (document.getElementById(id) != null)
		document.getElementById(id).src = src;
	if (document.getElementById('link'+id) != null)
		document.getElementById('link'+id).href = ahref.href;
	if (stopslide.indexOf(id) == -1)
		stopslide += id + ';';
}

function slideshow(id, images, index){
	imgarray = images.split(';');
	if (index >= imgarray.length)
		index = 0;

	if (index != 0)
		document.getElementById(id +''+ index).className = '';
	else
		document.getElementById(id +''+ (imgarray.length)).className = '';

	if (stopslide.indexOf(id) != -1)
		return;

	if (document.getElementById(id) != null){
		document.getElementById(id).src = imgarray[index];
	}

	if (document.getElementById('link'+id) != null && document.getElementById(id +''+ (index + 1)) != null){
		document.getElementById('link'+id).href = document.getElementById(id +''+ (index + 1)).href;
		document.getElementById(id +''+ (index + 1)).className = 'found';
	}
	
	setTimeout('slideshow("'+ id +'", "'+ images +'", '+ (index + 1) +')', 5*1000);
	
}

function openPlayer(linkhref){
	if (linkhref == null){
		return true;
	}
	else {
		window.open(linkhref + '&window=1', 'player', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=425,height=500').focus();
		return false;
	}
}

function showhint(id){
	document.getElementById(id).style.display = 'block';
}

function hidehint(id){
	document.getElementById(id).style.display = 'none';
}

function goblink(){
	blinkMe = document.getElementById("blink");
	if (blinkMe != null){
		blinkMe.style.visibility = blinkMe.style.visibility != "visible" ? "visible" : "hidden";
		setTimeout("goblink()", 500);
	}
}

// scroller

// initial position 
var scroll_startpos=20;
var scroll_endpos=-80; 			
var scroll_speed=80;				
var scroll_ID='scroller';
var scroll_currpos = scroll_startpos;

// check for DOM
// stop scroller when window is closed
function endScroll(){ 
	clearInterval(scroll_interval); 
}

function initDOMscroller()
{
	if(!document.getElementById){return;}
	var n=document.getElementById(scroll_ID);
	if(!n){return;}
	scroll_interval = setInterval('scrollDOM()',scroll_speed);
	window.onunload = endScroll;
	n.onmouseover=function()
		{ clearInterval(scroll_interval); }
	n.onmouseout=function()
		{ scroll_interval=setInterval('scrollDOM()',scroll_speed); }
	
}

function scrollDOM()
{
	var n=document.getElementById(scroll_ID).getElementsByTagName('a')[0];
	n.style.marginTop = scroll_currpos+'px';	
	n.style.display = "inline";
	if(scroll_currpos==scroll_endpos) {scroll_currpos=scroll_startpos;}
	scroll_currpos--;
}

function addFav()
{
	url = 'http://' + window.location.hostname + '/?id=' + projectId;
	title = window.document.title;
	if (window.sidebar) { 
		// Mozilla Firefox Bookmark		
		window.sidebar.addPanel(title, url, "");	
	} 
	else if( window.external ) { 
		// IE Favorite		
		window.external.AddFavorite( url, title); 
	}
	else if (window.opera && window.print){
		// Opera
		alert("Please use CTRL + D.");
	}
	else {
		// Mac and other
		alert("Please use CTRL + T, or similar.");
	}
}

function display_overlay()
{
	if (navigator.appName.indexOf("Microsoft")!=-1) 
	{
		toppos = 150;
		leftpos = document.body.clientWidth / 2 - 240;
	}
	else
	{
		toppos = 150;
		leftpos = window.innerWidth / 2 - 240;
	}

	var newdiv = document.createElement('div');
	newdiv.setAttribute('id', "overlay");
	newdiv.style.width = 420;
	newdiv.style.height = 420;
	newdiv.style.position = "absolute";
	newdiv.style.left = leftpos + "px";
	newdiv.style.top = toppos + "px";
	newdiv.style.background = "#FFFFFF";
	newdiv.style.border = "4px solid #CC0000";
	newdiv.style.padding = "6px";
	newdiv.className = "box";
	
	var image = document.createElement('img');
	image.src = "front/img/layer.jpg";
	image.height = 400;
	image.width = 400;

	var link = document.createElement('a');
	link.onclick = function(){document.getElementById("overlay").style.display="none"; return false};
	link.href='#';
	link.appendChild(image);
	link.appendChild(document.createElement('br'));
	link.appendChild(document.createTextNode("Fenster schliessen"));
	link.style.textDecoration = "none";

	newdiv.appendChild(link);
	document.body.appendChild(newdiv);
}