/**
 * Fanta.com Flash Marquee Javascript 
 * 
 * - To be included on every page that uses the Fanta.com flash marquee
 * - Instantiates the flash marquee
 * 
 */

var FANTA = FANTA || {};

FANTA.Marquee = (function() {
	
	function swfObjectStatus(e) {
		if (e.success == true) {
			// The SWF was embedded successfully, but we still need an exit function to allow SWFObject to
			// finish writing before trying to access it
			setTimeout( function() {
				
			}, 1 );
		}
		else {
			// The SWF was not embedded, replacement content is shown
		}
	}
	
	function swfObjectExpressInstallCanceled() {
		// The user selected to cancel the express install process
	}
	
	function getQueryVariable(variable) {
		var query = window.location.search.substring(1);
		var vars = query.split("&");
		for (var i=0;i<vars.length;i++) {
			var pair = vars[i].split("=");
			if (pair[0] == variable) {
				return pair[1];
			}
		}
	}
	
	function domLoadedHandler(){
		
		// If the user has FP 10 or above, go ahead and embed the Flash site
		if (swfobject.hasFlashPlayerVersion("10")) {
			var flashvars = { 
				configuration: EPXML,
				deeplink: getQueryVariable('slide')
			};
			
			var params = {
				allowScriptAccess:"always", 
				allowFullScreen:"true",
				wmode: 'transparent',
				bgcolor: '#000000'
			};
			
			var attributes = {
				id: "runtimeID", name: "runtimeID"
			};
			
			swfobject.embedSWF(MARQUEE_SWF, "replaceWithFlash", "980px", "410px", "10.0.0", EXPRESS_INSTALL_SWF, flashvars, params, attributes, swfObjectStatus);
		}
		// If the user does not have FP 10 installed, show the express install state
		else {
			swfobject.showExpressInstall({data: EXPRESS_INSTALL_SWF, width: "980", height: "410"}, {menu: false}, "expressInstall", swfObjectExpressInstallCanceled);
		}
		
		$('#alternateContent').show();
	}
	
	/**
	 * Return our public API
	 */
	return {
		initialize: function() {
			swfobject.addDomLoadEvent(domLoadedHandler);
		}
	};
	
})();


FANTA.Marquee.initialize();

