// New Functions - www.Cyber-Web.biz 2009
// Don't eat my functions AntiCopyRight by vidar the wizard


// GLOBALS
function updateSize() {//user has resized window
	browserW = browserWidth();
	browserH = browserHeight();
	
		for (var t = 0; t < countObj; t++) {// update Ypos for all objects
			object[t].y = browserH - object[t].h;
			document.getElementById("id"+t).style.top = object[t].y;
	}

}

function hide(layer) { document.getElementById(layer).style.visibility= "hidden"  }
function show(layer) { document.getElementById(layer).style.visibility="visible"; }


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;
}


var browserW = browserWidth();
var browserH = browserHeight();


// OBJECT
function obj(content,x,y,w,h) {
	this.content = content;
	this.x = x;
	this.y = y;
	this.w = w;
	this.h = h;
	
	var oDiv = document.createElement ("DIV");
	oDiv.id = "id"+countObj;
	oDiv.style.position = "absolute";
	oDiv.style.left=x;
	oDiv.style.top=y;
	oDiv.style.width = w;
	oDiv.style.height= h;
	oDiv.innerHTML=content;
	document.body.appendChild(oDiv);
	delete oDiv;
	countObj++;
}


function run() {
	
	
	object[0].x++;object[1].x++;// Clouds
	object[2].x-=1;object[3].x-=1;// City
	object[4].x-=2;object[5].x-=2;// Houses
	
	// If Statements
	if (object[0].x>browserW) object[0].x = object[1].x-object[0].w;
	 else if (object[1].x>browserW) object[1].x = object[0].x-object[1].w;
	 
	if (object[2].x<-object[2].w) object[2].x = object[3].x + object[3].w;
	 else if (object[3].x<-object[3].w) object[3].x = object[2].x + object[2].w;
	
	if (object[4].x<-object[4].w) object[4].x = object[5].x + object[5].w;
	 else if (object[5].x<-object[5].w) object[5].x = object[4].x + object[4].w;
	 
	for (var t = 0; t < countObj; t++) {// Loop all obj to move
		document.getElementById("id"+t).style.left = object[t].x;
	}
}



// Global variables
var delay = 160;
var countObj = 0;
var object = new Array();


	
	if (screen.width<1025) {
		object[0] = new obj('<img src="images3/clouds.gif">',0,browserH-366,1024,366); // Clouds
		object[1] = new obj('<img src="images3/clouds.gif">',-1024,browserH-366,1024,366);
	
		object[2] = new obj('<img src="images3/city.gif">',0,browserH-193,1024,193); // City
		object[3] = new obj('<img src="images3/city.gif">',1024,browserH-193,1024,193);
		
		object[4] = new obj('<img src="images3/house.gif">',0,browserH-67,1024,67); // Houses
		object[5] = new obj('<img src="images3/house.gif">',1024,browserH-67,1024,67);
	
	} else {//makes the divs double horizontal size for really large resolutions
		object[0] = new obj('<img src="images3/clouds.gif"><img src="images3/clouds.gif">',0,browserH-366,2048,366); // Clouds
		object[1] = new obj('<img src="images3/clouds.gif"><img src="images3/clouds.gif">',-2048,browserH-366,2048,366);
		
		object[2] = new obj('<img src="images3/city.gif"><img src="images3/city.gif">',0,browserH-193,2048,193); // City
		object[3] = new obj('<img src="images3/city.gif"><img src="images3/city.gif">',2048,browserH-193,2048,193);
		
		object[4] = new obj('<img src="images3/house.gif"><img src="images3/house.gif">',0,browserH-67,2048,67); // Houses
		object[5] = new obj('<img src="images3/house.gif"><img src="images3/house.gif">',2048,browserH-67,2048,67);		
		
	}
	

var runID = setInterval(run,delay);




