// mostly written from scratch by Dennison Uy <dennison_uy@yahoo.com>
$loadScript("js/prototype.lite.js");
$loadScript("js/prototype.lite.js");
$loadScript("js/moo.fx.js");
$loadScript("js/litebox-1.0.js");
$loadScript("js/init.js");
$loadStyle("css/lightbox.css");

//window.onload=load_init;
addEvent(window, "load", load_init);
window.onunload = saveSettings;

normal = "style.css";
acc = "style_new.css";

normalName = "normal";
accName = "high contrast";

currentStyle = normal;

prefsLoaded = false;
//defaultFontSize = 62.5;
defaultFontSize = 100;
currentFontSize = defaultFontSize;

function load_init() {

	//show accessibility toolbox only if javascript is enabled
	getElement("accessibility12").style.display="block";

	//font resizer
	if(!prefsLoaded){

		cookie = readCookie("fontSize");
		currentFontSize = cookie ? cookie : defaultFontSize;
		setFontSize(currentFontSize);

		//check cookie if a style was previously set (returning visitors)
		lastStyle = readCookie("style");
		/*if (lastStyle != null) {
			setLayout(lastStyle);
			currentStyle = lastStyle;
		}*/
	
		prefsLoaded = true;
	}

	//load litebox scripts
}

function fontUp() {
	if (document.body.style.fontSize == "") {
		document.body.style.fontSize = defaultFontSize + 10 + "%";
	} else {
		alert(document.body.style.fontSize)
	}
}

function setLayout(e) {
	getElement("stylesheet").href=e;
	if (getElement("stylesheet").className==normal) {
		getElement("layout-name").innerHTML="to " + accName + " ";
	} else {
		getElement("layout-name").innerHTML="to " + normalName + " ";
	}
	currentStyle = e;
}

function getElement(e){
	old = document.layers;
	ie = document.all;
	others = document.getElementById && !document.all; 
	if (old) {
		alert("Sorry, your web browser does not support this function.");
		return null;
	}
	else if (ie) {
		obj = document.all[e];
		return obj;
	}
	else if (others) {
		obj = document.getElementById(e);
		return obj;
	}
	return null;
	
}

function switch_style() {
	obj = getElement("stylesheet");	
	if (obj.className==acc) {
		setLayout(normal);
	} else {
		setLayout(acc);
	}
	return true;
}

function $loadScript(src){
	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.src = src;
	document.getElementsByTagName('head')[0].appendChild(script);  
}

function $loadStyle(src){
	var style = document.createElement('link');
	style.type = 'text/css';
	style.href = src;
	style.rel = 'stylesheet';
	document.getElementsByTagName('head')[0].appendChild(style);  
}

/***** third party functions *****/

function addEvent(elm, evType, fn, useCapture)
// addEvent and removeEvent
// cross-browser event handling for IE5+,  NS6 and Mozilla
// By Scott Andrew
{
	if (elm.addEventListener){
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent){
		var r = elm.attachEvent("on"+evType, fn);
		return r;
	} else {
		//alert("Handler could not be removed");
	}
} 


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


//taken from Joomla

function revertStyles(){

	currentFontSize = defaultFontSize;
	changeFontSize(0);

}

function changeFontSize(sizeDifference){
	currentFontSize = parseInt(currentFontSize) + parseInt(sizeDifference * 5);

	if(currentFontSize > 210){
		currentFontSize = 210;
	}else if(currentFontSize < 50){
		currentFontSize = 50;
	}
	setFontSize(currentFontSize);
};

function setFontSize(fontSize){
//	var stObj = (document.getElementById) ? document.getElementById('content_area') : document.all('content_area');
	var stObj = (document.getElementById) ? document.getElementById('leftcol') : document.all('leftcol');
//	document.body.style.fontSize = fontSize + '%';
	document.getElementById('leftcol').style.fontSize = fontSize + '%';
//	alert (document.getElementById('leftcol').style.fontSize);
	
	
};

function saveSettings()
{
	createCookie("fontSize", currentFontSize, 365);
	createCookie("style", currentStyle, 365);
}

