// JS Style changer

var prefsLoaded = false;
var defaultFontSize = 70;
var currentFontSize = defaultFontSize;
var currentStyle = "Big";

function revertStyles(){

	currentFontSize = defaultFontSize;
	changeFontSize(0);
}

function switchNormal(){
	if(currentStyle == "Normal"){
		setWidth("Big");
	}
}
function switchBig(){
	if(currentStyle == "Big"){
		setWidth("Normal");
	}
}
function setWidth(width){
	d=new Date();
	flash=Math.round(Math.random()*d.getTime());
	if(width != "Big"){
		document.body.className = '';
		currentStyle = "Normal";
	}else{
		document.body.className = 'contentBig';
		currentStyle = "Big";
	}
}
function changeFontSize(sizeDifference){
	currentFontSize = parseInt(currentFontSize) + parseInt(sizeDifference * 5);

	if(currentFontSize > 80){
		currentFontSize = 80;
	}else if(currentFontSize < 60){
		currentFontSize = 60;
	}

	setFontSize(currentFontSize);
};

function setFontSize(fontSize){
	var stObj = (document.getElementById) ? document.getElementById('content_area') : document.all('content_area');
	document.body.style.fontSize = fontSize + '%';
	
	// alert (document.body.style.fontSize);
};

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 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;
};

window.onload = setWidthFont;

function setWidthFont(){
	if(!prefsLoaded){

		cookie = readCookie("fontSize");
		currentFontSize = cookie ? cookie : defaultFontSize;
		setFontSize(currentFontSize);
		
		cookie = readCookie("pageWidth");
		currentStyle = cookie ? cookie : "Big";
		setWidth(currentStyle);
		prefsLoaded = true;
	}
}
window.onunload = saveSettings;

function saveSettings()
{
  createCookie("fontSize", currentFontSize, 365);
  createCookie("pageWidth", currentStyle, 365);
}


// jump to script
function toggle(elementid) {
	var theItem = $(elementid);

	if( theItem.style.display == "none")	{
		new Effect.BlindDown(theItem, {duration: 0.5});
	}else{
		new Effect.BlindUp(theItem, {duration: 0.5});
	}
}

function hideLoader(loader, target) {
	new Effect.Fade($(loader), {duration: 0.5});
	new Effect.BlindDown($(target));
}

var g_USER_AGENT = getAgent();
// return NN4, NN5(Netscape 6+, Mozilla 1+?), IE4, IE5(IE5+), Unknown
function getAgent(){
  	var userAgent = navigator.userAgent;
  	var charIndex;
  	var majorVersion;
		
  	charIndex = userAgent.indexOf("MSIE");
  	if(charIndex){
		majorVersion = userAgent.charAt(charIndex + 4 + 1);
		if(majorVersion > 4){
		  return("IE5");
		}
		else if(majorVersion == 4){
		  return("IE4");
		}
		}
		
		charIndex = userAgent.indexOf("Mozilla");
		majorVersion = userAgent.charAt(charIndex + 7 + 1);
		if(majorVersion > 4){
		return("NN5");
		}
		else if(majorVersion == 4){
		return("NN4");
		}
		
		return("Unknown");
		}

function getWindowYOffset(){
  	if(g_USER_AGENT == "IE5" || g_USER_AGENT == "IE4"){
		return document.body.scrollTop;
		}else if(g_USER_AGENT == "NN5" || g_USER_AGENT == "NN4"){
		return window.pageYOffset;
		}else{
		return 0;
		}
		}
		
		var waitTimer;
		function jumpTo(dstY, srcY, scrollRate, waitMillSec) {
		if(waitTimer){
		clearTimeout(waitTimer);
		}
		if( ! dstY || dstY < 0 ){
		dstY = 0;
		}
		if( ! srcY ){
		srcY = 0 + getWindowYOffset();
		}
		if( ! scrollRate ){
		scrollRate = 6;
		}
		if( ! waitMillSec ){
		waitMillSec = 20;
		}
		
		srcY += (dstY - getWindowYOffset()) / scrollRate;
		if(srcY < 0){
		srcY = 0;
		}
		posY = Math.floor(srcY);
		window.scrollTo(0, posY);
		
		if(posY != dstY){
		waitTimer = setTimeout("jumpTo("+ dstY +", "+ srcY +", "+ scrollRate +", "+ waitMillSec +")", waitMillSec);
		}
		else if(posY == dstY){
		clearTimeout(waitTimer);
		}
		else if(posY < 1){
		window.scroll(0, 0);
		}
		}
		
function backUp(){
	  jumpTo(0, 0, 7, 14);
		}
		
		
var statusmsg=""
function hidestatus(){
	window.status=statusmsg
	return true
}
		
// JavaScript Document