var content_dir		= "include/content/";
var cur_page		= "home";
var page_prefix		= ".php";
var side_bar_url	= "include/content/sidebar.php";

var init = function(){
	var contentNode = dojo.byId("content");
	dojo.xhrGet({
		url: content_dir + cur_page + page_prefix,
		handleAs: "text",
		load: function(data,args){
			// fade out the node we're modifying
			dojo.fadeOut({
				node: contentNode,
				onEnd: function(){
				  // set the data, fade it back in
				  contentNode.innerHTML = data; 
				  dojo.fadeIn({node: contentNode}).play();    
				}
			}).play();
		},
		// if any error occurs, it goes here:
		error: function(error,args){
			console.warn("error!",error);
		}
	});
}; 
dojo.addOnLoad(init);

function load_content(page, parameters){
	cur_page = page;
	if (parameters === undefined){
		params = "";
	}
	else {
		params = parameters;
	}
	var contentNode = dojo.byId("content");
	dojo.xhrGet({
		url: content_dir + cur_page + page_prefix + "?" + params,
		handleAs: "text",
		load: function(data,args){
			// fade out the node we're modifying
			dojo.fadeOut({
				node: contentNode,
				onEnd: function(){
				  // set the data, fade it back in
				  contentNode.innerHTML = data; 
				  dojo.fadeIn({node: contentNode}).play();    
				}
			}).play();
			var div = document.getElementById("content");
			div.innerHTML = data;
			var x = div.getElementsByTagName("script"); 
			for(var i=0;i<x.length;i++)
			{
				//alert(x[i].text);
				eval(x[i].text);
			}
		},
		// if any error occurs, it goes here:
		error: function(error,args){
			console.warn("error!",error);
		}
	});
}

function load_sidebar(){
	var contentNode = dojo.byId("side_bar");
	dojo.xhrGet({
		url: side_bar_url,
		handleAs: "text",
		load: function(data,args){
			// fade out the node we're modifying
			dojo.fadeOut({
				node: contentNode,
				onEnd: function(){
				  // set the data, fade it back in
				  contentNode.innerHTML = data; 
				  dojo.fadeIn({node: contentNode}).play();    
				}
			}).play();
		},
		// if any error occurs, it goes here:
		error: function(error,args){
			console.warn("error!",error);
		}
	});
}
