
var box_speed = 10;
var pix_per_move=10;
var container_speed=15;
var container_height=730;
var current_height=0;//that variable holds the current height of the container as it changes
var last_id = 'main2';//that is the id of the last box to be moved into place.  When that box has finished moving the page will be given its scroll bars back
var disable_info_boxes = false;//to enable the info boxes to be disabled until the boxes have finished flying around the page


function glide_in(id, plane, direction, offset){
	//if(typeof(finishing_pos) == 'undefined')
	//	finishing_pos=0;
	
	if(plane=='vert'){
		if(direction=='t2b') new_pos = 0-offset;
		else new_pos = 0+offset;
		
		document.getElementById(id).style.top = new_pos +'px';//set it to its starting position
		document.getElementById(id).style.display='block';//and now make it visible
	}
	else {//if plane=='horiz'
		if(direction=='l2r') new_pos = 0-offset;
		else new_pos = 0+offset;
		
		document.getElementById(id).style.left = new_pos +'px';//set it to its starting position
		document.getElementById(id).style.display='block';//and now make it visible
	}
	
	set_position(id, new_pos, plane, direction);
}


function set_position(id, new_pos, plane, direction, finishing_pos){
	//keep going until it's back in its correct place:
	if(((direction=='l2r' || direction=='t2b') && new_pos>=0) || ((direction =='r2l' || direction=='b2t') && new_pos<=0)){
		if(plane=='vert') document.getElementById(id).style.top = '0px';//set the element back EXACTLY to its original position
		else document.getElementById(id).style.left = '0px';
		
		if(id==last_id){//if it's the last box, which is now back in its correct position
			if(!navigator.userAgent.match(/MSIE|Safari/))//FF only
				t=setTimeout("document.getElementById('body').style.overflow='auto';",500); //IE screws this up and u get 2 scroll bars :-{
			else {//for IE & Safari
				t=setTimeout("document.getElementsByTagName('html')[0].style.overflow='auto';",500);
				if(navigator.userAgent.match(/Safari/)){//if it's safari
					//we need to trigger it into putting the scroll bars back
					document.getElementsByTagName('html')[0].style.width=(document.documentElement.clientWidth+10) +'px';
					document.getElementsByTagName('html')[0].style.height=(document.documentElement.clientHeight+10) +'px';
					t=setTimeout(function(){
						document.getElementsByTagName('html')[0].style.width='auto';
						document.getElementsByTagName('html')[0].style.height='auto';
					}, 500);
				}
			}
			disable_info_boxes=false;//so that the info boxes are now active
		}
		return;
	}
	
	if(direction=='t2b' || direction=='l2r') new_pos+=pix_per_move;
	else new_pos-=pix_per_move;
	
	if(plane=='vert') document.getElementById(id).style.top = new_pos +'px';
	else document.getElementById(id).style.left = new_pos +'px';
	
	t = setTimeout(
		function(){
			set_position(id, new_pos, plane, direction);
		}, box_speed
	);
}



function expand_container(){
	//first remove the 'loading' div
	//document.getElementById('loading').style.display='none';
	//keep going until it's back in its correct place:
	if(current_height >= container_height){//if we've reached or exceeded the correct height
		document.getElementById('shadow').style.display='block';
		load_boxes();
		return;
	}
	else {
		current_height +=pix_per_move;
		document.getElementById('inner_container').style.height=current_height + 'px';
		t = setTimeout("expand_container();",container_speed);
	}
}

function load_it(){//so that none of this is called until the page has loaded, otherwise getElementById wont work
	if(navigator.userAgent.match(/MSIE/) && 0)//if it's IE and therefore nothing will work
		return;
	//first, wait a couple of seconds
	t=setTimeout("expand_container();",1600);//when the container has been expanded to its full height load_boxes() will then be called
}

function load_boxes(){
	disable_info_boxes = true;//de-activate the info boxes until the page has finished moving about
	glide_in('main1', 'vert', 't2b', 920);
	glide_in('main2', 'vert', 't2b', 800);
	//glide_in('main3', 'vert', 't2b', 100);
	
	glide_in('right1', 'horiz', 'r2l', 370);
	glide_in('right2', 'horiz', 'r2l', 330);
	glide_in('right3', 'horiz', 'r2l', 300);
	
	glide_in('left1', 'horiz', 'l2r', 470);
	glide_in('left2', 'horiz', 'l2r', 480);
	glide_in('left3', 'horiz', 'l2r', 540);
	
}


function slide_in_error_box(){
	glide_in('form_error_message', 'vert', 't2b', 200);
}
