/* MooFlow Viewer (extra JS MooFlowViewer.js)
 * v0.1dev useViewer:true
 */
MooFlow.implement({

	attachViewer: function(){
		return this;
	},
	flowStart: function(){
		this.hideIcon();
	},
	
	flowComplete: function(){
		this.createIconTip();
	},
	
	createIconTip: function(){
		var cur = this.getCurrent();
		//if(!$chk(cur.rel)||!$chk(cur.href)) return;
		this.tipFx = new Fx({link:'cancel'});
		if(!$chk(this.icon)) { this.icon = new Element('a').addClass('show').setStyles({'display':'none','opacity':'0'}).inject(this.MooFlow); }
		this.icon.addEvent('click', this.onClickView.bind(this, cur));
		this.icon.addEvent('mouseenter', this.showTip.bind(this, cur));
		this.icon.addEvent('mouseleave', this.hideTip.bind(this, cur));
		if(!$chk(this.tip)){ this.tip = new Element('div').addClass('tooltip').setStyles({'display':'none','opacity':'0'}).inject(this.MooFlow); }
		this.tip.set('html', cur.alt);
		//this.icon.addClass(cur.rel.toLowerCase());
		this.icon.addClass('link');
		this.icon.setStyle('display','block').fade(1);
	},

	showTip: function(cur){
		this.tip.setStyles({'top':100,'display':'block'});
		//this.tipFx = new Fx.Morph(this.tip,{link:'cancel'}).start({'opacity': 0.8, 'top': this.icon.getCoordinates().bottom-this.tip.getSize().y-0});
		this.tipFx = new Fx.Morph(this.tip,{link:'cancel'}).start({'opacity': 1});
	},
	
	hideTip: function(cur){
		this.tipFx.start({'opacity': 0});
	},

	hideIcon: function(){
		if($chk(this.icon) && $chk(this.icon.getParent())) this.icon.destroy();
		if($chk(this.tip) && $chk(this.tip.getParent())) this.tip.destroy();
		this.icon = this.tip = null;	
	},
	
	onClickView: function(cur){
		if(!cur.rel)
		{
			window.open(cur.href, cur.target || '_self');
			return;
		}
		
		switch (cur.rel.toLowerCase()){
			case 'image':
				Mediabox.open(cur.href, cur.alt, 'mediabox');
				break;
				
			case 'link':
				window.open(cur.href, cur.target || '_blank');
				break;
				
			case 'lightbox':
				Mediabox.open(cur.href, cur.alt, 'mediabox');
				break;
				
			default:
		}
		
	}
});

