
// Creates Object
function FlashContent(flashvars) {
	// Properties
	this.swfURL     = "experience/challenger850.swf";
	this.objectID   = "flashObject";
	this.width      = "100%";
	this.height     = "100%";
	this.minWidth   = "994";
	this.minHeight  = "640";
	this.reqVersion = "10.0";
	this.installURL = "experience/swfobject_expressInstall.swf";
	
	this.tourURL    = "virtual-tour/panorama.swf";
	
	this.flashvars = flashvars;
	this.params = new Object();
		this.params.menu              = "false";
		this.params.wmode             = "transparent";
		this.params.bgcolor           = "#000000";
		this.params.allowscriptaccess = "always";
		this.params.allowfullscreen   = "true";
	
	// Methods
	this.pageLoadHandeler      = FlashContent_PageLoadHandeler;
	this.resizeHandler         = FlashContent_ResizeHandler;
	this.resizeTour            = FlashContent_ResizeTour;
	this.getViewport           = FlashContent_GetViewport;
	this.showTour              = FlashContent_ShowTour;
	this.hideTour              = FlashContent_HideTour;
	this.showTourEventHandeler = FlashContent_ShowTourEventHandeler;
	this.hideTourEventHandeler = FlashContent_HideTourEventHandeler;
	
	
	var refObject = this;
	
	// Adds Listeners
	addEvt(window, "load", function(evt) { refObject.pageLoadHandeler(evt); }, false);
	addEvt(window, "resize", function(evt) { refObject.resizeHandler(evt); }, false);
}




// Resize the virtual tour container
function FlashContent_ResizeTour() {
	var viewport = this.getViewport();
	
	try {
		var eLightbox = document.getElementById("virtual-tour");
		
		eLightbox.style.width  = String(viewport.width) + "px";
		eLightbox.style.height = String(viewport.height) + "px";
		
		document.getElementById("virtual-tour-window").style.width = eLightbox.style.width;
		document.getElementById("virtual-tour-window").style.height = eLightbox.style.height;
	} catch (err) {}
}




// Shows the Virtual Tour
function FlashContent_ShowTour() {
	try {
		eLightbox = document.getElementById("virtual-tour");
		this.resizeTour();
		
		eLightbox.style.display = "block";
		
		var refObj = this;
		var fader = new Fader(eLightbox, { listener: function (evt) { refObj.showTourEventHandeler(evt); } });
		fader.fadeIn();
		
	} catch (err) {}
}




// Hides the Virtual Tour
function FlashContent_HideTour() {
	try {
		eLightbox = document.getElementById("virtual-tour");
		eLightbox.innerHTML = eLightbox.innerHTML.substring(0, eLightbox.innerHTML.toLowerCase().indexOf("<object")) + '<div id="virtual-tour-content"></div>';
		var refObj = this;
		var fader = new Fader(eLightbox, { startOpacity: 1, listener: function (evt) { refObj.hideTourEventHandeler(evt); } });
		fader.fadeOut();
		
	} catch (err) {}
}




// Returns the viewport dimensions
function FlashContent_GetViewport() {
	var newWidth  = document.documentElement.clientWidth;
	var newHeight = document.documentElement.clientHeight;
	
	if ( newWidth < this.minWidth ) newWidth = this.minWidth;
	if ( newHeight < this.minHeight ) newHeight = this.minHeight;
	
	return { width: newWidth, height: newHeight };
}




// ---------------------------------------------------------------------------------------------------------
// Event Handelers
// ---------------------------------------------------------------------------------------------------------

// Page Load Handeler
function FlashContent_PageLoadHandeler(evt) {
	var eLightbox;
	if ( eLightbox = document.getElementById("virtual-tour") )
		eLightbox.style.display = "none";
		
	swfobject.embedSWF(this.swfURL, this.objectID, this.width, this.height, this.reqVersion, this.installURL, this.flashvars, this.params);
	
	this.resizeHandler(evt);
}




// Resizes Flash content and Lightbox at window's dimensions
function FlashContent_ResizeHandler(evt) {
	var viewport = this.getViewport();
	
	var eContainer;
	if ( eContainer = document.getElementById("flashContainer") ) {
		eContainer.style.width  = String(viewport.width) + "px";
		eContainer.style.height = String(viewport.height) + "px";
	}
	
	var eLightbox;
	if ( eLightbox = document.getElementById("virtual-tour") ) {
		if (eLightbox.style.display == "block")
			this.resizeTour();
	}
}




// Adds the flash object of the virtual tour
function FlashContent_ShowTourEventHandeler(evt) {
	if ( evt == "FADE_IN_COMPLETE" )
		swfobject.embedSWF(this.tourURL, "virtual-tour-content", "100%", "100%", this.reqVersion, this.installURL, this.flashvars, this.params);
}




// Disables the lightbox when hidden
function FlashContent_HideTourEventHandeler(evt) {
	if ( evt == "FADE_OUT_COMPLETE" ) {
		var eLightbox = document.getElementById("virtual-tour");
		eLightbox.style.display = "none";
	}
}




// ---------------------------------------------------------------------------------------------------------
// Library
// ---------------------------------------------------------------------------------------------------------

// Universal 'addEventListener'
function addEvt(obj, evt, func, capture) {
	try {
		if (!capture) capture = false;
		if ( obj.addEventListener )
			obj.addEventListener(evt, func, capture);
		else if ( obj.attachEvent )
			obj.attachEvent("on" + evt, func);
	} catch(err) {}
}

