/**
*	@package		My Own Art
*	@subpackage		Javascript
*	@author			Ben Sekulowicz-Barclay
*	@copyright		Copyright 2008, Outside Line.
*	@version		1.00
*
************************************************************************************************************************ **/

var moa_flashViewer = Class.create({	
	
	initialize: function(vars) {
		// Create our class-level object
		this.vars = vars;
	
		if (swfobject.hasFlashPlayerVersion("9.0.0")) {
			
			// Update the links
			$$('ul.listArtwork li').each(function(li) {
				
				li.observe('click', function(e) {
				
					// Update the variables
					this.vars.token = li.getAttribute('rel');
					
					// Open the overlay
					this.open();
								
				}.bindAsEventListener(this));				
				li.onclick = function() { return false; }				
			}.bind(this));	
			
			// If we are viewing already
			if ($('sectionSingleRoom')) {
				
				// Update the variables
				this.vars.token = $('sectionSingleRoom').getAttribute('rel');
				
				// Remove the HTML window and add the Flash window
				$('sectionSingleRoom').remove();
				
				// Open the overlay
				this.open();
			}	
		}
	},
	
	/* ****************************************************************************************************************** */
	
	open: function() {
		// Create the overlay
		$$('body').first().insert({bottom: '<div id="sbOverlay" style="display:none; "><div id="sbOverlayWindow"><div id="sbOverlayWindowFlash" style="height:700px;width:920px;"></div></div></div>' });
		
		// Insert the flash movie					
		swfobject.embedSWF(base_url + "assets/swf/creator/creator.swf", "sbOverlayWindowFlash", "920px", "700px", "9.0.0","creator.swf", this.vars, {wmode: "transparent"}, {});	
		
		// Fade in the overlay ...
		$('sbOverlay').appear({ duration: 0.3 });
	},
	
	/* ****************************************************************************************************************** */
	
	close: function() {
		// Fade out the overlay ...
		$('sbOverlay').fade({ 
			duration: 0.3,
			afterFinish: function() { $('sbOverlay').remove(); }
		});
	}
	
	/* ****************************************************************************************************************** */
});