// JavaScript Document
//
// FontSizeChanger Class


function FontSizeChanger(){
	this.cookie = new Cookie();
	this.changer = document.getElementById('selectFontsize');
	this.status = this.cookie.fsize ? this.cookie.fsize : 'midium';
}

FontSizeChanger.prototype.initFontSize = function(){
	this.setFontSize();
	this.markCurrentFontSize();
}

FontSizeChanger.prototype.changeStatus = function(_status){
	this.status = _status;
	this.cookie.save('fsize', _status, 10, '/');
	
	this.setFontSize();
	this.markCurrentFontSize();
}

FontSizeChanger.prototype.setFontSize = function(){
	if(this.status == 'larger') document.body.style.fontSize = 'larger';
	else if(this.status == 'midium') document.body.style.fontSize = '100%';
	else if(this.status == 'smaller') document.body.style.fontSize = 'smaller';
}

FontSizeChanger.prototype.markCurrentFontSize = function(){
	var now = getElementsByClassName('on', this.changer)[0];
	var li = getElementsByClassName(this.status, this.changer)[0];
	var a = li.getElementsByTagName('a')[0];
	
	now.className = '';
	a.className = 'on';
}

function getElementsByClassName(class_name, Container){
	var container = Container ? Container : document;
	var descendants = (container.all && !window.opera) ? container.all : container.getElementsByTagName('*');
	var elements = [];
	var regExp = new RegExp('\s?'+class_name+'\s?');
	for(var i=0; i<descendants.length; i++){
		if(descendants[i].className == class_name || descendants[i].className.match(regExp)){
			elements[elements.length] = descendants[i];
		}
	}
	
	return elements
}