if(typeof Ferengi == "undefined") {
	var Ferengi = {
		Version: "1.0"
	};
	Ferengi.namespace = function() {
		var a = arguments,
			o = null,
			i, j, d;
		for(i=0; i<a.length; ++i) {
			d = a[i].split(".");
			o = Ferengi;
			for(j=(d[0]=="Ferengi")?1:0; j<d.length; ++j) {
				o[d[j]]=o[d[j]] || {};
				o=o[d[j]];
			}
		}
		return o;
	};
};
Ferengi.namespace("Decorator");

// Creating a class

Ferengi.Decorator.UpDownScroll = new Class({
	Implements: Options,
	options: {
		container:null
		,downButton:null
		,upButton:null
	},
	initialize: function(options) {
		this.setOptions(options);
		// initialize commands goes here
		this.buildButtons();
		this.build();
	}
});

Ferengi.Decorator.UpDownScroll.implement({
		build:function(){
			var bb = this.options.container;
			var oup = this.options.upButton;
			var odown = this.options.downButton;
		
			//Le defino el efecto al bloque y lo anido por dom, y este a los buttons, para reutilizarlo en los eventos de click
			bb.Fx = new Fx.Scroll(bb);
			oup.container = odown.container = bb;

			//Cuando mousedown al boton, Lo desplaza hacia la direccion del boton
			oup.addEvent("mouseenter", function(){
				this.container.Fx.toTop();
			});
			odown.addEvent("mouseenter", function(){
				this.container.Fx.toBottom();
			});

			//Cuando mouseup al boton, detengo el efecto actual
			oup.addEvent("mouseleave", function(){
				this.container.Fx.cancel();
			});
			odown.addEvent("mouseleave", function(){
				this.container.Fx.cancel();
			});
		}
		,buildButtons:function(){
			var container = this.options.container;
			var cc = new Element("div").addClass("buttonsContainer").injectInside(container.parentNode);
			var oup = new Element("a").addClass("buttonUp").injectInside(cc).set('html', '<span>Up</span>');
			var odown = new Element("a").addClass("buttonDown").injectInside(cc).set('html', '<span>Down</span>');
			
			cc.setPosition({
			  relativeTo: $(this.options.container),
			  position: 'centerBottom',
			  edge: 'top'
			});
			
			this.options.upButton = oup;
			this.options.downButton = odown;
		}
});
