FLYG.ImageViewer=(function(){

	var self=function(id,next,prev,images,copyright){
		this.node=document.getElementById(id);
		//this.node.className='imgViewer';
		
		this.images=images;
		this.copyright=copyright;
		this.position=0;
		
		var me=this;
		document.getElementById(prev).onclick=function(e){
			this.blur();
			FLYG.Event.handleBubble(e,false);
			me.previous();
			};
			
		document.getElementById(next).onclick=function(e){
			this.blur();
			FLYG.Event.handleBubble(e,false);
			me.next();
			}
		};
		
	self.prototype={
		next:function(){
			this.position=this.position==this.images.length-1 ? 0 : this.position+1;
			return this.update();
			},
		previous:function(){
			this.position=this.position==0 ? this.images.length-1 : this.position-1;
			return this.update();
			},
		update:function(){
			this.node.getElementsByTagName('img')[0].src=this.images[this.position];
			this.node.getElementsByTagName('span')[1].innerHTML=this.copyright[this.position] || '';
			return this;
			}
		};

	return self;
	})();
	
FLYG.ClickableImageViewer=function(){
	var a=[].slice.call(arguments);
	this.onClick=a.pop();
	this.constructor.baseClass.apply(this,a);
	this.update();
	};
	
FLYG.extend(FLYG.ClickableImageViewer,FLYG.ImageViewer);
FLYG.ClickableImageViewer.prototype.update=function(){
	this.constructor.baseClass.prototype.update.call(this);
	this.node.getElementsByTagName('img')[0].style.cursor='pointer';
	var self=this;
	this.node.getElementsByTagName('img')[0].onclick=function(){
		self.onClick(this);
		};
	};

	
FLYG.TextViewer=(function(){

	var self=function(links,text){
		this.links=links;
		this.text=text;
		
		var self=this;
		this.links.click(function(e){
			var result=FLYG.Event.handleBubble(e,false);
			this.blur();
			self.links.removeClass('active');
			self.text.removeClass('active');
			for (var i=0;i<self.links.length;i++){
				if (self.links[i]==this) FLYG.$(self.text[i]).addClass('active');
				}
			FLYG.$(this).addClass('active');
			return result;
			});
		
		};

	return self;
	})();