//Toggle Overlays
function toggle(x) {
	if ($(x).style.visibility == 'visible') {
		$(x).style.visibility = 'hidden';
	} else {
		$(x).style.visibility = 'visible';
	}
}

//Gallery Embed
function photoEmbed(gallery){
	document.write('<input type="text" class="overlayInput" id="photoEmbed" value=\'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="630" height="446" name="wmode" value="transparent"><param name="src" value="http://www.scion.com/scionracing/swf/racing_gallery.swf" /><param name="base" value="." /><param name="FlashVars" value="xmlfile=http://www.scion.com/scionracing/xml/' + gallery + '_embed.xml" /><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="wmode" value="transparent"><embed type="application/x-shockwave-flash" allowFullScreen="true" width="630" height="446" wmode="transparent" allowScriptAccess="always" src="http://www.scion.com/scionracing/swf/' + gallery + '.swf" FlashVars="xmlfile=http://www.scion.com/scionracing/xml/' + gallery + '_embed.xml"></embed></object>\'\'/>');
}
function videoEmbed(gallery){
	document.write('<input type="text" class="overlayInput" id="videoEmbed" value=\'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="630" height="446" name="wmode" value="transparent"><param name="src" value="http://www.scion.com/scionracing/swf/racing_gallery.swf" /><param name="base" value="." /><param name="FlashVars" value="xmlfile=http://www.scion.com/scionracing/xml/' + gallery + '_embed.xml" /><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="wmode" value="transparent"><embed type="application/x-shockwave-flash" allowFullScreen="true" width="630" height="446" wmode="transparent" allowScriptAccess="always" src="http://www.scion.com/scionracing/swf/' + gallery + '.swf" FlashVars="xmlfile=http://www.scion.com/scionracing/xml/' + gallery + '_embed.xml"></embed></object>\'\'/>');
}


// used by slide show pro for deep linking
function flashPutHref(href) { 
	location.href = href; 
}

function initGallery(xmlPath, type)
{	
	var initialURLString = escape(window.location);
	var xmlFilePath = xmlPath;
	var flashvars = "initialURL=" + initialURLString + "&xmlfile=" + xmlFilePath;
	var att = { data:"/scionracing/swfs/racing_gallery.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);
	
	setEmailOverlayLocation(type);
	setCopyURLLocation();
	
}

// handles click of 'email a friend' button on a gallery item.  Passes the current window.location value to the email form, which is necessary since that form is in a different domain (ssl) and can't handle cross frame js
function openEmailOverlay(type)
{
	setEmailOverlayLocation(type);
	toggle('emailOverlay');
}

function setEmailOverlayLocation(type)
{
	var currentLocation = '';
	currentLocation = '/ssl/scionracing/includes/emailForm.html?url=' + window.location;
	currentLocation = currentLocation.gsub('#', '%23');
	$('emailFormFrame').src = currentLocation;
}

function showGetLinkOverlay()
{
	setCopyURLLocation();
	toggle('getLinkOverlay');
}

function setCopyURLLocation()
{
	$('photoURL').value = window.location;
}


var flash_ID = "External_AS3";
	var flash_Obj = null;
	function getFlashObject(){
		if (flash_Obj == null){
			var flashObj;
			if (navigator.appName.indexOf( "Microsoft" ) != -1){
	       	   flashObj = window[flash_ID];
	   	    } 
	   		else{
	    		 flashObj = window.document[flash_ID];
	    	}
	    	flash_Obj = flashObj;
		}
		return flash_Obj;
	}

/** Form validation scripts **/	
