// JavaScript Document

/* used for positioning three objects

The main work is done in do_move from which setTimeout is called and in turn calls do_move until object hits x and y limits.
The index is bumped to the next object and do_move is called again until no more objects are left.  The html body event onload calls move(css_class).  In this case class should be 'moving_object'.  Function move calls build_objects(tag, css_class) for tags img and div.  For all matching tags and css_class, the init_object(id, index) is called.  Argument id is the page elements id and index is used for the array indices for the objects width, height, etc.  Object attributes are hardwired in the arrays for each attribute and object.  

// var t = setTimeout("alert('5 seconds!')",5000);
*/
var width_start = new Array();
width_start[0] = 560;	// flag
width_start[1] = 348;	// logo
width_start[2] = 360;	// tagline

var width_end = new Array();
width_end[0] = 216;
width_end[1] = 348;
width_end[2] = 360;

var width_inc = new Array();
width_inc[0] = -12;
width_inc[1] = -18;
width_inc[2] = 0;

var width = new Array();
width[0] = width_start[0];
width[1] = width_start[1];
width[2] = width_start[2];

var height_start = new Array();
height_start[0] = 380;
height_start[1] = 190;
height_start[2] = 100;

var height_end = new Array();
height_end[0] = 146;
height_end[1] = 190;
height_end[2] = 100;

var height_inc = new Array();
height_inc[0] = -8;
height_inc[1] = -10;
height_inc[2] = 0;

var height = new Array();
height[0] = height_start[0];
height[1] = height_start[1];
height[2] = height_start[2];

var opacity = new Array();
opacity[0] = 100;
opacity[1] = 60;
opacity[2] = 20;

var strength = new Array();
strength[0] = 10;
strength[1] = 20;
strength[2] = 40;

var x_start = new Array();
x_start[0] = 100;
x_start[1] = 10;
x_start[2] = 10;

var x_end = new Array();
x_end[0] = 10;
x_end[1] = 600;
x_end[2] = 240;

var x_inc = new Array();
x_inc[0] = -3;
x_inc[1] = 24;
x_inc[2] = 12;

var x_pos = new Array();
x_pos[0] = x_start[0];
x_pos[1] = x_start[1];
x_pos[2] = x_start[2];

var y_start = new Array();
y_start[0] = 100;
y_start[1] = 10;
y_start[2] = 25;

var y_end = new Array();
y_end[0] = 10;
y_end[1] = 10;
y_end[2] = 25;

var y_inc = new Array();
y_inc[0] = -2;
y_inc[1] = -6;
y_inc[2] = -8;

var y_pos = new Array();
y_pos[0] = y_start[0];
y_pos[1] = y_start[1];
y_pos[2] = y_start[2];

var visibility = new Array();
visibility[0] = 'hidden';
visibility[1] = 'hidden';
visibility[2] = 'hidden';

var zIndex_start = new Array();
zIndex_start[0] = 203;
zIndex_start[1] = 199;
zIndex_start[2] = 202;

var zIndex = new Array();
zIndex[0] = zIndex_start[0];
zIndex[1] = zIndex_start[1];
zIndex[2] = zIndex_start[2];

var zIndex_end = new Array();
zIndex_end[0] = 203;
zIndex_end[1] = 0;
zIndex_end[2] = 2;

var tpf = 80; //time per frame [1000 == 1ms.] lower faster higher slower
var fps = 1000/tpf;	// fps (not used)
var index = 0;	// gets bumped by div.moving_object
var last_index = 0;	// gets value of last index
var movable_objects;

function move(css_class) {
	//document.getElementById("content").filters.item("DXImageTransform.Microsoft.MotionBlur").strength = 100;
	build_objects("img", css_class);
	build_objects("div", css_class);
	last_index = index;
	index = 0;
	do_move(index);
}

function build_objects(tag, css_class) {
	movable_objects = document.getElementsByTagName(tag);	// for text objects
	for(var i = 0; i < movable_objects.length; i++) {
		movable_object = movable_objects[i];
		if(movable_object.id != '') {
			if(document.getElementById(movable_object.id).className == css_class) {
				id = document.getElementById(movable_object.id).id;	// such as id "movable_object_0"
				init_object(id, index++);
			}
		}
	}
}

function init_object(id, index) {
	//set_report('id: ', id);
	document.getElementById(id).style.top = y_start[index];	
	document.getElementById(id).style.left = x_start[index];	
	document.getElementById(id).style.width = width_start[index];	
	document.getElementById(id).style.height = height_start[index];	
	//document.getElementById(id).filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity[index];
	document.getElementById(id).style.visibility = visibility[index];	
	document.getElementById(id).style.zIndex = zIndex[index];
}

function do_move(index) {
	// <img id="movable_object_0" class="moving_object" src="...
	var full_id = 'movable_object_'+index;
	//set_report('index: ', index);
	document.getElementById(full_id).style.visibility = 'visible';	
	//set_report(full_id+' visibility: ', document.getElementById(full_id).style.visibility);
	//document.getElementById(full_id).filters.item("DXImageTransform.Microsoft.MotionBlur").strength = strength[id];
	if((x_inc[index] < 0) && (x_pos[index] > x_end[index]) || (x_inc[index] > 0) && (x_pos[index] < x_end[index])) {
		x_pos[index] = x_pos[index] + x_inc[index];
		//set_report(index+ '(x,y): ', '('+x_pos[index] +' <> '+ x_end[index] +', '+ y_pos[index] +' <> '+ y_end[index]+')' );
	}
	if((width_inc[index] < 0) && (width[index] > width_end[index]) || (width_inc[index] > 0) && (width[index] < width_end[index])) {
		width[index] = width[index] + width_inc[index];
		document.getElementById(full_id).style.width = width[index];
		//set_report(index+ '(x,y): ', '('+x_pos[index] +' <> '+ x_end[index] +', '+ y_pos[index] +' <> '+ y_end[index]+')' );
	}
	if((y_inc[index] < 0) && (y_pos[index] > y_end[index]) || (y_inc[index] > 0) && (y_pos[index] < y_end[index])) {
		y_pos[index] = y_pos[index] + y_inc[index];
		//set_report(index+ '(x,y): ', '('+x_pos[index] +' <> '+ x_end[index] +', '+ y_pos[index] +' <> '+ y_end[index]+')' );
	}
	if((height_inc[index] < 0) && (height[index] > height_end[index]) || (height_inc[index] > 0) && (height[index] < height_end[index])) {
		height[index] = height[index] + height_inc[index];
		document.getElementById(full_id).style.height = height[index];
		//set_report(index+ '(x,y): ', '('+x_pos[index] +' <> '+ x_end[index] +', '+ y_pos[index] +' <> '+ y_end[index]+')' );
	}
	// make sure at least one dimension is still moving
	if((x_inc[index] < 0) && (x_pos[index] > x_end[index]) || (x_inc[index] > 0) && (x_pos[index] < x_end[index]) || 
		(y_inc[index] < 0) && (y_pos[index] > y_end[index]) || (y_inc[index] > 0) && (y_pos[index] < y_end[index]))	{
		document.getElementById(full_id).style.left = x_pos[index];	
		document.getElementById(full_id).style.top = y_pos[index];	
		//set_report(full_id+ ' (x,y): ', '('+document.getElementById(full_id).style.left +' <> '+ x_end[index] +', '+ document.getElementById(full_id).style.top +' <> '+ y_end[index]+')' );
		
		var t = setTimeout("do_move('"+index+"')",tpf);	// recursive call
		
	} else {
		//document.getElementById(full_id).filters.item("DXImageTransform.Microsoft.Alpha").opacity = 100;
		document.getElementById(full_id).style.left = x_end[index];	
		document.getElementById(full_id).style.top = y_end[index];	
		document.getElementById(full_id).style.width = width_end[index];
		document.getElementById(full_id).style.height = height_end[index];
		document.getElementById(full_id).style.zIndex = zIndex_end[index];
		//document.getElementById(full_index).filters.item("DXImageTransform.Microsoft.MotionBlur").strength = 0;
		if(index < last_index-1) {
			document.getElementById(full_id).style.zIndex = zIndex_end[index];
			do_move(++index);
		} else {
			focus_content ();
			document.getElementById('movable_object_0').style.zIndex = 0;
			document.getElementById('movable_object_1').style.zIndex = 1;
			document.getElementById('movable_object_2').style.zIndex = 2;
			//document.getElementById("content").style.zIndex = 200;
		}
	}
}

function focus_content () {
	for(var i = 0; i <= 100; i = i+5) {
		//content.filters.item("DXImageTransform.Microsoft.Alpha").opacity = i;
		var t = setTimeout("focus_content",tpf);	// recursive call
	}
}

function set_report(label, value) {
	var report = document.getElementById("report").innerHTML;
	document.getElementById("report").innerHTML = report + label + value + "<br />";
}

/* reference */ 
function timedCount()
{
	document.getElementById('txt').value=c
	c=c+1
	t=setTimeout("timedCount()",1000)
}

function stopCount()
{
	clearTimeout(t)
}
