var textSize = {
	initialize:function(target){
		//starting checks
		if(!document.getElementById || !document.createTextNode){return}
		if(!$('text_size') || !$('minus') || !$('plus')){return} 
		
		//declare variables
		this.text_size = $('text_size');
		this.plus = $('plus');
		this.minus = $('minus');
		this.maximum = 3; //x factor to increase
		this.minimum = -2; //x factor to decrease
		
		//find original sizes and remember them
		if($E('h1', target)){
			this.origSizeH1 = $E('h1', target).getStyle('font-size').toInt();
		}
		if($E('h2', target)){
			this.origSizeH2 = $E('h2', target).getStyle('font-size').toInt();
		}
		if($E('h3', target)){
			this.origSizeH3 = $E('h3', target).getStyle('font-size').toInt();
		}
		if($E('h4', target)){
			this.origSizeH4 = $E('h4', target).getStyle('font-size').toInt();
		}
		if($E('h5', target)){
			this.origSizeH5 = $E('h5', target).getStyle('font-size').toInt();
		}
		if($E('h6', target)){
			this.origSizeH6 = $E('h6', target).getStyle('font-size').toInt();
		}
		if($E('p', target)){
			this.origSizeP = $E('p', target).getStyle('font-size').toInt();
		}
		if($E('ul', target)){
			this.origSizeUL = $E('ul', target).getStyle('font-size').toInt();
		}
		if($E('ul ul', target)){
			this.origSizeULUL = $E('ul ul', target).getStyle('font-size').toInt();
		}
		if($E('dl', target)){
			this.origSizeDL = $E('dl', target).getStyle('font-size').toInt();
		}
		if($E('dt', target)){
			this.origSizeDT = $E('dt', target).getStyle('font-size').toInt();
		}
		if($E('dd', target)){
			this.origSizeDD = $E('dd', target).getStyle('font-size').toInt();
		}
		if($E('blockquote', target)){
			this.origSizeBQ = $E('blockquote', target).getStyle('font-size').toInt();
		}
						
		//show widget
		this.text_size.setStyles('display:block; visibility:visible;');
		
		//add events to elements
		this.plus.addEvent('click', this.increase.pass([target], textSize));
		this.minus.addEvent('click', this.decrease.pass([target], textSize));
	},
	
	increase:function(target){
		if($E('h1', target)){
			curSize = $E('h1', target).getStyle('font-size').toInt();
			if(curSize < (this.origSizeH1 + this.maximum)){$E('h1', target).setStyle('font-size', curSize+1);}
		}
		if($E('h2', target)){
			curSize = $E('h2', target).getStyle('font-size').toInt();
			if(curSize < (this.origSizeH2 + this.maximum)){$E('h2', target).setStyle('font-size', curSize+1);}
		}
		if($E('h3', target)){
			curSize = $E('h3', target).getStyle('font-size').toInt();
			if(curSize < (this.origSizeH3 + this.maximum)){$E('h3', target).setStyle('font-size', curSize+1);}
		}
		if($E('h4', target)){
			curSize = $E('h4', target).getStyle('font-size').toInt();
			if(curSize < (this.origSizeH4 + this.maximum)){$E('h4', target).setStyle('font-size', curSize+1);}
		}
		if($E('h5', target)){
			curSize = $E('h5', target).getStyle('font-size').toInt();
			if(curSize < (this.origSizeH5 + this.maximum)){$E('h5', target).setStyle('font-size', curSize+1);}
		}
		if($E('h6', target)){
			curSize = $E('h6', target).getStyle('font-size').toInt();
			if(curSize < (this.origSizeH6 + this.maximum)){$E('h6', target).setStyle('font-size', curSize+1);}
		}
		if($E('p', target)){
			curSize = $E('p', target).getStyle('font-size').toInt();
			if(curSize < (this.origSizeP + this.maximum)){$ES('p', target).each(function(item, index){item.setStyle('font-size', curSize+1);})}
		}
		if($E('ul', target)){
			curSize = $E('ul', target).getStyle('font-size').toInt();
			if(curSize < (this.origSizeUL + this.maximum)){$E('ul', target).setStyle('font-size', curSize+1);}
		}
		if($E('ul ul', target)){
			curSize = $E('ul ul', target).getStyle('font-size').toInt();
			if(curSize < (this.origSizeULUL + this.maximum)){$ES('ul ul', target).each(function(item, index){item.setStyle('font-size', curSize+1);})}
		}
		if($E('dl', target)){
			curSize = $E('dl', target).getStyle('font-size').toInt();
			if(curSize < (this.origSizeDL + this.maximum)){$E('dl', target).setStyle('font-size', curSize-1);}
		}
		if($E('dt', target)){
			curSize = $E('dt', target).getStyle('font-size').toInt();
			if(curSize < (this.origSizeDT + this.maximum)){$ES('dt', target).each(function(item, index){item.setStyle('font-size', curSize+1);})}
		}
		if($E('dd', target)){
			curSize = $E('dd', target).getStyle('font-size').toInt();
			if(curSize < (this.origSizeDD + this.maximum)){$ES('dd', target).each(function(item, index){item.setStyle('font-size', curSize+1);})}
		}
		if($E('blockquote', target)){
			curSize = $E('blockquote', target).getStyle('font-size').toInt();
			if(curSize < (this.origSizeBQ + this.maximum)){$E('blockquote', target).setStyle('font-size', curSize+1);}
		}
	},
	
	decrease:function(target){
		if($E('h1', target)){
			curSize = $E('h1', target).getStyle('font-size').toInt();
			if(curSize > (this.origSizeH1 + this.minimum)){$E('h1', target).setStyle('font-size', curSize-1);}
		}
		if($E('h2', target)){
			curSize = $E('h2', target).getStyle('font-size').toInt();
			if(curSize > (this.origSizeH2 + this.minimum)){$E('h2', target).setStyle('font-size', curSize-1);}
		}
		if($E('h3', target)){
			curSize = $E('h3', target).getStyle('font-size').toInt();
			if(curSize > (this.origSizeH3 + this.minimum)){$E('h3', target).setStyle('font-size', curSize-1);}
		}
		if($E('h4', target)){
			curSize = $E('h4', target).getStyle('font-size').toInt();
			if(curSize > (this.origSizeH4 + this.minimum)){$E('h4', target).setStyle('font-size', curSize-1);}
		}
		if($E('h5', target)){
			curSize = $E('h5', target).getStyle('font-size').toInt();
			if(curSize > (this.origSizeH5 + this.minimum)){$E('h5', target).setStyle('font-size', curSize-1);}
		}
		if($E('h6', target)){
			curSize = $E('h6', target).getStyle('font-size').toInt();
			if(curSize > (this.origSizeH6 + this.minimum)){$E('h6', target).setStyle('font-size', curSize-1);}
		}
		if($E('p', target)){
			curSize = $E('p', target).getStyle('font-size').toInt();
			if(curSize > (this.origSizeP + this.minimum)){$ES('p', target).each(function(item, index){item.setStyle('font-size', curSize-1);})}
		}
		if($E('ul', target)){
			curSize = $E('ul', target).getStyle('font-size').toInt();
			if(curSize > (this.origSizeUL + this.minimum)){$E('ul', target).setStyle('font-size', curSize-1);}
		}
		if($E('ul ul', target)){
			curSize = $E('ul ul', target).getStyle('font-size').toInt();
			if(curSize > (this.origSizeULUL + this.minimum)){$ES('ul ul', target).each(function(item, index){item.setStyle('font-size', curSize-1);})}
		}
		if($E('dl', target)){
			curSize = $E('dl', target).getStyle('font-size').toInt();
			if(curSize > (this.origSizeDL + this.minimum)){$E('dl', target).setStyle('font-size', curSize-1);}
		}
		if($E('dt', target)){
			curSize = $E('dt', target).getStyle('font-size').toInt();
			if(curSize > (this.origSizeDT + this.minimum)){$ES('dt', target).each(function(item, index){item.setStyle('font-size', curSize-1);})}
		}
		if($E('dd', target)){
			curSize = $E('dd', target).getStyle('font-size').toInt();
			if(curSize > (this.origSizeDD + this.minimum)){$ES('dd', target).each(function(item, index){item.setStyle('font-size', curSize-1);})}
		}
		if($E('blockquote', target)){
			curSize = $E('blockquote', target).getStyle('font-size').toInt();
			if(curSize > (this.origSizeBQ + this.minimum)){$E('blockquote', target).setStyle('font-size', curSize-1);}
		}
	}
};
window.addEvent('domready', textSize.initialize.pass(['content'], textSize));