// author: Bas Wenneker		website: http://www.solutoire.com
// Fx.Font is MIT-Licensed

Fx.Font = new Class({
	initialize: function(elements, sid, gid, growsize){
		if(!$(gid) || !$(sid)) return;
		
		// Creating class member variables inside the initialize function
		// 'this' refers to the object that is created to the class
		this.growsize = growsize || 2;
		//this.lineheightgrowsize = this.growsize + 4;
		this.elements = [];
		
		// Create a local variable in the function that will be used as the 'placeholder' for the 
		// values that will be iterating in the loop below; Instead of creating a new variable
		// everytime we run through the loop and wasting memory.
		var currentSize;
 		elements.each(function(el){
			//store the fontsize of 'el'
			currentSize = el.getStyle('font-size').toInt();
		//	currentLineHeight = el.getStyle('line-height').toInt();
			
			//check if you have the Cookie module and if fontSize is set and if so if it's set to 'large'
			if(Cookie.get != null && (size = Cookie.get('fontSize')) && size == 'large'){
				//now change the font-size of 'el' to large
				el.setStyle('font-size',currentSize+this.growsize+'px');		
				//el.setStyle('line-height',currentLineHeight+this.lineheightgrowsize+'px');		
			}
			
			// Save the element & the original font size and push it into the class member variable elements 
			this.elements.push([el,currentSize]);	
			//this.elements.push([el,currentSize, currentLineHeight]);
		},this);
		
		// bind() lets you pass a new reference of the current object to the function that is being called 
		$(gid).onclick = function(){this.grow()}.bind(this);
		$(sid).onclick = function(){this.shrink()}.bind(this);
	},
	grow: function(){
		this.elements.each(function(el){
			if(el[0].getStyle('font-size').toInt() == el[1])
				el[0].effect('font-size',{duration:300,unit:'px'}).custom(el[1],el[1]+this.growsize);			
			
		//	if(el[0].getStyle('line-height').toInt() == el[2])
		//		el[0].effect('line-height',{duration:300,unit:'px'}).custom(el[2],el[2]+this.lineheightgrowsize);			

		},this);
		
		//remember the users preference, keep the data for 1 week
		Cookie.set('fontSize','large',7);							
	},
	shrink: function(){
		this.elements.each(function(el){
			if(el[0].getStyle('font-size').toInt() == el[1]+this.growsize)
				el[0].effect('font-size',{duration:300,unit:'px'}).custom(el[1]+this.growsize, el[1]);
				
		//	if(el[0].getStyle('line-height').toInt() == el[2]+this.lineheightgrowsize)
		//		el[0].effect('line-height',{duration:300,unit:'px'}).custom(el[2]+this.lineheightgrowsize, el[2]);			
		},this);	
		
		//remember the users preference, keep the data for 1 week
		Cookie.set('fontSize','small',7);	
	}						
});