/* 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.href)){
			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.setStyle('display','block').fade(0,9);
		}
	},

	showTip: function(cur){
		this.tip.setStyles({'display':'block'});
		this.tipFx = new Fx.Morph(this.tip,{link:'cancel'}).start({'opacity': 0.8, 'top': this.icon.getCoordinates(this.MooFlow).top-this.tip.getSize().y-1});
	},
	
	hideTip: function(cur){
		this.tipFx.start({'opacity': 0, 'top': 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){
			window.open(cur.href, cur.target || '_blank');
	}
});