var objWidth = 900;
var objHeight = 315;
var offsetY = -20;

var accRate = .9;
var frameRate = 20;

var transitionActive = false;
var somethingHappened = false;
var windowHeightPost;
var windowWidthPost;
var increment;
var dirY;
var dirX;
var boxInitY;
var boxInitX;
var boxDY;
var boxDX;

function animation(id) {
	this.sty = document.getElementById(id).style;
	this.obj = document.getElementById(id);
	this.easeOutTimer = null;
	this.easeInTimer = null;
	this.name = id + "Obj";
	eval(this.name + " = this");
	this.animate = animate;
	this.easeOut = easeOut;
	this.easeIn = easeIn;
}


function animate() {

	boxInitY = parseInt(document.getElementById('flashContainer').style.top);
	windowHeight = (document.all)? document.body.clientHeight : window.innerHeight;
	boxDY = Math.round((windowHeight/2 - objHeight/2)) - boxInitY + offsetY;
	dirY = (boxDY >= 0)? 1:-1;

	boxInitX = parseInt(document.getElementById('flashContainer').style.left);
	windowWidth = (document.all)? document.body.clientWidth : window.innerWidth;
	boxDX = Math.round((windowWidth/2 - objWidth/2)) - boxInitX;
	dirX = (boxDX >= 0)? 1:-1;

	increment = dirY;
	
	this.easeOutTimer = setInterval(this.name + ".easeOut()",frameRate);
}

function easeOut() {

	condition = (dirY > 0)? parseInt(this.sty.top) < boxInitY + boxDY/2 : parseInt(this.sty.top) > boxInitY + boxDY/2;

	increment = increment*(1/accRate);
	if ( condition ) {
		this.sty.top = Math.round(parseInt(this.sty.top) + increment);
		this.sty.left = boxInitX + Math.round((parseInt(this.sty.top) - boxInitY)/boxDY*boxDX);	
	} else {
		clearInterval(this.easeOutTimer);
		this.easeInTimer = setInterval(this.name + ".easeIn()",frameRate);
	}
}

function easeIn() {

	condition = (dirY > 0)? parseInt(this.sty.top) < boxInitY + boxDY : parseInt(this.sty.top) > boxInitY + boxDY;

	increment = increment*accRate;
	if ( condition ) {
		this.sty.top = Math.round(parseInt(this.sty.top) + increment);
		this.sty.left = boxInitX + Math.round((parseInt(this.sty.top) - boxInitY)/boxDY*boxDX);	
	} else {
		//alert("finished easing")
		windowHeightPost = windowHeight;
		windowWidthPost = windowWidth;
		positionFn()
		clearInterval(this.easeInTimer);
	}

}

function checkWindowSize() {
	windowHeight = (document.all)? document.body.clientHeight : window.innerHeight;
	windowWidth = (document.all)? document.body.clientWidth : window.innerWidth;

	if (windowHeightPost != windowHeight || windowWidthPost != windowWidth) {
		
		clearInterval(positionTimer)
		timer = setTimeout("anim1.animate()",1000);
		
	}
}

function init() {
	anim1 = new animation("flashContainer");

	windowHeight = (document.all)? document.body.clientHeight : window.innerHeight;
	windowWidth = (document.all)? document.body.clientWidth : window.innerWidth;
	document.getElementById('flashContainer').style.top = windowHeight/2 - objHeight/2 + offsetY;
	document.getElementById('flashContainer').style.left = windowWidth/2 - objWidth/2;
	document.getElementById('flashContainer').style.display = "block";
	
	windowHeightPost = windowHeight;
	windowWidthPost = windowWidth;
	
	positionFn();

}

function positionFn() {
	positionTimer = setInterval("checkWindowSize()", 100);
}

