// the measurements of the background image
var backgroundWidth = 772;
var backgroundHeight = 444;
var imgPfad = "images/";
var tageszeiten = new Array("morgen","tag","abend","nacht");
var bodycolors = new Array("FFCC72","CEE7FF","4A4F55","101228");
var mainpage="index.html";
LINKS=0,RECHTS=LINKS+1;
X=0,Y=X+1;

var preloadImg = new Array();

function XY(x,y) { this.x = x; this.y = y; }

function Page(x, y, link, target, alt, menutext, imgID) {
	this.XY = new XY(x, y);
	this.link = link;
	this.target = target;
	this.alt = alt;
	this.menutext = menutext;
	this.imgID = imgID;
this.timeOfDay="";
	this.setTimeOfDay = function(timeOfDay) { this.timeOfDay = timeOfDay; }
	this.getImgBrightName = function() { return this.timeOfDay + "_nav" + this.imgID + "_h.gif"; } 
	this.getImgDarkName = function() { return this.timeOfDay + "_nav" + this.imgID + "_d.gif"; } 
}

var PAGEBIO = 0, PAGEDISCO = PAGEBIO + 1, PAGEGALLERY = PAGEDISCO + 1,
    PAGELINKS = PAGEGALLERY + 1, PAGECONTACT = PAGELINKS + 1, PAGEFOAM = PAGECONTACT + 1; 

var pageBio = new Page(89, 333, "bio.html", "_self", "biography", "BIOGRAPHY", 0);
var pageDisco = new Page(244, 356, "disco.html", "_self", "tipps & discography", "TIPPS &amp; DISCOGRAPHY", 1);
var pageGallery = new Page(373, 381, "gallery.html", "_self", "gallery", "GALLERY", 2);
var pageLinks = new Page(464, 355, "links.html", "_self", "links", "LINKS", 3);
var pageContact = new Page(686, 358, "contact.html", "_self", "news & contact", "NEWS &amp; CONTACT", 4);
var pageFoam = new Page(43, 244, "http://www.foam.de", "_blank", "foam.de", "foam.de", 5);

var pages = new Array();
pages[PAGEBIO] = pageBio;
pages[PAGEDISCO] = pageDisco;
pages[PAGEGALLERY] = pageGallery;
pages[PAGELINKS] = pageLinks;
pages[PAGECONTACT] = pageContact;
pages[PAGEFOAM] = pageFoam;

var numPages = pages.length;

function Arrow(x, y, imgNameBright, imgNameDark, alt) {
	this.XY = new XY(x, y);
	this.imgNameBright = imgNameBright;
	this.imgNameDark = imgNameDark;
	this.alt = alt;
	
	this.setTimeOfDay = function(timeOfDay) { this.timeOfDay = timeOfDay; }
	this.getImgBrightName = function() { return this.timeOfDay + this.imgNameBright; } 
	this.getImgDarkName = function() { return this.timeOfDay + this.imgNameDark; } 
}

arrowLeft = new Arrow(626, 319, "_pfeil_links_h.gif", "_pfeil_links_d.gif", "previous");
arrowRight = new Arrow(686, 319, "_pfeil_rechts_h.gif", "_pfeil_rechts_d.gif", "next");

var arrows = new Array();
arrows[LINKS] = arrowLeft;
arrows[RECHTS] = arrowRight;

var mouseIsOverArrows = new Array();
mouseIsOverArrows[LINKS] = false;
mouseIsOverArrows[RECHTS] = false;
mouseWasOverArrows = false;

var mouseIsOverNavigation = new Array();

// glowing times in ms
MINMSBEFOREGLOW=1000;
MAXMSBEFOREGLOW=2300;
MINMSGLOWTIME=500;
MAXMSGLOWTIME=1000;

// a trim function
if (!String.prototype.trim)
{
  String.prototype.trim = function()
  {
    return this.replace(/^\s+/, '').replace(/\s+$/, '');
  };
}

if (!String.prototype.left)
{
  String.prototype.left = function(n){ return this.substr(0, n); }
}
if (!String.prototype.right)
{
  String.prototype.right = function(n){ return this.substr(this.length-n); }
}

// current page
var curpage=location.href.left(location.href.length-location.search.length);

function tageszeitID()
{
  var jetzt = new Date();
  var imgID;
  var Std = jetzt.getHours();

  if (Std >= 5 && Std < 12) imgID = 0;
  else if(Std >= 12 && Std < 18) imgID = 1;
  else if(Std >= 18 && Std <= 23) imgID = 2;
  else if(Std >= 0 && Std < 5) imgID = 3;
  return imgID;
}

var tageszeitID = tageszeitID();

function myRandom(l,u)
{
  return Math.round((u - l) * Math.random() + l);
}

function isPosInteger(v)
{
  var v1=v.toString();
  var r=true;
  for (var i=0; i<v1.length; i++)
    r &= (v.charAt(i) >= "0" && v.charAt(i) <= "9");

  return r;
}

// decode the query string to determine which form field we're dealing with
var qstring, name_value_pairs, i, pairs, p, val;
var sp=0; // subpage on page
qstring = new String(self.location.search);
qstring = qstring.substr(1);  // remove the ? character
// split into name value pairs
name_value_pairs = qstring.split("&");
for (i = 0; i < name_value_pairs.length; i++)
{
	pairs = name_value_pairs[i].split("=");
	p = pairs[0];
	val = pairs[1];

	if (p=="t")	// tageszeit
	  if (val >= 0 && val <= tageszeiten.length) tageszeitID=val;
	if (p=="sp")	// subpage
	  sp=isPosInteger(val)?val:0;
}
sp=parseInt(sp);

var tageszeit = tageszeiten[tageszeitID];  // welche tageszeit haben wir?

// und jedem object die tageszeit geben
for (var i = 0; i < numPages; i++)
	pages[i].setTimeOfDay(tageszeit);

arrows[LINKS].setTimeOfDay(tageszeit);
arrows[RECHTS].setTimeOfDay(tageszeit);
	
function insertCSS(d)
{
  var h;
  h='<style type="text/css">';
  for (var i=0; i<numPages; i++)
    h+='#layerNav'+i+'{position:absolute;left:0px;top:0px;z-index:3;visibility:visible;}';

  // pfeile
  h+='#layerPfeil'+LINKS+'{position:absolute;left:0px;top:0px;z-index:4;visibility:hidden;}';
  h+='#layerPfeil'+RECHTS+'{position:absolute;left:0px;top:0px;z-index:4;visibility:hidden;}';
  h+='</style>';
  d.write(h);
}

function showPfeile(d,l,r)
{
  d.getElementById("layerPfeil"+LINKS).style.visibility=(l?"visible":"hidden");
  d.getElementById("layerPfeil"+RECHTS).style.visibility=(r?"visible":"hidden");

  // kick off the auto glow to show that there is something to click
  glowArrows(l,r);
}

function showBackgroundHigh(d)
{
  d.getElementById("layerBackgroundHigh").style.visibility="visible";
}

function hell(img,id){ eval("document."+img+".src='"+imgPfad+ pages[id].getImgBrightName() + "'");}
function dunkel(img,id){eval("document."+img+".src='"+imgPfad + pages[id].getImgDarkName() +"'");}
function hellPfeil(img,id){eval("document."+img+".src='"+imgPfad+arrows[id].getImgBrightName() + "'");}
function dunkelPfeil(img,id){eval("document."+img+".src='"+imgPfad+arrows[id].getImgDarkName() + "'");}

function positionImages(d)
{
  for (var i=0; i<numPages; i++)
  {
  	page = pages[i];
    layer=eval(d.getElementById("layerNav"+i));
    layer.style.position = "absolute";
    layer.style.left = page.XY.x;
    layer.style.top = page.XY.y;
  }
  
  // pfeile
  layer=d.getElementById("layerPfeil"+LINKS);
  layer.style.position = "absolute";
  layer.style.left = arrows[LINKS].XY.x;
  layer.style.top = arrows[LINKS].XY.y;
  layer=d.getElementById("layerPfeil"+RECHTS);
  layer.style.position = "absolute";
  layer.style.left = arrows[RECHTS].XY.x;
  layer.style.top = arrows[RECHTS].XY.y;
}

function loadBackground(d)
{
  // load the image
  d.getElementById("jondalimg").src = imgPfad+tageszeit+"_bg.jpg";
}

function insertBackgroundHigh(d)
{
  d.getElementById("layerBackgroundHigh").style.background="url("+imgPfad+tageszeit+"_bg_high.jpg)";
}

function loadImages()
{
  // preload the navigation images
  var n = 0;
  for (var i=0; i<numPages; i++)
  {
  	page = pages[i];
    preloadImg[n] = new Image(); preloadImg[n++].src = imgPfad+page.getImgBrightName();
    preloadImg[n] = new Image(); preloadImg[n++].src = imgPfad+page.getImgDarkName();
  }

  // pfeile
  preloadImg[n] = new Image(); preloadImg[n++].src = imgPfad+arrows[LINKS].getImgBrightName();
  preloadImg[n] = new Image(); preloadImg[n++].src = imgPfad+arrows[RECHTS].getImgBrightName();
  preloadImg[n] = new Image(); preloadImg[n++].src = imgPfad+arrows[LINKS].getImgDarkName();
  preloadImg[n] = new Image(); preloadImg[n++].src = imgPfad+arrows[RECHTS].getImgDarkName();
}

function setBodyColor(d)
{
  d.body.style.backgroundColor="#"+bodycolors[tageszeitID];
}

function waitLoading()
{
  var c = true;
  for (var i=0; i<document.images.length; i++)
    c &= document.images[i].complete;

  if (!c) Window.setTimeout("waitLoading",100);
}

function insertJondalLogo(d)
{
  var h='<div id="layerJondalLogo">';
  h+='<a href="'+mainpage+'"><img src="'+imgPfad+tageszeit+'_logo_jondal.gif" name="logoImg" border="0"></a>';
  h+='</div>';
  d.write(h);
}

function insertNavigation(d)
{
  var h="";
  for (var i=0; i<numPages; i++)
  {
    mouseIsOverNavigation[i] = false;
    page = pages[i];
    h+='<div id="layerNav'+i+'"><a href="' + page.link + '" target="' + page.target + '"><img src="'+imgPfad+ page.getImgDarkName() + '" name="navImg'+i+'" onmouseover="hell(\'navImg'+i+'\','+i+');mouseIsOverNavigation['+i+']=true;mouseWasOverNavigation=true;" onmouseout="dunkel(\'navImg'+i+'\','+i+');mouseIsOverNavigation['+i+']=false;" alt="'+page.alt+'" title="'+page.alt+'" border="0"></a></div>';
  }
  
	arrow = arrows[LINKS];
  h+='<div id="layerPfeil'+LINKS+'"><a href="javascript:clickPfeil(document,'+LINKS+');" border="0"><img src="'+imgPfad+arrow.getImgBrightName()+'" name="pfeilImg'+LINKS+'" onmouseover="hellPfeil(\'pfeilImg'+LINKS+'\','+LINKS+');mouseIsOverArrows['+LINKS+']=true;mouseWasOverArrows=true;" onmouseout="dunkelPfeil(\'pfeilImg'+LINKS+'\','+LINKS+');mouseIsOverArrows['+LINKS+']=false;" alt="'+arrow.alt+'" title="'+arrow.alt+'" border="0"></a></div>';
  
	arrow = arrows[RECHTS];
  h+='<div id="layerPfeil'+RECHTS+'"><a href="javascript:clickPfeil(document,'+RECHTS+');" border="0"><img src="'+imgPfad+arrow.getImgDarkName()+'" name="pfeilImg'+RECHTS+'" onmouseover="hellPfeil(\'pfeilImg'+RECHTS+'\','+RECHTS+');mouseIsOverArrows['+RECHTS+']=true;mouseWasOverArrows=true;" onmouseout="dunkelPfeil(\'pfeilImg'+RECHTS+'\','+RECHTS+');mouseIsOverArrows['+RECHTS+']=false;" alt="'+arrow.alt+'" title="'+arrow.alt+'" border="0"></a></div>';
  d.write(h);

  // kick off glowing
  mouseWasOverNavigation = false;
  glowNavigations();
}

function Browser() {

   var agt=navigator.userAgent.toLowerCase();

   this.major = parseInt(navigator.appVersion);
   this.minor = parseFloat(navigator.appVersion);
   this.MajorVer = parseInt(navigator.appVersion.charAt(0));
   this.MinorVer1 = parseInt(navigator.appVersion.charAt(2));
   this.MinorVer2 = parseInt(navigator.appVersion.charAt(3));

   this.nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1));
   this.nav2 = (this.nav && (this.major == 2));
   this.nav3 = (this.nav && (this.major == 3));
   this.nav4 = (this.nav && (this.major == 4));
   this.nav4up = (this.nav && (this.major >= 4));
   this.navonly      = (this.nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
   this.nav5 = (this.nav && (this.major == 5));
   this.nav5up = (this.nav && (this.major >= 5));

   // opera is IE compatible, so just treat it as IE
   this.ie   = (agt.indexOf("msie") != -1) || (agt.indexOf("opera") != -1);
   this.ie3  = (this.ie && (this.major < 4));
   this.ie4  = (this.ie && (this.major == 4) && (agt.indexOf("msie 5")==-1) );
   this.ie4up  = (this.ie  && (this.major >= 4));
   this.ie5  = (this.ie && (this.major == 4) && (agt.indexOf("msie 5")!=-1) ) || (agt.indexOf("opera") != -1);
   this.ie5up  = (this.ie  && !this.ie3 && !this.ie4);
   this.mozilla = (agt.indexOf("safari") != -1) || (agt.indexOf("mozilla") != -1);
   this.mac    = (agt.indexOf("mac")!=-1);
   this.unix  = ((agt.indexOf("x11")!=-1));
}

var browser = new Browser();
var dl = document.layers;
var da = document.all;

if(browser.nav4) {
    doc = "document";
    sty = "";
    htm = ".document";
	hidden = "hide";
	visible = "show";

    cDoc = "document";
    cSty = "";
    cHtm = ".document";
	cHidden = "hide";
	cVisible = "show";

	mousexpos = "event.pageX";
	mouseypos = "event.pageY";
}
else if(browser.nav5up)
{
    doc = "document";
    sty = "";
    htm = ".document";
	hidden = "hide";
	visible = "show";

    cDoc = "document";
    cSty = "";
    cHtm = ".document";
	cHidden = "hide";
	cVisible = "show";

	mousexpos = "event.clientX";
	mouseypos = "event.clientY";
}
else if(browser.ie4up)
{
    doc = "document.all";
    sty = ".style";
    htm = "";
	hidden = "hidden";
	visible = "visible";

    cDoc = "document.all";
    cSty = ".style";
    cHtm = "";
	cHidden = "hidden";
	cVisible = "visible";

	mousexpos = "window.event.clientX + document.body.scrollLeft";
	mouseypos = "window.event.clientY + document.body.scrollTop";
}

function rl() {
	var obj;

 	if (browser.nav4) {
		obj = dl[arguments[0]];
		for (var i = 1 ; i < arguments.length ; i++) {
			obj = obj.document.layers[arguments[i]];
		}
	}
	if (browser.nav5up || browser.ie4up) obj = document.getElementById(arguments[arguments.length-1]);
	return obj;
}

function writeLayer(obj,content) {
	if (browser.nav4) {
		obj.document.open();
		obj.document.write(content);
		obj.document.close();
	}
	if (browser.ie4up) {
		obj.innerHTML = content;
	}
}

function clipLayer(obj,x,y,width,height) {
	var bottom = y+height;
	var right = x+width;
	if (browser.nav4) {
		obj.clip.top = y;
		obj.clip.left = x;
		obj.clip.bottom = bottom;
		obj.clip.right = right;
	}
	if (browser.ie4up || browser.nav5up) {
		obj.style.clip = 'rect('+y+'px,'+right+'px,'+bottom+'px,'+x+'px)';
	}
}

function setChildImage(obj,iname,src) {
	if (browser.nav4)obj.document.images[iname].src = src;
	if (browser.ie4)document.images(iname).src = src;
	if (browser.nav5up || browser.ie5up) {
		for (var i=0; i < obj.childNodes.length; i++) {
			if (obj.childNodes[i].name == iname) obj.childNodes[i].src = src;
		}
	}
}

function setObjPos(obj, x, y, units, fn) {

	if (!units) units = "px";
	if (browser.nav4) {
		obj.left = x;
		obj.top = y;
	} else {
    	obj.style.left = x + "" + units;
    	obj.style.top = y + "" + units;
	}
	if (fn) eval(fn+";");
}

function getObjLeft(obj)
{
	return (browser.nav4 ? obj.left : (browser.nav5up  || browser.ie4up) ? parseInt(obj.offsetLeft) : obj.style.pixelLeft)
}
function getObjTop(obj)
{
	return (browser.nav4 ? obj.top : (browser.nav5up || browser.ie4up) ? parseInt(obj.offsetTop) : obj.style.pixelTop)
}
function getObjWidth(obj)
{
	return (browser.nav4 ? obj.clip.width : (browser.nav5up || browser.ie4up) ? parseInt(obj.offsetWidth) : obj.style.pixelWidth)
}
function getObjHeight(obj)
{
	return (browser.nav4 ? obj.clip.height : (browser.nav5up || browser.ie4up) ? parseInt(obj.offsetHeight) : obj.style.pixelHeight)
}
function getObjcliWidth(obj)
{
	return (browser.nav4 ? obj.clip.width : (browser.nav5up || browser.ie4up) ? parseInt(obj.offsetWidth) : obj.clientWidth)
}

function setObjWidth(obj,width)
{
	if (browser.nav4)
		obj.clip.width = width
	else
		obj.style.pixelWidth = width
}

function setObjHeight(obj,height) {if (browser.nav4) {obj.clip.height = height} else {obj.style.pixelHeight = height}}
function getObjMiddleX(obj) {return (browser.nav4 ? obj.left+obj.clip.width / 2 : getObjLeft(obj)+getObjWidth(obj) / 2)}
function getObjMiddleY(obj) {return (browser.nav4 ? obj.top+obj.clip.height / 2 : getObjTop(obj)+getObjHeight(obj) / 2)}
function getObjID(obj) {return(browser.nav4 ? obj.name : obj.id)}
function showObj(obj,fn) {if (browser.nav4) {obj.visibility = "show";} else {obj.style.visibility = "visible";}if (fn) eval(fn+";");}
function hideObj(obj,fn) {if (browser.nav4) {obj.visibility = "hide";} else {obj.style.visibility = "hidden";}if (fn)	eval(fn+";");}

function scrHeight(){return screen.height;}
function scrWidth(){return screen.width;}
function scrAvailHeight(){return screen.availHeight;}
function scrAvailWidth(){return screen.availWidth;}
function scrColorDepth() {return screen.colorDepth;}

function cliInnerHeight(wobj) {return (browser.nav4up ? wobj.innerHeight : wobj.document.body.clientHeight)}
function cliInnerWidth(wobj) {return (browser.nav4up ? wobj.innerWidth : wobj.document.body.clientWidth)}

function preLoadImages(d)
{
  loadImages();
  loadBackground(d);
}

function insertGfx(d)
{
  setBodyColor(d);
  insertJondalLogo(d);
  insertNavigation(d);
}

function positionGfx(d)
{
  positionImages(d);
}

function positionBackgroundHigh(d)
{
  insertBackgroundHigh(d);
  showBackgroundHigh(d);
}

function insertPageTitle(d,t)
{
  var h='<div id="layerBackgroundTitle">&LT; ';
  for (var i=0;i<t.length;i++)
    h += t.substr(i,1) + " ";
  h+=" &GT;</div>";
  d.write(h);
}

function glowArrows(l,r)
{
  // if one of both arrows is available and the mouse wasn't over it yet
  if ((l || r) && !mouseWasOverArrows)
  {
    // left arrow available?
    if (l)
      window.setTimeout("glowArrow(LINKS)",myRandom(MINMSBEFOREGLOW,MAXMSBEFOREGLOW));

    // same for the right one
    if (r)
      window.setTimeout("glowArrow(RECHTS)",myRandom(MINMSBEFOREGLOW,MAXMSBEFOREGLOW));

    // repeat the whole thing after a while
    window.setTimeout("glowArrows('"+l+"','"+r+"')",MAXMSBEFOREGLOW + MAXMSGLOWTIME);
  }
}

// let the arrows glow to show there is something to click
function glowArrow(p)
{
  window.setTimeout("dimArrow("+p+")",myRandom(MINMSGLOWTIME,MAXMSGLOWTIME));
  hellPfeil('pfeilImg'+p,p);
}

function dimArrow(p)
{
  // if the mouse isn't over the img right now, dim it
  if (!mouseIsOverArrows[p])
    dunkelPfeil('pfeilImg'+p,p);
}

function glowNavigations()
{
  if (!mouseWasOverNavigation)
  {
    window.setTimeout("glowNavigation("+myRandom(0,numPages-1)+")",myRandom(MINMSBEFOREGLOW,MAXMSBEFOREGLOW));

    // repeat the whole thing after a while
    window.setTimeout("glowNavigations()",MAXMSBEFOREGLOW + MAXMSGLOWTIME);
  }
}

// let the arrows glow to show there is something to click
function glowNavigation(n)
{
  window.setTimeout("dimNavigation("+n+")",myRandom(MINMSGLOWTIME,MAXMSGLOWTIME));
  hell('navImg'+n,n);
}

function dimNavigation(n)
{
  // if the mouse isn't over the img right now, dim it
  if (!mouseIsOverNavigation[n])
    dunkel('navImg'+n,n);
}

function insertCopyright(doc)
{
	var today = new Date();
	var copyright = '<div id="layerCopyright">&copy; 2002-'+today.getFullYear()+' B+R Productions &amp; <a class="l" href="mailto:jondal@dj-jondal.de">DJ Jondal</a> - <a class="l" href="contact.html" target="_top">Impressum</a></div>';

	doc.write(copyright);
	
	insertLinksMenu(doc);
}

function insertLinksMenu(doc)
{
	var links = '<div id="layerLinksMenu">';
	links += '<table border=0 width=100%><tr>';
	links += '<td width=20% align=center><a class="lm" href="' + pageBio.link + '" target="_self">' + pageBio.menutext + '</a></td><td>.</td>';
	links += '<td width=20% align=center><a class="lm" href="' + pageDisco.link + '" target="_self">' + pageDisco.menutext + '</a></td><td>.</td>';
	links += '<td width=20% align=center><a class="lm" href="' + pageGallery.link + '" target="_self">' + pageGallery.menutext + '</a></td><td>.</td>';
	links += '<td width=20% align=center><a class="lm" href="' + pageLinks.link + '" target="_self">' + pageLinks.menutext + '</a></td><td>.</td>';
	links += '<td width=20% align=center><a class="lm" href="' + pageContact.link + '" target="_self">' + pageContact.menutext + '</a></td>';
	links += '</tr></table></div>';

	doc.write(links);
}

if (/Mozilla\/5\.0/.test(navigator.userAgent))
 document.write('<script type="text/javascript" src="mozInnerHTML.js"></sc' + 'ript>');
