function loadTheWork() {
	var o = document.getElementById("thework");

	var url = theWorksContent[work_index].link;
	o.setAttribute('src', url);

	update_session_work_index();


	setTitleButton();
	
	loadSideBar();
}



function update_session_work_index() {
	var url = "http://www.clubinternet.org/clubinternet/set.php?WORKINDEX=" + work_index;
	
	new Ajax.Request(url,{
			method: 'get',
			onSuccess:function(transport) {	
//			alert("updated work id " + url);
			}
		}
	);
	
	/*var xhr = new XMLHttpRequest();
	xhr.open("GET", url, true);
	xhr.send(null);*/
	
}


function loadWorkById(workid) {
	
	for (var i=0;i < theWorksContent.length;i++) {
		if (theWorksContent[i].id == workid) {
			work_index = i;
		}
	}
	loadTheWork();
}

function nextWork() {
	work_index++;
	if (work_index > theWorksContent.length-1) {
		work_index  = 0;
	}
	loadTheWork();
}


function makeWorkTitle() {
	if (showid == 7) {
		var operator = "found by"; 
	} else {
		var operator = "by";
	}
	var res = theWorksContent[work_index].title + " " + operator + " " + theWorksContent[work_index].artist;
	var y = theWorksContent[work_index].year;
	if (y != 0) {
		res += ", " + y;
	}
	return res;
}

function toggleSideBar() {
	var state = document.getElementById("sidebar").style.display;
	if (state == "none") {
		state = "inline";
	} else {
		state = "none";
	}
	document.getElementById("sidebar").style.display = state;
}

function makeSidebarURL() {
	var url = "http://www.clubinternet.org/clubinternet/xul/about.php?workid=" + theWorksContent[work_index].id  + "&showid=" + showid;

	return url;
}