// JavaScript Document

var mClouds = null;   // array of Explosions
 
	function CloudsInitialize()
	{
		mClouds = new Array();			
 
		var height = parseInt(window.document.getElementById("textlast").style.top);
		deltatop = parseInt(height / (14 * 3 - 1));
		// if (deltatop < 600) { deltatop = 600; }
 
		/*
		var index = 0, left = 0, top = 0;
		top = -700 + parseInt(Math.random() * 400);
		while ((index < 14 * 3) && (top < height)) {
			left = -250 + parseInt(Math.random() * gBrowser.width);
			top += deltatop + (-100 + parseInt(Math.random() * 200)); // 600 + parseInt(Math.random() * 200);
 
 
		
			mClouds[index] = new Cloud(index);
			mClouds[index].Initialize(left, top);
			
			index++;
		}
		*/
 
		var left = 0, top = 0;
		var maxheight = 1000;
		var l = window.document.getElementById("textlast");
		if (l != null) {	maxheight = parseInt(l.style.top); }
 
		for (index = 0; index < 12; index++) {
			left = -250 + parseInt(Math.random() * gBrowser.width);
			top = -200 + parseInt(Math.random() * (maxheight + 200));
			mClouds[index] = new Cloud(index);
			mClouds[index].Initialize(left, top);
		}
 
	}
 
	function CloudsMove()
	{
		// for (var i = 0; i < 1; i++) {			
		for (var i = 0; i < mClouds.length; i++) {			
			mClouds[i].Movez();
		}	
	}
	
	
	
	function Cloud(pID) {
		this.id = parseInt(pID);
		this.left = parseFloat(0);
		this.top = parseFloat(0);
		this.speed_left = parseFloat(0);
		this.speed_top = parseFloat(0);
		this.imagez = null;
		
		this.Initialize = function (pleft, ptop) {
			this.left = pleft;
			this.top = ptop;
			this.speed_left = .5 + parseInt(Math.random() * 2.0) * 0.5;  // 3 slower speeds are great .5, 1.0 and 1.5. all blowing the same way looks great
			this.imagez = window.document.getElementById("Cloud" + this.id);
			this.imagez.style.left = this.left;
			this.imagez.style.top = this.top;
		}
		
		this.Movez = function() {
			this.left += this.speed_left;
			if ((this.speed_left > 0) && (this.left > gBrowser.width)) {
				this.left = -this.imagez.width - 100;
				this.speed_left = 0.5 + parseInt(Math.random() * 6.0) / (4.0);
			} else if ((this.speed_left < 0) && (this.left < -this.imagez.width - 100)) {
				this.left = gBrowser.width + 10;
				this.speed_left = -(.4 + (Math.random() * .6))
			}
	    	this.imagez.style.left = this.left;
		}
	}	
 
	var show = false;
 
	function toggle_all(pthis) {
		var value = "";
		var img = null;
 
		if (show) {
			value = "none";
			document.getElementById('toggle').innerHTML="Director's Cut";
		} else {
			value = "block";
			document.getElementById('toggle').innerHTML="Standard Edition";
		}
 
		var divs = document.getElementsByTagName("div"); 	
		for (var i = 0; i < divs.length; i++) {
			if ((divs[i].id) && (divs[i].id.toLowerCase() == "container")) {
				img = divs[i].getElementsByTagName("img"); 	
				if (img.length != 0) {
					var e = divs[i].getElementsByTagName("DIV")[0];
					e.style.display = value;
				}
			}
		}
		world_onresize();
 
		show = !show;
	}
	
	function toggle_text(pthis) {
		if (document) {
			var e = pthis.parentNode.getElementsByTagName("DIV")[0];
			if (e.style.display == "block") { e.style.display = "none"; } else { e.style.display = "block"; }			
			world_onresize();
		}
	}
 
	
	function world_onresize()
	{
		var img = null;
		var left = 10, top = 10;
		var maxwidth = 850, deltaleft = 0;
		var style = 0; // 0 = left, 1 = right, 2 = center
		
		var currentwidth = 0;
 
		deltaleft = (gBrowser.width - maxwidth) / 2; if (deltaleft < 0) { deltaleft = 0; }
				
		var divs = document.getElementsByTagName("div"); 	
		for (var i = 0; i < divs.length; i++) {
			if ((divs[i].id) && (divs[i].id.toLowerCase() == "container")) {
				img = divs[i].getElementsByTagName("img"); 	
				if (img.length != 0) { divs[i].style.width = img[0].width; }
 
				if (img.length == 0) {
					left = deltaleft + (maxwidth - divs[i].offsetWidth) / 2;
					style++;
				} else {			
					if (style == 0) {
						left = deltaleft + 10;
					} else if ((style == 1) || (style == 3)) {					
						left = deltaleft + parseInt((maxwidth - img[0].width) / 2);
					} else {
						left = deltaleft + (maxwidth - img[0].width - 10);
					}
				}
				divs[i].style.left = left;
				divs[i].style.top = top;								
				
				divs[i].style.visibility = "visible";
				top += divs[i].offsetHeight + 50;
				style++; if (style > 3) { style = 0; }
			}
		}
 
		var l = window.document.getElementById("textlast");
		if (l != null) {				
			l.style.left = 0; l.style.top = top; l.style.width = 1; l.style.height=1;
		}		
	
		var l = window.document.getElementById("world");
		l.style.left = 0; l.style.top = 0; l.style.width = "100%"; l.style.height=top + 200;	
		
		
		if((x==0) || (x==1) || (x==3))
		{
		document.getElementById("ryanbg").style.top=((gBrowser.height/2) - 75);
		document.getElementById("ryanbg").style.left=((gBrowser.width/2) - 75);
		document.getElementById("ryanbox").style.top=((gBrowser.height/2) - 75);
		document.getElementById("ryanbox").style.left=((gBrowser.width/2) - 75);
		}
		else if(x==2)
		{
		document.getElementById("aboutbg").style.top=((gBrowser.height/2) - 150);
		document.getElementById("aboutbg").style.left=((gBrowser.width/2) - 150);
		document.getElementById("aboutbox").style.top=((gBrowser.height/2) - 150);
		document.getElementById("aboutbox").style.left=((gBrowser.width/2) - 150);
		}
		else if(x==3)
		{
		document.getElementById("ryanbg").style.top=((gBrowser.height/2) - 75);
		document.getElementById("ryanbg").style.left=((gBrowser.width/2) - 75);
		document.getElementById("ryanbox").style.top=((gBrowser.height/2) - 75);
		document.getElementById("ryanbox").style.left=((gBrowser.width/2) - 75);
		}
		else if(x>=9)
		{
		document.getElementById("researchbg1").style.top=((gBrowser.height/2) - 200);
		document.getElementById("researchbg1").style.left=((gBrowser.width/2) - 350);
		document.getElementById("researchbg2").style.top=((gBrowser.height/2) - 200);
		document.getElementById("researchbg2").style.left=((gBrowser.width/2) + 100);
		document.getElementById("researchbox1").style.top=((gBrowser.height/2) - 200);
		document.getElementById("researchbox1").style.left=((gBrowser.width/2) - 350);
		document.getElementById("researchbox2").style.top=((gBrowser.height/2) - 200);
		document.getElementById("researchbox2").style.left=((gBrowser.width/2) + 100);
		}	
			
	}
 
	function world_onload()
	{		
		world_onresize();
		CloudsInitialize();
		world_ontimer();
 
		/*
		var body = document.getElementsByTagName("body").item(0);
        alert(body.offsetWidth + " : " + body.offsetHeight);
		*/
 
		/*
		var d = window.document.getElementById("world"); 
		alert("hey offset:" + d.offsetWidth + " " + d.offsetHeight);
		alert("hey inner:" + d.innerWidth + " " + d.innerHeight);
		alert("hey client:" + d.clientWidth + " " + d.clientHeight);
		alert("hey documentelement.client:" + document.documentElement.clientWidth + " " + document.documentElement.clientHeight);
		alert("hey body" + document.body.clientWidth + " " + document.body.clientHeight);
		alert("hey:" + d.width + " " + d.height);
		*/	
	}
 
	function world_ontimer() {
		if ((window.document) && (mClouds))
		{
			CloudsMove();
			
		}	
		window.setTimeout("world_ontimer();", 30);
	}
	
	
	function ryan_initialize() {
		var r = 0;		
 
		var html = "";
		html += "<DIV ID='textlast' style='position:absolute; width:1px; height:1px; margin:0px; padding:0px;'>&nbsp;</DIV>"
 
		html += "<DIV ID='world' Style='position:absolute; left:-1px; top:-1px; width:1; height:1; overflow:hidden;z-index:5px;background:url(http://www.ryanmcgrady.com/backgroundcloud.jpg)'>";
		
		var toggle = "";
		for (var i = 0; i < (14 * 3); i++) {
			r = Math.random();
 
			// Cloud3 needs to be redone
			if (r < .15) {
				html += "<IMG ID='Cloud" + i + "' Src='http://www.ryanmcgrady.com/cloudb.gif' width=683 height=232 Style='position:absolute; left:-1500px; top:0px;'>";
			} else if (r < .3) {
				html += "<IMG ID='Cloud" + i + "' Src='http://www.ryanmcgrady.com/cloud2b.gif' width=465 height=465 Style='position:absolute; left:-1500px; top:0px;'>";			
			} else if (r < .65) {
				html += "<IMG ID='Cloud" + i + "' Src='http://www.ryanmcgrady.com/cloud3b.gif' width=836 height=566 Style='position:absolute; left:-1500px; top:0px;'>";
			} else if (r < 1) {
				html += "<IMG ID='Cloud" + i + "' Src='http://www.ryanmcgrady.com/cloud4b.gif' width=631 height=366 Style='position:absolute; left:-1500px; top:0px;'>";
			}
			
			
		}
		html += "</DIV>";
		
		document.write(html);
 
		addLoadEvent(world_onload);	
		addResizeEvent(world_onresize);
	}
	ryan_initialize();
