(function($) {
	var self = null;

	$.fn.baner = function(o)
	{
		o = jQuery.extend({
			interval: 5000,
			fade: 400
		},o);
		return this.each(function(){
			new $.baner(this, o);
		});
	}

	$.baner = function(e,o){
		self = this;
		this.field = $(e);
		this.options = jQuery.extend(o,this.options);
		this.current = 1; //start from second one
		this.init();
	}

	$.baner.prototype = {
		init : function(){
			//register timed event
			this.field.everyTime(this.options.interval, this.cycle);
			//register mouse click events
			this.options.elements.each(function(){
				$(this).click(function(e){return self.mclick(e)});
			});
		},
		cycle : function(){
			//banners
			self.options.banners.each(function(){
				$(this).hide();
			});
			$(self.options.banners[self.current]).fadeIn(self.options.fade);
			//elements
			self.options.elements.each(function(){
				$(this).removeClass('baner_active');
			});
			$(self.options.elements[self.current]).addClass('baner_active');
			//next element
			++self.current;
			if(self.current == self.options.elements.size())
				self.current = 0;
		},
		mclick : function(e){
			if(e.target.nodeName == 'A')
				return true;
			this.field.stopTime();
			self.current = jQuery.inArray(e.currentTarget,self.options.elements);
			self.cycle();
			this.field.everyTime(5000, this.cycle);
			return false;
		}
	}
})(jQuery);

