/*
 * class”Å
 */

var fontProperty = {
	"Font-Small" : '86%',
	"Font-Medium" : '100%',
	"Font-Large" : '120%'
};

var activeFontSize = "Font-Medium";

var buttonTagName = 'AREA';


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;
}

function setFontSize( size ){
	var el = document.getElementsByTagName('BODY')[0];
	setStyle( el, { fontSize : fontProperty[size] } );
	activeFontSize = size;
	createCookie("fontSize", size, 365);
}

function setStyle( element, styles ){
	if(!element) return;
	for( var key in styles ){
		element.style[key] = styles[key];
	}
}


function isFontProperty( p ){
	for( var fp in fontProperty ){
		if(fp==p) return true;
	}
	return false;
}

function init(){
	if(!document.getElementById) return;
	
	var fs = readCookie("fontSize");
	if(fs) setFontSize(fs);
	else setFontSize(activeFontSize);
	
	var className = document.all? 'className' : 'class';
	var sw = document.getElementsByTagName(buttonTagName);
	for( var i=0; i<sw.length; i++ ){
		if(!sw[i].getAttribute(className)) continue;
		var cns = sw[i].getAttribute(className).split(/ /);
		for(var j=0; j<cns.length; j++){
			if( isFontProperty(cns[j]) ){
				var num = j;
				sw[i].onclick = function(){
					var fs = this.getAttribute(className).split(/ /)[num];
					setFontSize( fs );
				};
/*				sw[i].onmouseover = function(){
					this.style.cursor = document.all? "hand" : "pointer";
				};
				sw[i].onmouseout = function(){
					this.style.cursor = "default";
				};*/
			}
		}
	}
	var className02 = document.getElementById['fontmap']? 'className' : 'class';
	var sw = document.getElementsByTagName(buttonTagName);
	for( var i=0; i<sw.length; i++ ){
		if(!sw[i].getAttribute(className02)) continue;
		var cns = sw[i].getAttribute(className02).split(/ /);
		for(var j=0; j<cns.length; j++){
			if( isFontProperty(cns[j]) ){
				var num = j;
				sw[i].onclick = function(){
					var fs = this.getAttribute(className02).split(/ /)[num];
					setFontSize( fs );
				};
/*				sw[i].onmouseover = function(){
					this.style.cursor = document.all? "hand" : "pointer";
				};
				sw[i].onmouseout = function(){
					this.style.cursor = "default";
				};*/
			}
		}
	}
}








//var evt = new EventManager();
evt.addEvent( window, 'load', init, false );
evt.addEvent( window, 'unload', function(){
	createCookie("fontSize", activeFontSize, 365);
}, false );


