/*



		                       __                                                __     
		                      /\ \                  __                          /\ \    
		  ___ ___      __     \_\ \      __  __  __/\_\  ____      __     _ __  \_\ \    ____  
		/' __` __`\  /'__`\   /'_` \    /\ \/\ \/\ \/\ \/\_ ,`\  /'__`\  /\`'__\/'_` \  /',__\ 
		/\ \/\ \/\ \/\ \_\.\_/\ \_\ \   \ \ \_/ \_/ \ \ \/_/  /_/\ \_\.\_\ \ \//\ \_\ \/\__, `\
		\ \_\ \_\ \_\ \__/.\_\ \___,_\   \ \___¤___/'\ \_\/\____\ \__/.\_\\ \_\\ \___,_\/\____/
		 \/_/\/_/\/_/\/__/\/_/\/__,_ /    \/__//__/   \/_/\/____/\/__/\/_/ \/_/ \/__,_ /\/___/ 
  <=======[http://MadWizards.net 2004-2006]=================[Code:Vidar Larsen]===========>




*/

//window.onerror = stopError;
/************[This function stop most errors when enabled]********/
function stopError(msg, url, lno) { 
	//alert(msg+"  "+url+"  "+lno);
	return true; 
}//	(S)Smart solutions international::.

function error(message) {
	buff=' last active object = '+this.name;
	buff+=message;
	 alert(buff);
	return true;
}



ns6 = document.getElementById;
ns  = document.layers;
ie  = document.all;
                


var gameSpeed=20;
var activeLevel=1;
var scrlX=0;
var scrlY=0;


/*******************[AccessCSS]***********************************/
function accessCSS(layerID)	{    																//
  if(ns6){ return document.getElementById(layerID).style;}     //
   else if(ie){ return document.all[layerID].style; }         //
    else if(ns){ return document.layers[layerID]; }          //
}/***********************************************************/





/**************************[move Layer]*************************************/
function move(layer,x,y)  { accessCSS(layer).left=x; accessCSS(layer).top = y; } 

function moveRelative(layer,x,y)  { 
	accessCSS(layer).left+=x; //does it work ??
	accessCSS(layer).top += y;
	
	 
} 


//=============[fast imageResize for internetExplorer]-------------------------------,
function resize(imgnm,x,y) { accessCSS(imgnm).width=x;accessCSS(imgnm).height=y; } //
//________________________________________________________________________________//



//>==================[CrossBrowser resize for all browsers]==============================-,
	function crossResize(layer,imgnm,x,y) {						//
 	newContent(layer,'<img src="'+imgnm+'" width="'+x+'" height="'+y+'">');}       //
//____________________________________________________________________________________//


//>~~~~<[Change content of layer]>~~~~~~~~~~~~~~~~~~~~>
function newContent(layernm,content) { 
	if (ns6) document.getElementById(layernm).innerHTML=content;
	else if (ie) document.all[layernm].innerHTML=content;
	else if (ns) {					
    eval('  document.layers["'+layernm+'"].document.open();');			
    eval("  document.layers['"+layernm+"'].document.write('"+content+"');");     
    eval('  document.layers["'+layernm+'"].document.close();');		     
  } 
}

function addContent(layernm,content) {if (ns6) { document.getElementById(layernm).innerHTML+=content; } }
function loadFrameIntoDiv(frameNm,layerNm) {
	document.getElementById(layerNm).innerHTML=window.frames[frameNm].document.body.innerHTML;
}



function scrollWindow(x,y) {
	//gamewindow.scrollTo(x,y);
	gamewindow.scrollTop = y;
		gamewindow.scrollLeft = x;
}

function randomize(maxNumber) { var r=Math.random()*maxNumber; r=Math.floor(r); return r; }
function scrollWindowLeft(howMuch) {	window.scrollBy(howMuch,0); }
function scrollWindowRight(howMuch) {	window.scrollBy(-howMuch,0); }
function setBgColor(layernm,bcol) {if (document.layers) accessCSS(layernm).bgColor=bcol;else accessCSS(layernm).backgroundColor=bcol;}
function setHeight(layernm,nyHoyde) {	accessCSS(layernm).height=nyHoyde; }
function setWidth(layernm,nyBredde) {	accessCSS(layernm).width=nyBredde; }
function setZ(layer,zNR) { accessCSS(layer).zIndex=zNR; }
function hide(layer) { accessCSS(layer).visibility= "hidden"  }
function show(layer) { if (ns) accessCSS(layer).visibility="show";else accessCSS(layer).visibility="visible"; }
function setAlpha(layername,filterCount) { eval(' accessCSS("'+layername+'").filter="alpha(opacity='+filterCount+')";   ');}
function mouseUp(){}
function setOverflow(layernm,scrollit) { accessCSS(layernm).overflow=scrollit; }
function setBodyBGcolor(color) {document.bgColor=color;}
function wr(stringToWrite) {document.write(stringToWrite);}
function setBodyBackground(imgNm) { if (document.body) document.body.background = imgNm; }

function makeDiv(objName,parentDiv,w,h,content,x,y,overfl,positionType)
{	  
	  // positionType could be 'absolute' or 'relative'
	
		if (parentDiv==null) parentDiv='body';

    var oDiv = document.createElement ("DIV");
    oDiv.id = objName;
    
 		if (w) oDiv.style.width = w;
		if (h) oDiv.style.height= h;
		

	  if (content) oDiv.innerHTML=content;
	  if (positionType==null) positionType="absolute";
		oDiv.style.position = positionType;
		if (x) oDiv.style.left=x; else oDiv.style.left=-2000;
		if (y) oDiv.style.top=y; else oDiv.style.top=-2000;


		if (overfl) oDiv.style.overflow=overfl; else oDiv.style.overflow="hidden";
    eval('  document.'+parentDiv+'.appendChild (oDiv);  ');

    delete oDiv;
}

var numberOfBubbles = 17; // change this as you see fit

function bubble(objName, x, y, z) {
    this.name = objName;
    this.x = x;
    this.y = y;
    this.z = z;
    this.count = Math.random(40);
    this.remX = x;
    this.remY = y;
    this.moveUp = moveUp;
    this.loopID = objName + "" + x + "" + y + "" + z;
    makeDiv(objName, x, y, '<img src="images/bubble' + z + '.gif">');
}

function randomizeX() { return randomize((browserWidth() - 40)); }
function randomizeY() { return (browserHeight() - randomize(40) - 40); }

function moveUp() {
    this.count += Math.random() * 10;
    this.y -= this.z;
    this.x += (Math.cos(this.count));
    if (this.y < -20) { this.y = randomizeY(); this.x = randomizeX(); }
    move(this.name, this.x, this.y);
}


// have to do it like this so it wont get look bad in FireFox
function startBubbles(nmCount) {
    if (nmCount < numberOfBubbles) {
        //alert("1");
        var bubbleNm = "bubble" + nmCount;
        var ranX = randomizeX();
        var ranY = randomizeY();
        var ranZ = randomize(3);
        eval(bubbleNm + ' = new bubble("' + bubbleNm + '",ranX,ranY,ranZ);  ');
        eval(bubbleNm + '.loopID = setInterval("' + bubbleNm + '.moveUp();",20);  ');
        nmCount++;
        setTimeout('startBubbles(' + nmCount + ');', 300);
    }
}

function makeDiv(objName, x, y, content, w, h, overfl, parentDiv) {
    if (parentDiv == null) parentDiv = 'body';
    var oDiv = document.createElement("DIV");
    oDiv.id = objName;
    if (w) oDiv.style.width = w;
    if (h) oDiv.style.height = h;
    if (content) oDiv.innerHTML = content;
    oDiv.style.position = "absolute";
    if (x) oDiv.style.left = x; else oDiv.style.left = -2000;
    if (y) oDiv.style.top = y; else oDiv.style.top = -2000;
    if (overfl) oDiv.style.overflow = overfl; else oDiv.style.overflow = "hidden";
    eval('  document.' + parentDiv + '.appendChild (oDiv);  ');
    delete oDiv;
}

function browserWidth() {
    if (window.innerWidth) return window.innerWidth;
    else if (document.body.clientWidth) return document.body.clientWidth;
    else return 1024;
}

function browserHeight() {

    if (window.innerHeight) return window.innerHeight;
    else if (document.body.clientHeight) return document.body.clientHeight;
    else return 800;
}
function randomize(maxNumber) { var r = Math.random() * maxNumber; r = Math.floor(r); return (r + 1); }
