// common JavaScripts
// power-games.ch
// Author: ker
// Copyright: 2001-2002, zimtkorn GmbH, Dietikon


// google ad-sense init
/*google_ad_client = "pub-6697880082787979";
google_ad_width = 120;
google_ad_height = 240;
google_ad_format = "120x240_as";
google_ad_channel ="";
google_ad_type = "text";
google_color_border = "336699";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_url = "008000";
google_color_text = "000000";*/

// the code
var aszMenus = new Array("home", "power-games", "power-events", "referenzen", "offerte", "preise", "firma", "guestbook", "kontakt", "pool");
var aMnus = new Array(), aMnusOver = new Array();

var darkBox = null;
var lightBox = null;
var theDoc = null;

preloadImages();

function toggle(id, on) {
	var mnu = document.images["mnu" + id];
	if (on && mnu.src != aMnusOver[id].src)
		mnu.src = aMnusOver[id].src;
	else if (!on && mnu.src != aMnus[id].src)
		mnu.src = aMnus[id].src;
}

function on(id) {
	toggle(id, true);
}

function off(id) {
	toggle(id, false);
}

function preloadImages() {
	for (var i = 0; i < aszMenus.length; i++) {
		aMnus[i] = new Image();
		aMnus[i].src = "/images/menu/" + aszMenus[i] + ".gif";
		
		aMnusOver[i] = new Image();
		aMnusOver[i].src = "/images/menu/" + aszMenus[i] + "_over.gif";
	}
}


function writePageStart(szTitle, hasNewsTicker) {
	with (document) {
write('');
if (bNS)	// stupid old netscape
	write('<table border=0 cellpadding=0 cellspacing=0 width=100%>');
else // good browsers, such as Microsoft Internet Explorer
	write('<table border=0 cellpadding=0 cellspacing=0 width=100% height=100%>');
write('<tr><td height=155><table border=0 cellpadding=0 cellspacing=0 width=100%>');
write('	<tr valign=top>');
write('		<td width=145><img src="/images/frame/words.gif" width=145 height=85></td>');
write('		<td class=bgwhite><img src="/images/blank.gif" width=4 height=1></td>');
write('		<td width=99% class=logobanner align=right><img src="/images/blank.gif"');
write('			width=1 height=14><br><a href="/cm/login.asp"><img');
// write('			src="/images/frame/logo_t.gif" width=320 height=65 border=0></a><img');
write('			src="/images/frame/logo.gif" width=455 height=65 border=0></a><img');
write('			src="/images/blank.gif" width=13 height=1></td>');

write('		<td rowspan=4 class=rightback width=34><img src="/images/frame/righttop.gif" width=30 height=85><br>');
write('			<img src="/images/blank.gif" width=34 height=4><br>');
write('			<img src="/images/frame/rightnews.gif" width=30 height=62><br>');
write('			<img src="/images/blank.gif" width=34 height=4></td>');

//write('		<td bgcolor=red rowspan=5 width=150><img src="/images/blank.gif" width=150 height=1></td>');

write('	</tr>');
write('	<tr><td colspan=3 class=bgwhite><img src="/images/blank.gif" width=1 height=4></td></tr>');
write('	<tr>');
write('		<td class=menubar align=center><img src="/images/blank.gif" width=1 height=62');
write('			align=absmiddle><img src="/images/titles/' + szTitle + '.gif" height=23></td>');
write('		<td class=bgwhite><img src="/images/blank.gif" width=4 height=1></td>');
write('		<td class=newsbar align=right><img src="/images/frame/news.gif" width=220');
write('			height=62><img src="/images/blank.gif" width=15 height=1></td>');
write('	</tr>');
write('	<tr><td colspan=3 class=bgwhite><img src="/images/blank.gif" width=1 height=4></td></tr>');
write('</table></td>');
/*write('	<td width=50 rowspan=3 valign=top>');
	//writeAds();
write('	</td>');*/
write('</tr>');
if (bNS) // netscape
	write('<tr><td><table border=0 cellpadding=0 cellspacing=0 width=100% height=100%>');
else // browsers
	write('<tr><td height=99%><table border=0 cellpadding=0 cellspacing=0 width=100% height=100%>');
write('	<tr valign=top>');
write('		<td rowspan=4 class=menubar width=145><img src="/images/blank.gif" width=1 height=15><br>');
write('			<img src="/images/blank.gif" width=145 height=200>');
write('			<div id=menuBar><a href="/" onmouseover="on(0)" onmouseout="off(0)"><img name=mnu0');
write('				src="/images/menu/home.gif" width=145 height=23 border=0></a><br>');
write('			<a href="/power-games/" onmouseover="on(1)" onmouseout="off(1)"><img name=mnu1');
write('				src="/images/menu/power-games.gif" width=145 height=23 border=0></a><br>');
write('			<a href="/power-events/" onmouseover="on(2)" onmouseout="off(2)"><img name=mnu2');
write('				src="/images/menu/power-events.gif" width=145 height=23 border=0></a><br>');
write('			<a href="/referenzen/" onmouseover="on(3)" onmouseout="off(3)"><img name=mnu3');
write('				src="/images/menu/referenzen.gif" width=145 height=23 border=0></a><br>');
write('			<a href="/offerte.asp" onmouseover="on(4)" onmouseout="off(4)"><img name=mnu4');
write('				src="/images/menu/offerte.gif" width=145 height=23 border=0></a><br>');
write('			<a href="/preise.asp" onmouseover="on(5)" onmouseout="off(5)"><img name=mnu5');
write('				src="/images/menu/preise.gif" width=145 height=23 border=0></a><br>');
write('			<a href="/pool.asp" onmouseover="on(9)" onmouseout="off(9)"><img name=mnu9');
write('				src="/images/menu/pool.gif" width=145 height=23 border=0></a><br>');
write('			<a href="/firma/" onmouseover="on(6)" onmouseout="off(6)"><img name=mnu6');
write('				src="/images/menu/firma.gif" width=145 height=23 border=0></a><br>');
//write('			<a href="/guestbook/" onmouseover="on(7)" onmouseout="off(7)"><img name=mnu7');
//write('				src="/images/menu/guestbook.gif" width=145 height=23 border=0></a><br>');
write('			<a href="/kontakt.asp" onmouseover="on(8)" onmouseout="off(8)"><img name=mnu8');
write('				src="/images/menu/kontakt.gif" width=145 height=23 border=0></a><br></div>');
write('		</td>');
write('		<td rowspan=4 class=bgwhite width=4><img src="/images/blank.gif" width=4 height=1></td>');
write('		<td rowspan=3 class=contentpane width=200%><table border=0 cellpadding=10 width=100%><tr><td>');
	}
}

function writePageEnd(hasTicker) {
	with (document) {
write('		</td></tr></table></td>');
write('		<td class=rightmiddleback1 width=34 height=49%><img src="/images/blank.gif" width=34 height=1></td>');
write('	</tr>');
write('	<tr><td class=rightmiddleback1 valign=bottom width=34><img src="/images/frame/rightmiddle.gif" width=30 height=190></td></tr>');
write('	<tr><td rowspan=2 class=rightmiddleback2 width=34 height=49%><img src="/images/blank.gif" width=34 height=1></td></tr>');
if (hasTicker) {
	write('	<tr><td class=contentpane valign=bottom><div id=tickerBar>theTicker<div id=ticker nowrap></div></div></td></tr>');
} else {
	write('	<tr><td class=contentpane valign=bottom>&nbsp;</td></tr>');
}
write('</table></td></tr>');
write('<tr><td height=59><table border=0 cellpadding=0 cellspacing=0 width=100%>');
write('	<tr>');
write('		<td colspan=4 class=bgwhite><img src="/images/blank.gif" width=1 height=4></td>');
write('		<td rowspan=2 class=rightback width=34><img src="/images/blank.gif" width=34 height=4><br>');
write('			<img src="/images/frame/rightbottom.gif" width=30 height=55></td>');
write('	</tr>');
write('	<tr>');
write('		<td class=menubar width=145 align=center><img src="/images/blank.gif" width=145 height=1><br>');
write('			<span class=webdesign>webdesign by<br>');
write('			<a class=alva href="http://www.zimtkorn.ch" target=_blank>zimtkorn GmbH</a></span></td>');
write('		<td class=bgwhite><img src="/images/blank.gif" width=4 height=1></td>');
write('		<td class=searchbar><img src="/images/blank.gif" width=15 height=55><img');
write('			src="/images/frame/search.gif" width=272 height=55></td>');
write('		<td width=99% class=searchbar align=center valign=middle>');
write('			<table border=0 cellpadding=0 cellspacing=0><tr>');
write('				<td><form action="/search/search.asp" class=searchform name=searchForm>');
if (bNS)
	write('					<input name=q size=15></form></td>');
else
	write('					<input name=q class=searchbox></form></td>');
write('				<td>&nbsp;</td>');
if (bNS)
	write('				<td><form><a href="JavaScript:document.forms.searchForm.submit()" class=go>Go!</a></form></td>');
else
	write('				<td><a href="JavaScript:document.forms.searchForm.submit()" class=go>Go!</a></td>');
write('			</tr></table>');
write('		</td>');
write('	</tr>');
write('</table></td></tr>');
write('</table>');
/*write('<div id=lightbox style="filter:alpha(opacity=70);"><img src="/images/frame/lightbox.gif" width=24 height=24></div>');
write('<div id=darkbox style="filter:alpha(opacity=70);"><img src="/images/frame/darkbox.gif" width=18 height=18 alt="Klick und Zieh mich"></div>');*/
write('<div id=newscontainer><div id=newspane></div></div>');
	}
	//setTimeout("initBox();", 1);
	setTimeout("initNews(); initMenu()", 1);
	//resizeHandler.add("initBox()");
	
	if (hasTicker) {
		resizeHandler.add("initTicker()");
		setTimeout("initTicker();", 1);
	}
}

/*function initBox() {
	if (darkBox == null)
		darkBox = new drag("darkbox");
	if (lightBox == null)
		lightBox = new dynLayer("lightbox");
	if (theDoc == null)
		theDoc = new doc();
	
	//lightBox.homeX = theDoc.clientWidth() - 95;
	lightBox.homeX = theDoc.clientWidth() - 50;
	lightBox.homeY = (theDoc.clientHeight() - 24) / 2;
	lightBox.pos(lightBox.homeX, lightBox.homeY);
	
	darkBox.homeX = lightBox.homeX + 3;
	darkBox.homeY = lightBox.homeY + 3;
	darkBox.pos(darkBox.homeX, darkBox.homeY);
}

function MoveLightBox(dragdata)
{
	var dx = darkBox.left() - darkBox.homeX;
	var dy = darkBox.top() - darkBox.homeY;
	if (dragdata)
	{
		dx += dragdata.x - darkBox.dx;
		dy += dragdata.y - darkBox.dy;
	}
	var len = Math.sqrt(dx * dx + dy * dy);
	var a = 0;
	if (dy != 0 || dx != 0)
		a = Math.atan(dy / dx);
	if (a > 0.0)
		a += Math.PI / 2;
	else
		a -= Math.PI / 2;
	if (dy <= 0)
		a -= Math.PI;
	
	var x = len * Math.cos(a) + lightBox.homeX;
	var y = len * Math.sin(a) + lightBox.homeY;

	if (x > (theDoc.clientWidth() - 24))
		x = 2 * (theDoc.clientWidth() - 24) - x;
	if (x < 0)
		x = -x;
	if (y < 0)
		y = -y;
	if (y > (theDoc.clientHeight() - 24))
		y = 2 * (theDoc.clientHeight() - 24) - y;

	lightBox.pos(x, y);
}

function OnDrag(dragdata) {
	if (darkBox.left() + dragdata.x - darkBox.dx < 0)
		dragdata.x = darkBox.dx - darkBox.left();
	else if (darkBox.left() + dragdata.x - darkBox.dx + 18 > theDoc.clientWidth())
		dragdata.x = darkBox.dx - darkBox.left() + theDoc.clientWidth() - 18;

	if (darkBox.top() + dragdata.y - darkBox.dy < 0)
		dragdata.y = darkBox.dy - darkBox.top();
	else if (darkBox.top() + dragdata.y - darkBox.dy + 18 > theDoc.clientHeight())
		dragdata.y = darkBox.dy - darkBox.top() + theDoc.clientHeight() - 18;
	MoveLightBox(dragdata);
	return true;
}

function OnDrop(dragdata) {
	animElastic();
	return true;
}

var vx = 0;
var vy = 0;
var k = 0.4;
var c = 0.8;
var dt = 0.5;

function animElastic()
{
	var dx = darkBox.left() - darkBox.homeX;
	var dy = darkBox.top() - darkBox.homeY;
	vx = -k * dx + c * vx;
	vy = -k * dy + c * vy;
	if (Math.abs(vx) <= 2 && Math.abs(vy) <= 2 && Math.abs(dx) <= 2 && Math.abs(dy) <= 2)
	{
		darkBox.pos(darkBox.homeX, darkBox.homeY);
		lightBox.pos(lightBox.homeX, lightBox.homeY);
	}
	else {
		if ((darkBox.left() + vx * dt) > (theDoc.clientWidth() - 18)) {
			var dleft = theDoc.clientWidth() - 18 - darkBox.left();
			dx = 2 * dleft - vx * dt;
			vx = -vx;
		}
		else
			dx = vx * dt;
		if ((darkBox.top() + vy * dt) > (theDoc.clientHeight() - 18)) {
			var dtop = theDoc.clientHeight() - 18 - darkBox.top();
			dy = 2 * dtop - vy * dt;
			vy = -vy;
		}
		else
			dy = vy * dt;
		darkBox.moveby(dx, dy);
		MoveLightBox();
		setTimeout("animElastic()", 1);
	}
}*/


var menuBar = null;
function initMenu() {
	if (!menuBar) {
		menuBar = new dynLayer("menuBar");
	}
	
	if (bDHTML) {
		document.body.onscroll = menuScroll;
		menuScroll();
	}
}

function menuScroll() {
	if (!menuBar) {
		menuBar = new dynLayer("menuBar");
	}
	
	if (bDHTML) {
		var delta = document.body.scrollHeight - (170 + 184 + document.body.scrollTop) - 59;
		menuBar.top(170 + document.body.scrollTop + Math.min(delta, 0));
	}
	else {
	}
}


var tickerBar = null;
var ticker = null;
var tickerPos = null;
var tickerTimer = null;
function initTicker() {
	if (!tickerBar) {
		tickerBar = new dynLayer("tickerBar");
	}
	if (!ticker) {
		ticker = new dynLayer("ticker", tickerBar);
		setTimeout('ticker.setHTML(szTicker);', 10)
	}
	if (!theDoc) {
		theDoc = new doc();
	}
	
	if (tickerPos == null || tickerPos > tickerBar.width())
		tickerPos = tickerBar.width();
	tickerBar.clip(0, 0, tickerBar.width(), ticker.height());
	tickerBar.top(theDoc.clientHeight() - 59 - tickerBar.height());
	ticker.left(tickerPos - 50);
	
	if (tickerTimer == null)
		tickerTimer = setInterval("rollTicker()", 25);
}

function rollTicker() {
	tickerPos -= 1;
	ticker.left(tickerPos);
	
	if (tickerPos < -ticker.width()) {
		tickerPos = tickerBar.width();
	}
}