/* 
Author Cesar Quinteros, http://quinterox.com, May 2009
Usage: this script makes a box fall from the top of the browser window and stop in the middle of the screen
*/


function fallingObjApp() {
	
	var incrementVal;
	var timer;
	var object;
	
	this.init = function() {
		// set speed of animation
		this.incrementVal = 2;
		// make timer variable
		this.timer;
		// select object
		this.object = document.getElementById("ad_container");
		// detect browser less than ie6
		this.IE6 = (document.documentElement.clientHeight)? true : false;		
	}	
	this.hAlign = function() {		
		// get width of the object
		this.objectWidth = parseInt(this.object.offsetWidth);
		// get current browser window width
		this.windowWidth = parseInt((this.IE6) ? document.documentElement.clientWidth : (document.all) ? document.body.clientWidth : window.innerWidth);

		// figure out the middle of the screen
		this.X = (this.windowWidth / 2) - (this.objectWidth / 2);

		// place object in the middle of the screen (left to right)
		this.object.style.left = this.X +"px";
	}
	this.vScroll = function() {	    
		//get the height of the object
		this.objectHeight = parseInt(this.object.offsetHeight);		

		// get the top location of the object
	   	this.Y = parseInt( this.object.style.top );

		// get the client screen height
		this.stoppingPoint = ((parseInt((this.IE6) ? document.documentElement.clientHeight : (document.all) ? document.body.clientHeight : window.innerHeight)) / 2) - (this.objectHeight / 2);
 

		// if there is space between the current objectect location and the 
		if( this.Y/.02 < this.stoppingPoint ){
			this.object.style.top = ( this.Y + this.incrementVal ) + "px";
		    this.timer = setTimeout("fallingObjApp.vScroll()",this.incrementVal);
	    } else {
		   	clearTimeout(this.timer);
	    }
    }
	this.close = function() {
		this.object.style.visibility = "hidden";
	}
}

