var SlideShow = new Class ({
	Implements: Options,

	options : {
		imageTime	:	4000,
		fadeTime	:	1500
	},
	
	initialize : function (container, images, links, options) {
		this.setOptions(options);
		this.container = $(container);
		
		this.images = images.map(function(url) {
			return new Element('img', 
							   {'src' : url,
							    'width' : '100%', 'height': '100%',
								'tween' : {duration : this.options.fadeTime}
							   });
		}, this);

		this.index = 0;
		this.currentImage = this.images[this.index].inject(container);
		this.fade.periodical(this.options.imageTime + this.options.fadeTime, this);
	},
	
	fade : function () {
		this.index = (this.index + 1) % this.images.length;
		this.lastImage = this.currentImage;
		
		this.currentImage = this.images[this.index].fade('hide').inject(this.container).fade('in');
	}
	
});


function fixMenu (container) {
	var lst = $(container).getElements('li');
	
	lst.each(function (item, index) {
		if (index == lst.length - 1) item.set('class', 'last-item');
	});
}


function httpRequest (srcElt, dstElt) {
	srcElt.addEvent('click', function(event) { 
		event.stop();
        var req = new Request({  
					method: 'get',  
             		url: srcElt.get('href'), 
	             	onComplete: function(response) { dstElt.set('html',response) ; }  
		         	}).send();  
    	});  
	}


var Tools = new Class({
		Implements: Options,

		options : {
			size: '11px',
			line: '15px'
		},
	
		initialize : function (container, className, options) {
			this.setOptions(options);
			this.classNames = [];
			
			if ($chk(this.options.font) == true) {
				var temp = this.options.font.match(/(\w+)\/(\w+)*/);
				this.options.size = temp[1];
				this.options.line = temp[2];
			}
			
			className.each(function(item, index) {
				var font = (item.font).match(/(\w+)\/(\w+)*/);
				this.classNames[index] = {title: item.className, size: font[1], line: font[2]};
			}, this);
		
			this.container = $(container);
			
		},
		
		updateFont : function () {
			var param;
			var body = this.container.getElements('*');

			body.each(function(item, index) {
				var param = this.searchClass(item.get('class'));
				if ( param != false)
					item.set('style', 'font-size:'+ param.size+'; line-height:'+param.line+';');
				else item.set('style', 'font-size:'+ this.options.size+'; line-height:'+this.options.line+';');	
				
			}, this);
		},
		
		
		upto1 : function () {
			this.classNames.each(function(item, index) {
				item.size = (item.size.toInt()+1)+'px';
				item.line = (item.line.toInt()+1)+'px';
			});
			
			this.options.size = (this.options.size.toInt()+1)+'px';
			this.options.line = (this.options.line.toInt()+1)+'px';
		},
		
		downto1 : function () {
			this.classNames.each(function(item, index) {
				item.size = (item.size.toInt()-1)+'px';
				item.line = (item.line.toInt()-1)+'px';
			});
			
			this.options.size = (this.options.size.toInt()-1)+'px';
			this.options.line = (this.options.line.toInt()-1)+'px';
		},
		
		
		searchClass : function (name) {
			var bool = false;
			
			this.classNames.each(function(item,index) {
				if (item.title == name) {
					bool = {size: item.size, line: item.line};
				}
			});

			return bool;
		} 
	});