//
// 2006 by bitart; Author: Alexander Graf
//
// Copyright by bitart - Furch & Graf GbR, Gartenstr. 5 56220 St. Sebastian,
// Germany. All rights reserved.
// Copyright in this software is owned by bitart, unless otherwise indicated.
//
// You are not allowed to distribute this software in any form or use it as
// part of another project without asking the owner for permission to use.
//

var iemode = navigator.userAgent.indexOf('MSIE')>0;

var initOK = false;
function initButtons(/* button, button, ... */)
{
	if (arguments.length){
		return initButtonL(arguments);
	}else{
		return initButtonL(document.getElementsByTagName('div'));
	}
}
function initButtonL(es)
{
	for (var ec=0, ee=es.length; ec<ee; ec++){
		var ei = es[ec];
		if (ei.className.indexOf('Button')!=-1){
			if (iemode){
				ei.onmouseover = iehover;
				ei.onmouseout  = iedehover;
			}
			ei.onmousedown = bdown;
			ei.btype = ei.className.split(' ')[0];
		}
		if (ei.className.indexOf('BigButton')!=-1){
			var bl = new Image(); bl.src='/img/space.gif'; bl.className = 'bl'; bl.hspace = 0;
			var bm = document.createElement('div'); bm.className = 'bm';
			while (ei.hasChildNodes()) bm.appendChild(ei.firstChild);
			var br = new Image(); br.src='/img/space.gif'; br.className = 'br'; br.hspace = 0;
			ei.appendChild(br);
			ei.appendChild(bl);
			ei.appendChild(bm);
			ei.btype = ei.className.split(' ')[0];
		}
	}
	initOK = true;
}

function hideButtons(bclass, fuzzy)
{
	if (!bclass) bclass='Button';
	for (var ec=0, es=document.getElementsByTagName('div'), ee=es.length; ec<ee; ec++){
		var ei=es[ec];
		if (fuzzy){
			if (ei.className.indexOf(bclass)!=-1) ei.style.visibility = 'hidden';
		}else{
			if (ei.className.indexOf(bclass)==0) ei.style.visibility = 'hidden';
		}
	}
}

function showButtons(bclass, fuzzy)
{
	if (!bclass) bclass='Button';
	for (var ec=0, es=document.getElementsByTagName('div'), ee=es.length; ec<ee; ec++){
		var ei=es[ec];
		if (fuzzy){
			if (ei.className.indexOf(bclass)!=-1) ei.style.visibility = 'visible';
		}else{
			if (ei.className.indexOf(bclass)==0) ei.style.visibility = 'visible';
		}
	}
}

function bdown()
{
	this.className += ' '+this.btype+'Pressed';
	this.temp = typeof(document.onmouseup)!='undefined'&&typeof(document.onmouseup)!='unknown'?document.onmouseup:'';
	bup.but = this;
	document.onmouseup = bup;
}

function bup()
{
	var ths = bup.but;
	ths.className = ths.className.split(' '+ths.btype+'Pressed').join('');
	if (ths.temp) document.onmouseup = ths.temp;
}

function iehover()
{
	this.className += ' '+this.btype+'Hover';
}

function iedehover()
{
	this.className = this.className.split(' '+this.btype+'Hover').join('');
}

/* Misc Functions */

function printWindow(bclass)
{
	closePanel(true);
	hideButtons(bclass);
	window.print();
	window.setTimeout('showButtons("'+bclass+'")',10);
	return false;
}

function toTop()
{
	window.scrollTo(0,0);
	return false;
}

function frameCheck()
{
	if (window.name != 'content'){
		var but = document.getElementById('bookbut');
		if (but){
			window.location.replace(but.firstChild.href);
		}
	}
}

/* Tooltip Popup */

var tooltip = null;
var toolsav = null;
function showTip(text, x, y)
{
	if (!initOK) return false;
	if (tooltip === null){
		tooltip = document.createElement('div');
		tooltip.className = 'tooltip';
		tooltip.appendChild(document.createElement('div'));
		document.body.appendChild(tooltip);
	}
	var xp = (x?x:0) + (document.body.scrollLeft||window.pageXOffset||0);
	var yp = (y?y:0) + (document.body.scrollTop||window.pageYOffset||0);
	tooltip.style.left = xp+'px';
	tooltip.style.top = yp+'px';
	tooltip.firstChild.innerHTML = text;
	tooltip.style.visibility = 'visible';
	toolsav = document.onscroll;
	document.onscroll = hideTip;
}
function hideTip()
{
	if (tooltip !== null){
		tooltip.style.visibility = 'hidden';
	}
	if (toolsav !== null){
		try{
			document.onscroll = toolsav;
			toolsav();
		}catch(e){};
		toolsav = null;
	}
}

