
var EventsFlashGallery = Class.create();

//debugger;

EventsFlashGallery.prototype = {
	initialize: function() {
		this.flashGalleries = new Array();
		this.currentGallery = new Object();
		this.currentImageIndex = 0;
		this.backdrop = new ModalBackdrop($('modalBackdrop'));
		this.initGallery();
		this.bodyStyleCounter = 0;
	},
	
	initGallery: function() {
		try {
			this.flashGalleries = window.flashGalleries;
			// set up button event handlers
			Event.observe('flashGalleryCloseButton', 'click', this.close.bind(this));
			Event.observe('flashGalleryCloseButton', 'click', this.resetGallery.bind(this));
		} catch (e) {
			//alert('initGallery error: ' + e);
		}
	}, 
	
	/**
	* displays a given gallery, based on the variable name passed
	*/
	show: function(galleryName) {
		
		// turn on the lightbox modal backdrop effect
		this.backdrop.enable();
		// show the gallery
		$('flashGallery').style.display = 'block';
		// get the current gallery
		this.currentGallery = this.flashGalleries.find(function(flashGallery){
			return galleryName == flashGallery.name;
		});
		// display the content for this gallery

		//document.getElementById("gallerySwf").innerHTML = this.currentGallery.xml;
		
		var initialURLString = escape(window.location);
		var basePath = "/scionracing/events/xml/";
		var xmlFilePath = basePath + this.currentGallery.xml;
		var flashvars = "initialURL=" + initialURLString + "&xmlfile=" + xmlFilePath;
		var att = { data:"/scionracing/events/swf/eventsGallery.swf", width:"630", height:"446", wMode:"transparent", allowFullScreen:"true" };
		var par = { flashvars:flashvars, wMode:"transparent", allowFullScreen:"true"  };
		var id = "galleryCenter";
		
		var galleryObject = swfobject.createSWF(att, par, id);
		
		

		this.checkBodyStyle();
	},
	
	
	/**
	* this is a bug fix to work around an issue in the remote
	* 'addThis' library
	*/
	checkBodyStyle: function() {
		new PeriodicalExecuter(function(pe) {
			if( document.body.style.visibility == "hidden" )
			{
				document.body.style.visibility = "visible";
				pe.stop();
			}
			if (this.bodyStyleCounter >= 4)
			{
				pe.stop();
			}
		}.bind(this), 1);
		this.bodyStyleCounter ++;
	},
	
	/**
	* closes the gallery
	*/
	close: function() {
		this.backdrop.disable();
		$('flashGallery').style.display = 'none';
	},
	
	/**
	* resets url after user closes the gallery
	*/
	resetGallery: function() {
		window.location = String (document.location).split ('?')[0];
	}
}

// Toggle Overlays
function toggle(x) {
	if ($(x).style.visibility == 'visible') {
		$(x).style.visibility = 'hidden';
	} else {
		$(x).style.visibility = 'visible';
	}
}
// Get Link URL value
function eventsURL(){
	document.write('<input type="text" class="overlayInput" id="eventsURL" value=""/>');
}

// Get Link Embed value
function eventsEmbed(){
	document.write('<input type="text" class="overlayInput" id="eventsEmbed" value""/>');
}