function tab_hover(obj) {
	if (obj.className != 'tab tab-on') { 
		obj.className = 'tab tab-hover';
	}
}

function tab_hover_out(obj) {
	if (obj.className != 'tab tab-on') { 
		obj.className = 'tab tab-off';
	}
}

function make_tab_visible(tabset_id, tab_num) {
	var mainFrame = document.getElementById('main');
	var selTabView = document.getElementById(tabset_id);
	var sel_tab_cont = document.getElementById(tabset_id + tab_num + "-container");
	
	//make sure tab contents are scrolled if longer than view
	if (selTabView.offsetHeight > mainFrame.offsetHeight) { //scroll the tab if it will overflow
		sel_tab_cont.style.overflowY = "scroll";
		sel_tab_cont.style.height = (mainFrame.offsetHeight - 45) + "px";
	}
	
	//make sure the whole tab is in view
	if (mainFrame.scrollTop + mainFrame.offsetHeight < selTabView.offsetTop + selTabView.offsetHeight) {
		selTabView.scrollIntoView(false); //scroll to bottom, tabview is below view area
	} else if (mainFrame.scrollTop > selTabView.offsetTop) {
		selTabView.scrollIntoView(true); //scroll to top, tabview is above view area
	}
}

function show_tab(tabset_id, tab_num) {
	sel_tab_button = document.getElementById(tabset_id + tab_num);
	var max_tabs = 5;
	var mainFrame = document.getElementById('main');
	var selTabView = document.getElementById(tabset_id);
	
	if (sel_tab_button.className != 'tab tab-on') {
		//close all the sibling tab buttons
		for (var i = 1; i <= max_tabs; i++) {
			tab_button = document.getElementById(tabset_id + i);
			if (!tab_button) break; //no more tabs
			if (tab_button != sel_tab_button) tab_button.className = 'tab tab-off';
		}
		
		//open the selected tab
		sel_tab_button.className = 'tab tab-on';
		
		//close the tab containers
		var sel_tab_cont = document.getElementById(tabset_id + tab_num + "-container");
		for (var i = 1; i <= max_tabs; i++) {
			tab_cont = document.getElementById(tabset_id + i + "-container");
			if (!tab_cont) break; //no more tabs
			if (tab_cont != sel_tab_cont) {
				if (tab_cont.style.display != "none") tab_cont.style.display = "none";
			}
		}
		
		//open the selected tab container
		sel_tab_cont.style.display = 'block';
		
		make_tab_visible(tabset_id, tab_num);
	}
}

var loadedImages = new Array();
function loadImages(content_id, obj_id) {
	//only load once
	//if (loadedImages.indexOf(content_id) >= 0) return; //doesn't work in IE6
	for (var i = 0; i < loadedImages.length; i++) {
		if (loadedImages[i] == content_id) return;
	}

	obj_id = document.getElementById(obj_id.id + '-container');
	
	obj_id.innerHTML = '<div class="centeredMsg">Loading...</div>';
	
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		obj_id.innerHTML = '<div class="centeredMsg">Error!<br/>No AJAX Support.</div>';
		return;
	}
	
	var url = "/content_images.php?id=" + content_id;
	
	xmlHttp.onreadystatechange = function () { 
		if (xmlHttp.readyState == 4) {
			obj_id.innerHTML = xmlHttp.responseText;
			loadedImages.push(content_id);
			delete xmlHttp;
		}
	}
	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

var loadedFileInfo = new Array();
function loadFileInfo(dl_id, obj_id) {
	//only load once
	for (var i = 0; i < loadedFileInfo.length; i++) {
		if (loadedFileInfo[i] == dl_id) return;
	}

	obj_id = document.getElementById(obj_id);
	
	obj_id.innerHTML = 'Loading Details...';
	
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		obj_id.innerHTML = 'Error!<br/>No AJAX Support.';
		return;
	}
	
	var url = "/content_dl_info.php?id=" + dl_id;
	
	xmlHttp.onreadystatechange = function () { 
		if (xmlHttp.readyState == 4) {
			obj_id.innerHTML = xmlHttp.responseText;
			loadedFileInfo.push(dl_id);
			delete xmlHttp;
		}
	}
	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function GetXmlHttpObject() {
	var XMLHttpFactories = [
		function () {return new XMLHttpRequest()},
		function () {return new ActiveXObject("Msxml3.XMLHTTP")},
		function () {return new ActiveXObject("Msxml2.XMLHTTP")},
		function () {return new ActiveXObject("Microsoft.XMLHTTP")}
	];

	var xmlhttp = null;
	for (var i=0; i<XMLHttpFactories.length; i++) {
		try {
			xmlhttp = XMLHttpFactories[i]();
		} catch (e) {
			continue;
		}
		break;
	}
	return xmlhttp;
}