/* 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.setStyle('display','block').fade(0.9);
	},

	showTip: function(cur){
		this.tip.setStyles({'top':0,'display':'block'});
		this.tipFx = new Fx.Morph(this.tip,{link:'cancel'}).start({'opacity': 0.8, 'top': 5});
	},
	
	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){
		switch (cur.rel.toLowerCase()){
			
			case 'image':
			this.loadImage(cur);
			
			
			break;
			case 'vt-property-1':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/property/morgans/index.html");
			break;
			case 'vt-property-2':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/property/westpoint-homes/index.html");
			break;
			case 'vt-property-3':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/property/explore-living/index.html");			
			break;
			case 'vt-property-4':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/property/george-wimpey/index.html");
			break;
			case 'vt-property-5':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/property/st-george/index.html");
			break;
			case 'vt-property-6':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/property/pridewood/index.html");
			break;
			case 'vt-property-7':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/property/bryant-homes/index.html");			
			break;
			case 'vt-property-8':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/property/watersedge/index.html");
			break;
			case 'vt-property-9':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/property/places-for-people/index.html");			
			break;
			case 'vt-property-10':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/property/city-lofts/index.html");
			
					
			break;
			case 'vt-hotel-leisure-1':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/hotel-leisure/chalet-blanc/index.html");
			break;
			case 'vt-hotel-leisure-2':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/hotel-leisure/the-eton-collection/index.html");
			break;
			case 'vt-hotel-leisure-3':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/hotel-leisure/marriott-hotels/index.html");			
			break;
			case 'vt-hotel-leisure-4':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/hotel-leisure/crowne-plaza/index.html");
			break;
			case 'vt-hotel-leisure-5':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/hotel-leisure/sunseeker-yachts/index.html");
			break;
			case 'vt-hotel-leisure-6':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/hotel-leisure/aquapura/index.html");
			break;
			case 'vt-hotel-leisure-7':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/hotel-leisure/holiday-inn/index.html");			
			break;
			case 'vt-hotel-leisure-8':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/hotel-leisure/best-western/index.html");
			break;
			case 'vt-hotel-leisure-9':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/hotel-leisure/bramham-house/index.html");	
			
			
			break;
			case 'vt-creative-1':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/creative/oversea-views/index.html");
			break;
			case 'vt-creative-2':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/creative/netjets-europe/index.html");
			break;
			case 'vt-creative-3':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/creative/chateau-marouatte/index.html");			
			break;
			case 'vt-creative-4':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/creative/kings-college-london/index.html");
			break;
			case 'vt-creative-5':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/creative/video-in-virtual-tour/index.html");
			break;
			case 'vt-creative-6':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/creative/john-smeaton-college/index.html");
			break;
			case 'vt-creative-7':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/360-virtual-tours/creative/screen-yorkshire/index.html");	



			break;
			case 'gallery-equire-1':
			document.getElementById('gallery-equire').style.backgroundImage="url(mooflow/gallery/equires/main/balcony1.jpg)";
			break;
			case 'gallery-equire-2':
			document.getElementById('gallery-equire').style.backgroundImage="url(mooflow/gallery/equires/main/balcony2.jpg)";
			break;
			case 'gallery-equire-3':
			document.getElementById('gallery-equire').style.backgroundImage="url(mooflow/gallery/equires/main/banqueting-hall.jpg)";
			break;
			case 'gallery-equire-4':
			document.getElementById('gallery-equire').style.backgroundImage="url(mooflow/gallery/equires/main/beach.jpg)";
			break;
			case 'gallery-equire-5':
			document.getElementById('gallery-equire').style.backgroundImage="url(mooflow/gallery/equires/main/birds.jpg)";
			break;
			case 'gallery-equire-6':
			document.getElementById('gallery-equire').style.backgroundImage="url(mooflow/gallery/equires/main/conservatory.jpg)";
			break;
			case 'gallery-equire-7':
			document.getElementById('gallery-equire').style.backgroundImage="url(mooflow/gallery/equires/main/smeaton.jpg)";
			break;
			case 'gallery-equire-8':
			document.getElementById('gallery-equire').style.backgroundImage="url(mooflow/gallery/equires/main/laser.jpg)";
			break;
			case 'gallery-equire-9':
			document.getElementById('gallery-equire').style.backgroundImage="url(mooflow/gallery/equires/main/newby-hall.jpg)";
			break;
			case 'gallery-equire-10':
			document.getElementById('gallery-equire').style.backgroundImage="url(mooflow/gallery/equires/main/ski-bar.jpg)";
			break;
			case 'gallery-equire-11':
			document.getElementById('gallery-equire').style.backgroundImage="url(mooflow/gallery/equires/main/highpeak.jpg)";
			break;
			case 'gallery-equire-12':
			document.getElementById('gallery-equire').style.backgroundImage="url(mooflow/gallery/equires/main/terrace-garden.jpg)";
			break;
			case 'gallery-equire-13':
			document.getElementById('gallery-equire').style.backgroundImage="url(mooflow/gallery/equires/main/truck.jpg)";
			break;
			case 'gallery-equire-14':
			document.getElementById('gallery-equire').style.backgroundImage="url(mooflow/gallery/equires/main/waterloo-bridge.jpg)";
			break;
			case 'gallery-equire-15':
			document.getElementById('gallery-equire').style.backgroundImage="url(mooflow/gallery/equires/main/watersedge.jpg)";
			
			
			break;
			case 'gallery-creative-1':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/photography/creative/bahrain/index.html");
			break;
			case 'gallery-creative-2':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/photography/creative/uk/index.html");
			break;
			case 'gallery-creative-3':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/photography/creative/canada/index.html");
			break;
			case 'gallery-creative-4':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/photography/creative/cape-verde/index.html");
			break;
			case 'gallery-creative-5':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/photography/creative/crete/index.html");			
			break;
			case 'gallery-creative-6':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/photography/creative/france/index.html");
			break;
			case 'gallery-creative-7':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/photography/creative/italy/index.html");
			break;
			case 'gallery-creative-8':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/photography/creative/monaco/index.html");
			break;
			case 'gallery-creative-9':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/photography/creative/spain/index.html");
			
			
			break;
			case 'gallery-property-1':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/photography/property/bryant-homes/index.html");
			break;
			case 'gallery-property-2':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/photography/property/places-for-people/index.html");
			break;
			case 'gallery-property-3':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/photography/property/george-wimpey/index.html");
			break;
			case 'gallery-property-4':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/photography/property/pridewood/index.html");
			break;
			case 'gallery-property-5':
			window.document.getElementById("thisframe").setAttribute("src", "site-data/photography/property/westpoint-homes/index.html");
			break;
			
			default:
 
		}
	},
	
	loadImage: function(cur){
		this.icon.removeClass('image').addClass('viewerload');
		this.image = new Asset.image(cur.href, {onload: this.showImage.bind(this)});
	},
	
	showImage: function(){
		var cur = this.getCurrent();
		var c = cur.con.getFirst().getCoordinates();
		this.image.inject(document.body);
		this.image.addEvent('click', this.hideImage.bind(this));
		this.image.setStyles({'left':c.left,'top':c.top,'width':c.width,'height':c.height,'position':'absolute','z-index':'103'});
		var imageFx = new Fx.Morph(this.image, {transition: Fx.Transitions.Sine.easeOut});
		var to = {x: this.image.get('width'), y: this.image.get('height')};
		var box = document.getSize(), scroll = document.getScroll();
		var pos = {x: scroll.x + ((box.x - to.x) / 2).toInt(), y: scroll.y + ((box.y - to.y) / 2).toInt() };
		var vars = {left: pos.x, top: pos.y, width: to.x, height: to.y};
		imageFx.start(vars);
	},
	
	hideImage: function(){
		this.icon.removeClass('viewerload').addClass('image');
		this.image.dispose();
	}
});


