//==============================================================================
// Author:	Sheldon Zhou
// Purpose:	2.5D interface testing that is faked by moving layers
// Time:	Fri Dec 11, 2009
// Used in:	Blog themes
//==============================================================================


//=== Devolved functions
//document.observe("dom:loaded", OnStart);					//when HTML loaded
//window.addEventListener("DOMContentLoaded", OnStart, true);			//Mozilla special events, triggled when text content loaded
//document.observe("mousemove", DocOnMouseMove);					//mouse move event
//document.observe("resize", OnResize);						//resize event

//=== Private properties
var win_h = 0;									//inner window height
var win_w = 0; 									//inner window width

var mouse_l = 0;								//mouse position, left
var mouse_t = 0;								//mouse position, top

var mc_vector_x = 0;								//bias between mouse and center of the screen, x weight
var mc_vector_y = 0;								//bias between mouse and center of the screen, y weight

var div_background_id = "";							//id of background div, need to be speicification

//=== Code Block - upper behavior
function PlaceBackground()
{
	CalculateMoveStepForBackground();
}

function PlaceMessageBox()
{
	CalculateMoveStepForHintBox();
}
//=== Code Block

//=== Code Block - lower behavior
function DifineBackgroundBox(bid)
{
	div_background_id = bid;
}
//=== Code Block

//=== Code Block - Draw on the screen
function MoveBackgroundImage(eid, x, y)						//move background image in a certained container
{
	var temp_pos = parseInt(x).toString() + "px " + 
		parseInt(y).toString() + "px";
	$(div_background_id).style.backgroundPosition = temp_pos;		//let us do it
}
parseFloat
function MoveBoxPosition(eid, x, y)						//move a certained container
{
	$(eid).style.left = parseInt(x).toString() + "px";
	$(eid).style.top = parseInt(y).toString() + "px";
}
//=== Code Block

//=== Code Block - Let us do some MATH !!
function CalculateMoveStepForBackground()					//calculate the distans for the back ground
{
	var vec = new Array();
	vec = CalculateMoveSteps(10.0, 1.0);
	MoveBackgroundImage("full_box", vec[0], vec[1]);			//real work
}

function CalculateMoveStepForHintBox()						//calculate the distans for the message box
{
	var vec = new Array();
	vec = CalculateMoveSteps(20.0, -1.0);
	MoveBoxPosition("fb_message_box", vec[0], vec[1]);			//real work
}

function CalculateMoveSteps(m, d)						//Generic method for calculating steps
{
	m = typeof(m) != 'undefined' ? m : 20.0;				//workaround for no build-in default value support for, maximun size of step
	d = typeof(d) != 'undefined' ? d : 1;					//workaround for no build-in default value support for, and direction
	
	var step_x = parseFloat(m) * mc_vector_x / (win_w / 2.0) * d;			//figure out step x
	var step_y = parseFloat(m) * mc_vector_y / (win_h / 2.0) * d;			//figure out step y
	
	var vec_step = new Array(2);
	vec_step[0] = step_x;
	vec_step[1] = step_y;
	return vec_step;
	
}
//=== Code Block

//=== Code Block - Answer the events
function OnStart()								//when the session start
{
	GetClientWindowSize();							//get client window size
	//UpdatePropertiesToBrowser();
	//UpdatePropertiesToBrowser();
}

function OnResize()								//when the window resized
{
	GetClientWindowSize();
}

function DocOnMouseMove(e)							//when mouse moves
{
	GetMousePosition(e);
	GetBiasBetweenCentralAndMouse();
	PlaceBackground();
	//PlaceMessageBox();						
	//UpdatePropertiesToBrowser();
	return true;
}
//=== Code Block

//=== Code Block - Write information to the browser
function UpdatePropertiesToBrowser()
{
	//var omb = document.getElementById('fb_message_box');
	//omb.textContent = "ws: " + win_w.toString() + ", " + win_h.toString();
	$("fb_message_box").textContent = "ws: " + win_w.toString() + ", " + 
		win_h.toString() + " | mp: " + mouse_l.toString() + ", " +
		mouse_t.toString();						//update information to page
}

function UpdatePropertiesToBrowserWithText(text)
{
	//var omb = document.getElementById('fb_message_box');
	//omb.textContent = "ws: " + win_w.toString() + ", " + win_h.toStUpdatePropertiesToBrowser();ring();
	$("fb_message_box").textContent = text;
}
//===

//=== Code Block - Get information from the browser
function GetClientWindowSize()							//get client window size
{
	win_h = window.innerHeight;
	win_w = window.innerWidth;
}

function GetBiasBetweenCentralAndMouse()					//calculate bias vector for mouse position
{
	var center_x = win_w / 2.0;						
	var center_y = win_h / 2.0;						//find out center position
	
	mc_vector_x = mouse_l - center_x;
	mc_vector_y = mouse_t - center_y;					//find out bias 
}

function GetMousePosition(e)							//get mouse position to the document
{
	mouse_l = Event.pointerX(e);
	mouse_t = Event.pointerY(e);

	//mouse_l = e.pageX;
	//mouse_t = e.pageY;
}
//=== Code Block 
