/* 
	Function.js
	Contains animation and functionality
*/

var current_position = 1;
var current_width;
var bottom_enabled = false;
var button_locations = [null, 'button_why', 'button_what', 'button_how', 'button_who', 'button_when', 'button_where'];
var page_locations = {
	'why': '2', 'what': '3', 'how': '4', 'who': '5', 'when': '6', 'where': '7'  
};


var page_positions = [null, 'why', 'what', 'how', 'who', 'when', 'where'];
	
//Start
function init() {
	
	//Initially Hide
	Effect.multiple(['content_target'], Effect.Opacity, { duration: 0, delay: 0, to: 0.0});
	//Set the first button index
	document.getElementById(button_locations[current_position]).style.backgroundImage = 'url(\'assets/templates/ksc/img/button_active.png\')';
	
	//Fade in the logo
	Effect.multiple(['logo_left', 'logo_right'], Effect.Appear, { duration: 1.0, delay: 0});

	//Fade in the rest of the page
	Effect.Fade('white_overlay', { duration: 1.0, delay: 1.5 });
	
	//Fade in the current_location
	new Effect.Opacity('content_target', { to: 1.0, duration: 0, delay: 2 });

}

/* Ajax function for loading the subpages */
function loadXMLDoc(page)	{
	var xmlhttp;
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
	    xmlhttp=new XMLHttpRequest();
	} else {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {
	    	document.getElementById('page_content').innerHTML=xmlhttp.responseText;
	    	new Effect.Opacity('page_content', { to: 1.0, duration: 0.8, delay: 0 });
	    }
	}
	
	var page_to_load = 'index.php?id=' + page_locations[page];
	xmlhttp.open("GET", page_to_load,true);
	xmlhttp.send();
}

//Show the bottom Wrapper
function showBottomWrapper() {

	//load first doc
	loadXMLDoc('why');
	if (!bottom_enabled) {
		Effect.BlindDown('bottom_wrapper', { duration: 1.8 });
		Effect.Fade('more', { duration: 1.8 });
		bottom_enabled = true;
		setTimeout("goToContent();", 2000);
	}
}

function goToContent() {
	pixel_offset = -document.getElementById('bottom_wrapper').offsetHeight -80;
	Effect.ScrollTo('footer_wrapper', { duration: 0.5, delay: 0, offset: pixel_offset });
}

//Move the Content Container (does not move anymore, fades in requested pages instead)
function move(location, button_id) {
	
	//Change the buttons
	document.getElementById(button_id).style.backgroundImage = 'url(\'assets/templates/ksc/img/button_active.png\')';
	document.getElementById(button_locations[current_position]).style.backgroundImage = 'url(\'assets/templates/ksc/img/button_inactive.png\')';
	
	//Reset the current location
	new Effect.Opacity('page_content', { to: 0.0, duration: 0.2, delay: 0});
	
	loadXMLDoc(page_positions[location]);
	current_position = location;
}


	
