var mooRquee = new Class({

	//implements
	Implements: [Options,Events],

	//options
	options: {
		min: 0,
		max: 1,
		duration: 5000,
		times: 1,
		links: null,
		onComplete: function(){
			this.createAnchor();
		}
	},

	elements: {
		container:	null,
		anchor:		null
	},

	idx: 0,
	opc: 0,

	//initialization
	initialize: function(el,options) {
		//set options
		this.setOptions(options);
		this.elements.container = $(el);
		this.times = 0;

		this.create();
	},

	create: function(){
		this.elements.container.setStyles({
			'width':this.options.width+'px',
			'height':this.options.height+'px',
			'lineHeight':this.options.height+'px',
			'textAlign':'center'
		});

		if(this.options.links.length>0){
			this.createAnchor();
		}
	},

	createAnchor: function(){
		this.idx++;
		if(this.idx==this.options.links.length) this.idx=0;

		if(this.elements.anchor) this.elements.anchor.dispose();

		this.elements.anchor=new Element('a',{
			'href' : this.options.links[this.idx].link,
			'target': '_blank',
			'styles': {
				display		: 'block',
				opacity		: 0
			},
			'events': {
				mouseover: function(){
					mooPanel.running=0;
					mooPanel.fx.pause();
					mooPanel.elements.anchor.setStyle('opacity',1);
				},
				mouseout: function(){
					mooPanel.running=1;
					mooPanel.fx.resume();
				}
			}
		});

		this.elements.anchor.appendText(this.options.links[this.idx].text);
		this.elements.container.adopt(this.elements.anchor);

		this.start();
	},

	//starts the pulse fade
	start: function(times) {
		if(!times) times = this.options.times * 2;
		this.running = 1;
		this.fireEvent('start').run(times -1);
	},

	//stops the pulse fade
	stop: function() {
		this.running = 0;
		this.fireEvent('stop');
	},

	//runs the shizzle
	run: function(times) {
		//make it happen
		var self = this;
		var to = self.elements.anchor.get('opacity') == self.options.min ? self.options.max : self.options.min;
		self.fx = new Fx.Tween(self.elements.anchor,{
			duration: self.options.duration / 2,
			onComplete: function() {
				self.fireEvent('tick');
				if(self.running && times)
				{
					self.run(times-1);
				}
				else
				{
					self.fireEvent('complete');
				}
			}
		}).start('opacity',to);
	}
});
