var galleyHomeTH=new Class({
	Implements: [Events, Options],
	options:{
		onStart: $empty
		,onComplete: $empty
		,viewPort:$empty
		,mapPort: $empty
		,leftRow: $empty
		,rightRow: $empty
		,events: $empty
		,items:$empty
		,steps:1
		,duration:1500
		,itemsMouseOver:$empty
		,itemsMouseOut:$empty
		,itemsClick:$empty
		,flagFilter: false
		,fxTransition: Fx.Transitions.Linear
		,defaultPosition:0
		,offset: {'x': 0, 'y': 0}
		,discount:0
	},
	
	initialize: function(options){
		
		var _this=this;
		this.position=0;
		this.setOptions(options);
		this.items=this.options.items;
		this.points=new Array();
		this.moving=false;
		
		this.Fx=new Fx.Scroll2(_this.options.viewPort, {
			offset: _this.options.offset
			,duration:_this.options.duration
			,transition: _this.options.fxTransition
			,onComplete: function(){  
				_this.moving=false;
				}
		});
		
		var pos=0;
		var first=true;
		var number=0;
		this.items.each(function(item){
			item.set("number",number);
			
			
			item.addEvent("mouseover", function(){
				_this.options.itemsMouseOver(item);
			});
			
			item.addEvent("mouseout", function(){
				_this.options.itemsMouseOut(item);
			});
			
			item.addEvent("click", function(){
				_this.options.itemsClick(item);
			});
			
			
			if(first){
				item.set("point","true");
				_this.points.push(item);
				first=false;
			}
			if(pos==_this.options.steps){
				pos=0;
				item.set("point","true");
				_this.points.push(item);
			}
			pos++;
			number++;
		});
		
		if(this.options.leftRow!=$empty){
			this.options.leftRow.addEvent("click", function(){
				_this.move("left");
			});
		}
		
		if(this.options.rightRow!=$empty){
			this.options.rightRow.addEvent("click", function(){
				_this.move("right");
			});
		}
		
		
	},
	
	moveTo: function(pos){
		if(pos==this.position) return;
		//_this.Fx.toElement(_this.points[pos]-_this.options.discount);
		this.Fx.cancel();
		this.Fx.toElement(this.points[pos-this.options.discount]);
		this.position=pos;
	},
	move: function(dir){
		var _this=this;
		
		if(_this.moving) return;
		_this.moving=true;
		var totalPoints=_this.points.length-1;
		
		switch(dir){
			case 'left':
				_this.position--;
				if(_this.position<0) _this.position=totalPoints;
			break;
			
			case 'right':
			default:
				_this.position++;
				
				if(_this.position > totalPoints) _this.position=_this.options.defaultPosition;
				
			
		}
		
		
		_this.Fx.toElement(_this.points[_this.position]);
	}
});

var Windows=new Class({
	Implements: [Events, Options],
	options:{
		onOpen: $empty
		,Element:$empty
		,width:300
		,height:300
	},
	
	initialize: function(from, options){
				
		var _this=this;
		
		
		this.setOptions(options);
		_this.options.Element=_this.options.Element.clone();
		
		_this.options.Element.setStyle("display","block");
		
		this.container=new Element("div", {
			'styles':{
				'background':'#cac7be'
				,'border':'1px solid #333333'
			}
			,'class':'divflotante'
		});
		this.container.setStyles(from.getCoordinates());
		
		this.container.setStyle("opacity",0);
		
		this.container.setStyles({
				'position':'absolute'
				,'width': _this.options.width 
				,'height': _this.options.height 
		});
		
		this.header=new Element("div", {
			styles:{
				'width': '100%'
				//,'height': '10px'
			},
			'class':'close'
		});
		
		var a=new Element("a",{
			'href':'javascript:void(0)'
		});
		
		a.addEvent("click", function(){
			_this.container.removeEvents();
			_this.container.set("tween",{
				'complete':function(){
					_this.container.remove();
				}
			});
			_this.container.tween("opacity",1,0);
			
			
		}).appendText("X");
		
		this.header.adopt(a);
		
		this.windows=new Element("div", {
			styles:{
				'width': '100%'
				,'height': _this.options.height+30
			}
		});
		
		
		
		this.footer=new Element("div", {
			styles:{
				'width':'100%'
				,'height':"5px"
			}
		});
		
		this.container.adopt(_this.header);
		this.container.adopt(_this.windows);
		this.container.adopt(_this.footer);
		
		
		
		
		
		_this.windows.adopt(_this.options.Element);
		document.body.adopt(_this.container);
		
		_this.container.tween("opacity",0,1);
		
	}
});


