//<![CDATA[
var ns = (document.layers) ? true : false;
var ie = (document.all) ? true : false;
var mz = (document.getElementById && (window.innerWidth > 0)) ? true : false; //Mozilla/Opera//Netscape6
if (mz) {ie = false;}

/* Event Registrar, Simon Willison */
 function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}


var element;
function get_element_byID(id) {
	// nur ie4 und ns4 verstehen kein getElementById()
	//if(ie) {
	//	temp_element = document.all.id;
	//} else {
		temp_element = document.getElementById(id);
	//}
}
var preloaded_images = new Array();
function preload_image(src) {
	preloaded_images[src] = new Image();
	preloaded_images[src].src = src;
}
function sybo_toggle_vis(id, smooth, direction) {
	get_element_byID(id);
	element = temp_element;
	if(direction != 'hide' && typeof(direction) != 'undefined') {
		direction = 'show';
	}
	if(element == null) return
	if((typeof(element) != 'undefined' 
		&& (element.style.display == 'inline' || element.style.display == 'block') 
			&& direction != 'show') 
		|| direction == 'hide') {
		if(smooth == true) {
			for (var i=0;i<11;i++) {
				j = 10-i;
				setTimeout('setOpacity('+j+',"'+id+'")',100*i);
			}
			setTimeout(function() { element.style.display = 'none';}, 1000);
		} else {
			element.style.display = 'none';
		}
	} else {
		if(smooth == true) {
			setOpacity(0,id);
		}
		element.style.display = 'inline';
		if(smooth == true) {
			for (var i=0;i<11;i++) {
				setTimeout('setOpacity('+i+',"'+id+'")',100*i);
			}
		}
	}
}
/*function sybo_toggle_vis(id, id2, id3) {
	get_element_byID(id);
	element = temp_element;
	
	if(element.style.display == 'inline') {
		element.style.display = 'none';
	} else {
		element.style.display = 'inline';
	}
}*/

function setOpacity(value, id) {
	get_element_byID(id);
	element = temp_element;
	element.style.opacity = value/10;
	if(value == 0) {
		value = 0.1;
	}
	element.style.filter = 'Alpha(opacity=' + value*10 + ')';
	//element.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+ value*10 + ");";

}
function sybo_toggle_vis_by_height(id, time, finalheight) {
	get_element_byID(id);
	element = temp_element;

	startTime = new Date();
	startTime = startTime.getTime();
	if(finalheight == false || !finalheight) {
		finalheight = parseInt(element.scrollHeight);
	}
	height = parseInt(element.offsetHeight);
	// alert(height+', '+finalheight);
	if(finalheight == height) {
		sybo_change_height_smooth(id, height, 0, time);
	} else {
		sybo_change_height_smooth(id, height, finalheight, startTime, time);
	}
}
function sybo_change_height_smooth(id, height, finalheight, startTime, time) {
	get_element_byID(id);
	element = temp_element;
	
	k = 0.0001;
	
	currentTime = new Date();
	timeSpent = currentTime.getTime() - startTime;
	
	if(finalheight > 0) {
		if(height < finalheight) {
			if(height < (finalheight - 5)) {
				height = height + Math.ceil(0.3*(finalheight-height));
				//factor = 1/(1+Math.pow(Math.E, (-k*time*timeSpent)*(time/1-1)));
				//factor = 10 - 10*Math.pow(Math.E, (-k*timeSpent));
				//height = factor* finalheight;
				//height = Math.ceil(height);
			} else {
				height = finalheight;
			}
			element.style.height = height+'px';
		
			element.style.marginBottom = -height+'px';
			
			if(height < finalheight) {
				setTimeout("sybo_change_height_smooth('"+id+"', "+height+", "+finalheight+", "+startTime+", "+time+")", 50);
			}
		}
	} else {
		if(height > finalheight) {
			if(height > 5) {
				height = height + Math.ceil(0.3*(finalheight-height));
			} else {
				height = 0;
			}
			
			
			element.style.height = height+'px';
			element.style.marginBottom = -height+'px';
			
			if(height > finalheight) {
				setTimeout("sybo_change_height_smooth('"+id+"', "+height+", "+finalheight+", "+startTime+", "+time+")", 10);
			}
		}
	}
}

function sybo_toggle_css_vis(classname, direction) {
	var stylesheets;
	if(ie) {
		stylesheets = 'rules';
	} else {
		stylesheets = 'cssRules';
	}
	
	for(var i = 0; i < document.styleSheets.length; i++) {
		for(var j = 0; j < document.styleSheets[i][stylesheets].length; j++) {
			if(document.styleSheets[i][stylesheets][j].selectorText == classname) {
				element = document.styleSheets[i][stylesheets][j];
				if(direction == 'show') {
					element.style['display'] = 'block';
				} else if(direction == 'hide') {
					element.style['display'] = 'none';
				} else {
					if(element.style['display'] == 'block') {
						element.style['display'] = 'none';
					} else {
						element.style['display'] = 'block';
					}
				}
			}
		}
	}
}

function sybo_admin_options() {
	this.mode = 'mixed';
	if(getCookie('syboAdminUIMode') != null) {
		this.mode = getCookie('syboAdminUIMode');
	}
	// methods
	this.change_mode = function(mode) {
		this.mode = mode;
		switch(mode) {
			case 'structure': 
				sybo_toggle_css_vis('.sybo_admin_box', 'show');
				sybo_toggle_css_vis('.sybo_admin_comp_content', 'hide');
				sybo_toggle_css_vis('.sybo_admin_comp_details', 'hide');
				sybo_toggle_css_vis('.sybo_outer_admin_box', 'show');
				sybo_toggle_css_vis('.admin_links', 'show');
				sybo_toggle_css_vis('.admin_button', 'show');
				setCookie('syboAdminUIMode', 'structure');
				break;
			case 'mixed':
				sybo_toggle_css_vis('.sybo_admin_box', 'show');
				sybo_toggle_css_vis('.sybo_admin_comp_content', 'show');
				sybo_toggle_css_vis('.sybo_admin_comp_details', 'hide');
				sybo_toggle_css_vis('.sybo_outer_admin_box', 'show');
				sybo_toggle_css_vis('.admin_links', 'show');
				sybo_toggle_css_vis('.admin_button', 'show');
				sybo_toggle_vis('sybo_panel_contact', 'hide');
				setCookie('syboAdminUIMode', 'mixed');
				break;
			case 'hidden_structure':
				sybo_toggle_css_vis('.sybo_admin_box', 'show');
				sybo_toggle_css_vis('.sybo_admin_comp_content', 'show');
				sybo_toggle_css_vis('.sybo_admin_comp_details', 'hide');
				sybo_toggle_css_vis('.sybo_outer_admin_box', 'hide');
				sybo_toggle_css_vis('.admin_links', 'show');
				sybo_toggle_css_vis('.admin_button', 'show');
				sybo_toggle_vis('sybo_panel_contact', 'hide');
				setCookie('syboAdminUIMode', 'hidden_structure');
				break;
			case 'content':
				sybo_toggle_css_vis('.sybo_admin_box', 'hide');
				sybo_toggle_css_vis('.sybo_admin_comp_content', 'show');
				sybo_toggle_css_vis('.sybo_outer_admin_box', 'hide');
				sybo_toggle_css_vis('.sybo_admin_comp_details', 'hide');
				sybo_toggle_css_vis('.admin_links', 'hide');
				sybo_toggle_css_vis('.admin_button', 'hide');
				sybo_toggle_vis('sybo_panel_contact', 'hide');
				setCookie('syboAdminUIMode', 'content');
				break;
		
		}
	}
	this.getMode = function() {
		return this.mode;
	}
	// constructor
	this.change_mode(this.mode);
}

/* Ticker */
function Ticker(id) {
	this.items = new Array();
	this.tickerEl;
	this.currentItem = -1;
	this.height = 0;
	this.thisObj = this;
	this.tickerInfo = false;
	
	this.Ticker = function(id) {
		this.tickerEl = el = document.getElementById(id);
		for(var i = 0; i < el.childNodes.length; i++) {
			if(el.childNodes[i].className == 'tickerItem') {
				this.items[this.items.length] = el.childNodes[i];
				// generate id
				if(this.items[this.items.length-1].id == '') {
					this.items[this.items.length-1].id = Math.ceil(Math.random() * 10000);
				}
			}
			if(el.childNodes[i].className == 'tickerInfo') {
				this.tickerInfo = el.childNodes[i];
			}
		}
		for(var i = 0; i < this.items.length; i++) {
			// height
			el = document.getElementById(this.items[i].id);
			
			//alert(el.offsetHeight);
			if(el.offsetHeight > this.height) {
				this.height = el.offsetHeight;
			}
			
			// hide
			sybo_toggle_vis(this.items[i].id, false, 'hide');
		}
		this.tickerEl.style.height = this.height+'px';

		if(this.items.length > 0) {
			// start Toggle
			setTimeout(function() { this.Toggle() }, 100);
		}
	}
	this.Toggle = function() {
		// hide item
		if(this.currentItem >= 0) {
			sybo_toggle_vis(this.items[this.currentItem].id, true, 'hide');
		}
		
		// show next item
		this.currentItem++;
		if(this.currentItem == this.items.length) {
			this.currentItem = 0;
		}
		
		var length = this.items[this.currentItem].innerHTML.length;
		length = length * 60;
		if(length < 6000) {
			length = 6000;
		}
		if(this.tickerInfo != false) {
			this.tickerInfo.innerHTML = '<b>'+(this.currentItem+1)+'/'+this.items.length+'</b>';
		}

		setTimeout(function() { sybo_toggle_vis(this.items[this.currentItem].id, true, 'show');}, 2000);
		
		setTimeout(function() { this.Toggle() }, length);
	}
	this.Ticker(id);
}
function getPageSize() {
//	var width = document.body.clientWidth;
//	var height = document.body.clientHeight;

	var xScroll;
	var yScroll;
	var xVis;
	var yVis;

	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	width = xScroll;
	height = yScroll;
	
	
	 if(typeof window.innerWidth != 'undefined'){
		xVis = window.innerWidth;
		yVis = window.innerHeight;
	}else if(window.document.documentElement){
		xVis = parseInt(window.document.documentElement.clientWidth);
		yVis = parseInt(window.document.documentElement.clientHeight);
	}
	var data = new Array(width, height, xVis, yVis);
	return data;
}
function popupBox(text, width, height, src) {
	var body = document.getElementsByTagName("body").item(0);
	var box = document.createElement('div');
	box.id = 'popupBox_'+Math.ceil(Math.random() * 10000);
	box.onclick = function() { sybo_toggle_vis(box.id, true, 'hide');};
	
	box.className = 'popupBox';
	
	// dimensions
	var windowDim = getPageSize();
	var yScroll = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
	var xScroll = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft;
	
	
	width = width+10;
	height = height + 10;
	
	if(width > windowDim[2]-60) {
		width = windowDim[2]-60;
	}
	if(height > windowDim[3]-60) {
		height = windowDim[3]-60;
	}
	
	// content
	if(typeof src != undefined) {
		var imgObj = document.createElement('img');
		imgObj.setAttribute('src', src);
		imgObj.className = 'popupImg';
		
		// image size
		dim = new Image();
		dim.src = src;
		imgDim = new Array(dim.width, dim.height);
		var k = dim.width/dim.height;
		if(dim.width > width-20) {
			imgObj.setAttribute('width', width-20);
			imgObj.setAttribute('height', Math.round((imgObj.width)/k));
		}
		if(imgObj.height > height-10) {
			imgObj.setAttribute('height', height-10);
			imgObj.setAttribute('width', Math.round(imgObj.height*k));
			width = Math.round(imgObj.height*k)+20;
		}
		
		box.appendChild(imgObj);
		
	}
	
	if(width < 150) { width = 150; }
	if(height < 150) { height = 150; }

	
	var conObj = document.createElement('div');
	conObj.innerHTML = text;
	box.appendChild(conObj);
	
	var closeLink = document.createElement('a');
	closeLink.onclick = function() { sybo_toggle_vis(box.id, true, 'hide'); return false;};
	closeLink.innerHTML = '[X]';
	closeLink.href = '#';
	//closeLink.style.float = 'right';
	box.appendChild(closeLink);
	
	// basic style
	box.style.left = Math.round((xScroll-10) + (windowDim[2]/2 - width/2))+'px';
	
	box.style.top = (yScroll + 30)+'px';
	
	box.style.display = 'none';
	box.style.width = width+'px';
	box.style.height = height+'px';
	
	box.style.width = 'auto';
	box.style.height = 'auto';
	
	// create real box
	body.appendChild(box);
	
	// make appear
	sybo_toggle_vis(box.id, true, 'show');
	
	//box.style.height = (box.offsetHeight+0)+'px';
	
	return false;
}

/** returns selected comp-checkboxes as a string separated by spaces */
function sybo_get_selected_comps() {
	var checkboxes = document.getElementsByName('sybo_component_checkbox');
	var s = "";
	for(i = 0; i < checkboxes.length; i++) {
		if(checkboxes[i].checked == true) {
			s += checkboxes[i].value + " ";
		}
	}// todo trim()
	return s;
}
//]]>

// Galileo-Computing Javascript - Cookie-API
function setCookie(name, wert, domain, expires, path, secure){
   var cook = name +"="+unescape(wert);
   cook += (domain) ? "; domain="+ domain : "";
   cook += (expires) ? "; expires="+expires : "";
   cook += (path) ? "; path="+path : "";
   cook += (secure) ? "; secure" : "";
   document.cookie = cook;
}

function eraseCookie(name, domain, path){
   var cook= name +"=; expires=Thu, 01-Jan-70 00:00:01 GMT";
   cook += (domain) ? "domain="+domain : "";
   cook += (path) ? "path="+path : "";
   document.cookie = cook;
}

function getCookie(name){
   var i = 0;  //Suchposition im Cookie
   var suche = name+"=";
   while (i<document.cookie.length){
      if (document.cookie.substring(i, i+suche.length)==suche){
         var ende = document.cookie.indexOf(";", i+suche.length);
         ende = (ende>-1) ? ende : document.cookie.length;
         var cook = document.cookie.substring(i+suche.length, ende);
         return unescape(cook);
      }
      i++;
   }
   return null;
}