/**
* init function after page load
*/
function InitPage()
{
	ResizeContent();
	ResetLinkBullets();
	AdaptBoxes();
}

function AdaptBoxes()
{
	var boxes = $$('#content div.dynamicbox');
	var max_height = 0;
	var tmp_height = 0;
	
	for(var i=0;i<boxes.length;i++){
		tmp_height = Element.getHeight(boxes[i]);
		
		if(tmp_height>max_height){
			max_height = tmp_height;
		}		
	}
	
	for(var i=0;i<boxes.length;i++){
		boxes[i].style.height = max_height+'px';		
	}
}

function ResetLinkBullets()
{
	var li = $$('#content li a');

	if(li.length>0 && li[0].parentNode.parentNode.id!='preftoc'){
		for(var i=0;i<li.length;i++){
			if(li[i].parentNode.innerHTML.substr(0,2)=='<a'){
				Element.extend(li[i].parentNode);
				li[i].parentNode.addClassName('lnk');
			}else{
				li[i].className = 'nobullet';
			}
		}
	}
}
function ResizeContent()
{
	var skyscraper_width = $('skyscraper').getWidth();
	var viewport_width = document.viewport.getWidth();
	var sidebar_width = $('column-sidebar').getWidth();

	$('page').style.width = (viewport_width-skyscraper_width-20)+'px';
	$('column-content').style.width = (viewport_width-skyscraper_width-sidebar_width-31)+'px';
	
	if($('pano')){
		mypano = new Interface.Pano('pano','panowrap','panocursor');
	}
}

/**
* open accessible popup
*
* @param	string		url
* @return	boolean		always false
*/
function Popup (url) {
	var newwindow	= window.open(url, "popup","width=400,height=550,menubar=no,location=no,status=no,scrollbars=yes,toolbar=yes,resizable=yes");
	newwindow.focus();
	return false;
}

/**
* simulates target blank in an accessible way
*
* use links: <a href="http://www.triple-i.de" onclick="return TargetBlank(this.href)">Link</a>
*
* @param	string		url
* @return	boolean		always false
*/
function TargetBlank (url) {
	var newwindow	= window.open(url, "newwindow"+String(Math.round(Math.random()*10)),"menubar=yes,location=yes,status=yes,scrollbars=yes,toolbar=yes,resizable=yes");
	newwindow.focus();
	return false;
}

/*
* Creates a new browser window.
*
* @param	string		url to load in new window
* @param	string		name of new window
* @param	string		width of new window (optional, uses default size if omitted)
* @param	string		height of new window (optional, uses default size if omitted)
* @param	string		string containg attribs the new window should have (optional,
						default is everything on, use an empty string to turn everything,
						off, certain attribute keywords to activate these attributes)
* @returns	object		window object of created window
*/
function CreateWindow(url,name,w,h,attribs) {
	var menubar=0;
	var toolbar=0;
	var locationbar=0;
	var personalbar=0;
	var statusbar=0;
	var scrollbars=0;
	var resizable=0;
	if(typeof(w)=='undefined') { var w=0; }
	if(typeof(h)=='undefined') { var h=0; }
	if(typeof(attribs)=='undefined'||attribs=='none') { var attribs=''; }
	else if(attribs.match('all')||attribs.match('every')) {
		menubar=1;
		toolbar=1;
		locationbar=1;
		personalbar=1;
		statusbar=1;
		scrollbars=1;
		resizable=1;
	} else {
		if(attribs.match('menu')) { menubar=1; }
		if(attribs.match('tool')) { toolbar=1; }
		if(attribs.match('loc')) { locationbar=1; }
		if(attribs.match('pers')) { personalbar=1; }
		if(attribs.match('stat')) { statusbar=1; }
		if(attribs.match('scroll')) { scrollbars=1; }
		if(attribs.match('resiz')) { resizable=1; }
	}
	attribs='';
	if(w>0) { attribs+='width='+w; }
	if(h>0) {
		if(attribs!='') { attribs+=','; }
		attribs+='height='+h;
	}
	if(attribs!='') { attribs+=','; }
	attribs+='menubar='+menubar+',toolbar='+toolbar+',location='+locationbar;
	attribs+=',personalbar='+personalbar+',status='+statusbar+',scrollbars='+scrollbars;
	attribs+=',resizable='+resizable;
	return window.open(url,name,attribs);
}

/*
* Close a window and optionally focus on opener.
*
* @param	boolean 	wether or not to focus on window opener
*/
function CloseWindow(focusopener) {
	if(typeof(focusopener)=="undefined") { var focusopener=false; }
	if(focusopener&&window.opener) { window.opener.focus(); }
	window.close();
}

/**
* center a popup window on screen
*
* @param    object  window object (optional)
*/
function CenterPopup(win) {
	if(typeof(win)=='undefined'||win=='') { var win=window; }
	
	win_width	= GetDocumentWidth(win);
	win_height	= GetDocumentHeight(win);
	
	MoveWindowTo(screen.width/2-win_width/2,screen.height/2-win_height/2,win);
}

/*
* Move a window to a certain position on screen.
*
* @param	int			x coordinate
* @param	int			y coordinate
* @param	object		window object to use (optional)
*/
function MoveWindowTo(x,y,win) {
	if(typeof(win)=='undefined') { var win=window; }
	win.moveTo(x,y);
}

/**
* Creates a cookie
*
* @param	string		name of the cookie
* @param	string		value
* @param	integer		number of days till expires
*/
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=/";
}

/**
* read a cookie by name
*
* @param	string		name of cookie
* @return	string		get value of cookie
*/
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;
}

/**
* erase a cookie by name
*
* @param	string		name of cookie
*/
function EraseCookie(name) {
	createCookie(name,"",-1);
}
