var fontSizes   = new Array(12,13,14,15);

/*
	sizeArray  		new Array()
	buttonPrefix	String
*/
FontResizer = function(sizeArray, buttonPrefix, self){
	this.resizeClassName		= 'Resizeable';
	this.ResizeClassNamePrefix	= 'TextResize_ChangeSize';
	this.sizes					= sizeArray;
	this.buttonPrefix			= buttonPrefix;
	this.currentSize			= null;
	this.self					= self
}

FontResizer.prototype.init = function(){
	var oThis = this;
	
	
	oThis.currentSize = oThis.getCookie('currentFontSize');
	
	if(!oThis.currentSize) oThis.currentSize = oThis.sizes[0];
	
	for(i=0; i<oThis.sizes.length; i++){
	    var item = $(oThis.buttonPrefix+oThis.sizes[i]);
	    if (!item) continue;
		Event.observe(item, 'click', function(obj){
			eval(oThis.self + ".setCookie('currentFontSize', '"+ Event.element(obj).id.substring(oThis.buttonPrefix.length) +"', '', '/', '', '')")
			eval("var currentFontSize =" + oThis.self + ".getCookie('currentFontSize')");
			eval(oThis.self+".setFontSize('MainDiv', currentFontSize)")
		})
	}
}

FontResizer.prototype.setCookie = function(name, value, expires, path, domain, secure){
	var today = new Date();
	today.setTime( today.getTime() );
	
	if ( expires ){
		expires = expires * 1000 * 60 * 60 * 24;
	}
	
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

FontResizer.prototype.getCookie = function( name ){
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ){
		return null;
	}

	if ( start == -1 ) return null;

	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	
	return unescape( document.cookie.substring( len, end ) );
}

FontResizer.prototype.setFontSize = function(rootElement, size){
	var oThis = this;
	var objects = $(rootElement).getElementsByClassName(oThis.resizeClassName);
	
	for (var i=0; i<document.styleSheets.length; i++) {
	    if (document.styleSheets[i].title=='fontresizer-css') {
	        document.styleSheets[i].disabled = true;
	    }
	}

	if(oThis.currentSize){
		$(oThis.buttonPrefix+oThis.currentSize).removeClassName('ActiveText');	
		$(oThis.buttonPrefix+oThis.currentSize).addClassName('NormalText');
	}
	for(i=0; i<objects.length; i++){
		var childs = Element.childElements(objects[i]);

		if(oThis.currentSize) objects[i].removeClassName(oThis.ResizeClassNamePrefix + oThis.currentSize + "px");
		objects[i].addClassName(oThis.ResizeClassNamePrefix + size + "px");
	
		for(j=0; j<childs.length; j++){
			if(oThis.currentSize) childs[j].removeClassName(oThis.ResizeClassNamePrefix + oThis.currentSize + "px");
			childs[j].addClassName(oThis.ResizeClassNamePrefix + size + "px");
		}
	}
	
	$(oThis.buttonPrefix+oThis.currentSize).addClassName('NormalText');
	$(oThis.buttonPrefix+size).addClassName('ActiveText')
	oThis.currentSize = size;
}



function writeOutCSS(){
	var r = new FontResizer(fontSizes,'ResizeTo','');
	var currentFontSize = r.getCookie('currentFontSize');
	
	if(currentFontSize){
		document.write(
			"<style type=\"text\/css\" title=\"fontresizer-css\">"+
				"."+r.resizeClassName+" {font-size: "+r.getCookie('currentFontSize')+"px !important}"+
				"."+r.resizeClassName+" * {font-size: "+r.getCookie('currentFontSize')+"px !important}"+
				"#"+r.buttonPrefix+currentFontSize+"{font-weight:bold}"+
			"<\/style>"
		);
	}else{
		document.write(
			"<style type=\"text\/css\">"+
				"#"+r.buttonPrefix+r.sizes[0]+"{font-weight:bold }"+
			"<\/style>"
		);
	}
}


writeOutCSS()

