if (typeof(BigEar) != "object") {var BigEar = new MasterListener();}

var debug = false;

var tweenTimers = new Array();       // array for timers
var tweenObjects = new Array();      // array for tweens
var resizeDelay = 200;           // ms
var moveDuration = 1;            // move time in seconds

function centerObj_init(objID,slideInit,minX,minY,persist) {

	if (persist != true && persist != false) {
		persist = true;
	}

	tw_init(objID,minX,minY);

	if (persist) {
		BigEar.addAction("tw_tryCenterObject('"+objID+"')",0);
	}

	if (slideInit !== true) {
		tw_tryCenterObject(objID);
	} else {
		tw_centerObjectNow(objID);
	}

}


function fullHeightObj_init(objID) {
	BigEar.addAction("fullHeightObject('"+objID+"')",0);
	var sizeArray = getPageSize();
	$('#'+objID).height(getScrollTop() + sizeArray[3]);
}


function fullsizeObj_init(objID) {
	BigEar.addAction("fullsizeObject('"+objID+"')",0);
	var sizeArray = getPageSize();
	$('#'+objID).width(sizeArray[0]);
	$('#'+objID).height(getScrollTop() + sizeArray[3]);
}

function centerObj_destruct(objID) {
	try {
		BigEar.removeAction("tw_tryCenterObject('"+objID+"')",0);
	} catch (e) {
		// Couldn't clear	
	}
	tweenObjects[objID] = null;
	tweenTimers[objID] = null;
}


/**
 * Tweening Wrapper Functions
 * @ Avery Brooks 2007
 */
function tw_init(objID,minX,minY) {

	tweenObjects[objID] = Array();

	if (minX) {
		tweenObjects[objID]['minX'] = minX;
	} else {
		tweenObjects[objID]['minX'] = 0;
	}

	if (minY) {
		tweenObjects[objID]['minY'] = minY;
	} else {
		tweenObjects[objID]['minY'] = 0;
	}

	content_div = document.getElementById(objID);
	content_div.style.left = getCenterX(objID) + "px";
	content_div.style.top = getCenterY(objID) + "px";

	// tweenObjects[objID]['x'] = new Tween(content_div.style,'left',Tween.backEaseOut,parseInt(content_div.style.left),10,1,'px');
	// tweenObjects[objID]['y'] = new Tween(content_div.style,'top',Tween.backEaseOut,parseInt(content_div.style.top),10,1,'px');

}

/**
 * Get the squishy value for new 'center' X val
 */
function getCenterX (objID) {
	var pageSize = getPageSize();
	var x = getScrollLeft() + (pageSize[2] / 2) - (getObjWidth(objID) / 2);
	if (x < tweenObjects[objID]['minX']) {
		x = tweenObjects[objID]['minX'];
	}
	return x;
}

/**
 * Get the squishy value for new 'center' Y val
 */
function getCenterY (objID) {
	var pageSize = getPageSize();
	var y = getScrollTop() + (pageSize[3] / 2) - (getObjHeight(objID) / 2);
	if (y < tweenObjects[objID]['minY']) {
		y = tweenObjects[objID]['minY'];
	}
	return y;
}

function getObjWidth(objID) {
	if ($('#'+objID).width() == "undefined" || $('#'+objID).width() == null) {
		return 0;
	} else {
		return $('#'+objID).width();
	}
}

function getObjHeight(objID) {
	if ($('#'+objID).height() == "undefined" || $('#'+objID).height() == null) {
		return 0;
	} else {
		return $('#'+objID).height();
	}
}

function tw_centerObjectNow(objID) {
	if (document.getElementById(objID)) {
		content_div = document.getElementById(objID);
		content_div.style.left = getCenterX(objID) + "px";
		content_div.style.top = getCenterY(objID) + "px";
	} else {
		// Couldn't get object!		
	}
}

function tw_centerObject(objID) {
	tw_centerObjectNow(objID);
}

function tw_clearWait(timerID) {
	try {
		clearTimeout(tweenTimers[timerID]);
	} catch (e) {
		// deb(e);
	}
}

function tw_tryCenterObject(obj) {
	tw_clearWait(obj);
	tweenTimers[obj] = setTimeout('tw_centerObject("' + obj + '");',resizeDelay);
}

function fullsizeObject(obj) {
	var sizeArray = getPageSize();
	$('#'+obj).width(sizeArray[0]);
	$('#'+obj).height(getScrollTop() + sizeArray[3]);
}

function fullHeightObject(obj) {
	var sizeArray = getPageSize();
	// $('#'+obj).height(sizeArray[1]);
	$('#'+obj).height(getScrollTop() + sizeArray[3]);
}

/**
 * Quick debug function
 */
function deb(str){
	if (debug) {
		// curObj = document.getElementById('debug_output');
		// curObj.innerHTML += "<p>"+str+"</p>";
		// alert(str);
	}
	return;
}




