// author: Sven Rhinow		website: http://www.sr-tag.de
// Fx.FontResize is MIT-Licensed

Fx.FontResize = new Class({

	initialize: function(elements, sid, gid, normal, growsize){
		
		this.growsize = (growsize) ? growsize : 2;		
		this.elements = [];
		
		var currentSize;
 		elements.each(function(el){
 		
			//store the fontsize of 'el'
			currentSize = el.getStyle('font-size').toInt();			
			
			var myCookie = Cookie.read('fontSize');
			//console.log(myCookie);
			//check if you have the Cookie module and if fontSize is set
			if(myCookie){
			
				//now change the font-size of 'el' to Cokkie-Value
				el.setStyle('font-size',myCookie+'px');				
			}

			this.elements.push([el,currentSize.toInt()]);
									   
		},this);
		
		$(gid).addEvent('click', function(event){
			this.grow();
			event.stop();
		}.bind(this));

		$(sid).addEvent('click', function(event){
// 		console.log(sid);
			this.shrink();
			event.stop();
		}.bind(this));		
		
		
		if(normal != null) 
		    $(normal).addEvent('click', function(event){
// 			console.log(normal);
			this.normal();
			event.stop();
		}.bind(this));
	},
		
	grow: function(){		
		this.elements.each(function(el){
			var currentfsize = el[0].getStyle('font-size').toInt();
                        var newfsize = 	currentfsize + this.growsize;
			el[0].setStyle('font-size', newfsize+'px');
			var myCookie = Cookie.write('fontSize',newfsize,{duration:1});	
		},this);							
	},
	
	shrink: function(){
		this.elements.each(function(el){
			var currentfsize = el[0].getStyle('font-size').toInt();
			var newfsize = 	currentfsize - this.growsize;
					
			el[0].setStyle('font-size', newfsize+'px');
			var myCookie = Cookie.write('fontSize',newfsize,{duration:1});	
		},this);		
	},
							
	normal: function(){
	    this.elements.each(function(el){
	           
	           el[0].setStyle('font-size',el[1]+'px');
	           var myCookie = Cookie.write('fontSize',el[1],{duration:1});	
	    },this);
	}						
});
