/*******************************************************************************************
 * flashReplace
 * Written by Craig Francis
 * If the browser can support flash, replace the flash alternative with the flash object
 * //////////////////////////////////////////////////////////////////////////////////////////
 * MODIFIED 17th April 2008 - Steve Kirtley
 * Add in handling for a 'flashId' parameter to be appended to the object tag in front end 
 * output. 
 *******************************************************************************************/

//--------------------------------------------------
// Config variables, if not already defined

	var flashObjects = new Array();
	var flashUseXmlMethods = (document.contentType && document.contentType.indexOf('xml') > -1);

	if (typeof flashRequired == 'undefined' || flashRequired < 8) {
		var flashRequired = 8;
	}

	if (typeof flashDetectObjectUrl == 'undefined') {
		var flashDetectObjectUrl = '/a/swf/common/flashDetect.swf';
	}

	if (typeof flashReloadGifs == 'undefined' || flashUseXmlMethods) {
		var flashReloadGifs = false;
	}

	
	
	
//--------------------------------------------------
// Config for the flash enable and disable links,
// defined here to ensure scope is set correctly

	if (typeof flashBeforeLinkText  == 'undefined') var flashBeforeLinkText  = '';
	if (typeof flashEnableLinkText  == 'undefined') var flashEnableLinkText  = 'Flash Version';
	if (typeof flashBetweenLinkText == 'undefined') var flashBetweenLinkText = '';
	if (typeof flashDisableLinkText == 'undefined') var flashDisableLinkText = 'HTML Version';
	if (typeof flashAfterLinkText   == 'undefined') var flashAfterLinkText   = '';

//--------------------------------------------------
// Simple function to set the flashAvailable
// variable in a cookie and store in a variable
// for this script

	var flashAvailable;

	function setFlashAvailable (version) {
		flashAvailable = version;
		document.cookie = 'flashAvailable=' + escape(version) + '; path=/';
	}

//--------------------------------------------------
// Initial value of "flashAvailable"

	//--------------------------------------------------
	// See if there is a cookie set which can tell
	// us which version of flash the user has (from
	// previous page loads)

		flashAvailable = 0; // RUN TEST
		var cookieString = document.cookie;

		if (cookieString && cookieString.match(/^.*flashAvailable=([\-0-10]+).*$/i)) {
			flashAvailable = parseInt(cookieString.replace(/^.*flashAvailable=([\-0-10]+).*$/i, '$1'));
		}

	//--------------------------------------------------
	// See if we are being told what todo

		var locationString = window.location.search;

		if (locationString.match(/(\?|&)flashReplace=false/i)) {

			setFlashAvailable (-1); // SOFT DISABLE

		} else if (locationString.match(/(\?|&)flashReplace=true/i)) {

			if (flashAvailable < 1) {
				setFlashAvailable (0); // RUN TEST
			}

		}
	
		
	//--------------------------------------------------
	// If we have to check if flash exists (0), then
	// do a quick sanity check to see if the plugin
	// exists (if it doesn't, we should disable flash
	// now... to save on processing). This section of
	// code was origionally written by Christopher
	// Sheldon from http://www.microagesolutions.com

		if (flashAvailable == 0) {
			var pluginVersion = -1;
			if (navigator.plugins && navigator.plugins.length) {
				for (var i = (navigator.plugins.length - 1); i >= 0 && pluginVersion == -1; i--) {
					if (navigator.plugins[i].name.indexOf('Shockwave Flash') != -1) {
						pluginVersion = parseInt(navigator.plugins[i].description.split('Shockwave Flash ')[1]);
					}
				}
			} else if (window.ActiveXObject) {
				for (var i = (flashRequired + 10); i >= flashRequired; i--) {
					try {
						oFlash = eval('new ActiveXObject("ShockwaveFlash.ShockwaveFlash.' + i + '");');
						if (oFlash) {
							pluginVersion = i;
						}
					} catch(e) {
					}
				}
			}
			if (pluginVersion < flashRequired) {
				setFlashAvailable (-2); // HARD DISABLE
			}
		}

//--------------------------------------------------
// Function to setup a new flash object, this
// can be used several times from the HTML page

	function flashReplace (divId, flashUrl, flashWidth, flashHeight, flashBgColour, flashId) {

    //
    flashAvailable = 8;

		//--------------------------------------------------
		// If this is a SOFT DISABLE, we will give up soon,
		// but first, add the flash disable links. Although
		// technically this is called multiple times

			if (flashAvailable == -1) {
				addLoadEvent (flashDisableLinks);
			}

		//--------------------------------------------------
		// If version of flash is not good enough, give up

			if (flashAvailable < 0 || (flashAvailable > 0 && flashAvailable < flashRequired)) {
				return;
			}

		//--------------------------------------------------
		// Temporarily hide the flash object

			var cssRule = ' #' + divId + ' {';
			cssRule += '  visibility: hidden; ';
			cssRule += '  width: ' + flashWidth + 'px;';
			cssRule += '  height: ' + flashHeight + 'px;';
			cssRule += '}';

			if (flashUseXmlMethods) {

				var styleElement = createElement('style');
				var styleContent = document.createTextNode(cssRule);

				styleElement.setAttribute('type', 'text/css');
				styleElement.appendChild(styleContent);

				var headRef = document.getElementsByTagName('head');
				if (headRef[0]) {
					headRef[0].appendChild(styleElement);
				}

			} else {

				document.write ('<style type="text/css">' + cssRule + '<\/style>');

			}

		//--------------------------------------------------
		// Store the details in an array

			flashObjects[flashObjects.length] = {
				divId: divId,
				flashUrl: flashUrl,
				flashWidth: flashWidth,
				flashHeight: flashHeight,
				flashBgColour: flashBgColour,
				flashId: flashId
			}

		//--------------------------------------------------
		// If this is the first flash object, then ONLOAD
		// either create the flash detect object or bypass
		// straight into flashReplaceProcess (if we already
		// know which version of flash the user has)

			if (flashObjects.length == 1) {
				if (flashAvailable == 0) {
					addLoadEvent (flashDetectObjectAdd);
				} else {
					addLoadEvent (flashReplaceProcess);
				}
			}

	}

//--------------------------------------------------
// Self looping function to create the flash
// detection object... as soon as the body is
// available, then add it!

	function flashDetectObjectAdd () {

		//--------------------------------------------------
		// Untill we get a responce from the flash object,
		// it should be taken that the browser does not
		// support flash (for next page load)

			setFlashAvailable (-1); // SOFT DISABLE

		//--------------------------------------------------
		// Get a reference to the body

			var bodyRef = document.getElementsByTagName('body');
			if (bodyRef[0]) {
				bodyRef = bodyRef[0];
			} else {
				flashRestoreAlt();
				return;
			}

		//--------------------------------------------------
		// Create a div which will act as an anchor for
		// a small flash detect object

			var divTag = createElement('div');

			divTag.setAttribute('id', 'flashDetectObject');
			divTag.style.position = 'absolute';
			divTag.style.top = '0';
			divTag.style.left = '0';

		//--------------------------------------------------
		// Create the flash object, if the proper XML method
		// does not work (IE), then do it the old-school way

			if (flashUseXmlMethods) {
			  
        var browser=navigator.appName;

        var objTag = createElement('object');
        var objSubTag = createElement('object');
			  var objMovieParam = createElement('param');

 			  objTag.setAttribute('classid','clsid:D27CDB6E-AE6D-11cf-96B8-444553540000');
 			  objTag.setAttribute('width', '1');
 			  objTag.setAttribute('height', '1');

        objMovieParam.setAttribute('name', 'movie');
        objMovieParam.setAttribute('value', flashDetectObjectUrl);
        
        objSubTag.setAttribute('type', 'application/x-shockwave-flash');
        objSubTag.setAttribute('data', flashDetectObjectUrl);
        objSubTag.setAttribute('width', '1');
 			  objSubTag.setAttribute('height', '1');
        
        objTag.appendChild(objMovieParam);
        if(!(browser.toLowerCase().match('internet explorer'))){
          objTag.appendChild(objSubTag);
        }
			  divTag.appendChild(objTag);
			  			  
	
			  			  
		  }else{

				
				  flashHTML  = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="1" height="1">';
            flashHTML += '<param name="movie" value="/a/swf/common/flashDetect.swf" />';
            flashHTML += '<!--[if !IE]>-->';
            flashHTML += '<object type="application/x-shockwave-flash" data="/a/swf/common/flashDetect.swf" width="1" height="1">';
            flashHTML += '<!--<![endif]-->';
            flashHTML += '<!--[if !IE]>-->';
           flashHTML += ' </object>';
           flashHTML += ' <!--<![endif]-->';
          flashHTML += '</object>';

				divTag.innerHTML = flashHTML;

      }

		//--------------------------------------------------
		// Add out flashDetect script to the body

			bodyRef.appendChild(divTag);

	}

//--------------------------------------------------
// When the flash detection object has been
// loaded

	function flashDetectionResult (version) {

		//--------------------------------------------------
		// Remove the flash detection object... it is
		// no longer required. But you cant actually
		// remove it, because IE5 MAC crashes when you
		// try to refresh the page, and you cant do
		// a "display: none" as NS 6.2 crashes on refresh

			var flashDetectObject = document.getElementById('flashDetectObject');
			if (flashDetectObject) {
				flashDetectObject.style.left = '-10px';
			}

		//--------------------------------------------------
		// If this version of flash is good enough,
		// then store the value and continue to process
		// it, otherwise restore the alternative.

			version = parseInt(version);

			if (version >= flashRequired) {
				setFlashAvailable (version);
				flashReplaceProcess();
			} else {

				setFlashAvailable (-2); // HARD DISABLE
				flashRestoreAlt();
			}

	}

//--------------------------------------------------
// The function which will process the replacement
// of the flash objects. This function should ONLY
// be called if we know that the client can do flash

	function flashReplaceProcess () {

		//--------------------------------------------------
		// Go though each of the objects and try to
		// replace them (if they exist yet).

			for (var k=(flashObjects.length - 1); k >= 0; k--) {
				var flashObject = flashObjects[k];
				
				var objHolder = document.getElementById(flashObject.divId);
				if (objHolder) {

					//--------------------------------------------------
					// Add the flashHolder class to the main div
					// so that it can be targeted by CSS

						cssjs('add', objHolder, 'flashHolder');

					//--------------------------------------------------
					// Remove all the child nodes by sending them
					// off the screen, but add a class to them, so
					// we can bring them back (if nessary).

						var ch = objHolder.childNodes;
						var chLen = ch.length;

						for (i=(chLen-1); i>= 0; i--) {
							if (ch[i].style) {

 								cssjs('add', ch[i], 'flashAlternative');

								ch[i].style.position = 'absolute';
								ch[i].style.left = '-10000px';
								ch[i].style.height = '1px';
								ch[i].style.overflow = 'auto';

 							} else {
 								objHolder.removeChild(ch[i]);
 							}
						}

					//--------------------------------------------------
					// Create the flash object. If this fails the
					// user has a bad browser (IE) and has to be
					// told how to-do things incorrectly
					
          	var browser=navigator.appName;
          	var browserVendor = navigator.vendor;
					
            if (flashUseXmlMethods) {

                var objTag = createElement('object');
                var objSubTag = createElement('object');
        			  var objMovieParam = createElement('param');
        			  var objMovieParam2 = createElement('param');
                  
             //   objTag.setAttribute('id', flashObject.flashId);

         			  objTag.setAttribute('classid','clsid:D27CDB6E-AE6D-11cf-96B8-444553540000');
         			  objTag.setAttribute('width', flashObject.flashWidth);
         			  objTag.setAttribute('height', flashObject.flashHeight);

                objMovieParam.setAttribute('name', 'movie');
                objMovieParam.setAttribute('value', flashObject.flashUrl);
                
                objMovieParam2.setAttribute('name', 'wmode');
                objMovieParam2.setAttribute('value', 'transparent');

                objSubTag.setAttribute('id', flashObject.flashId);

                objSubTag.setAttribute('type', 'application/x-shockwave-flash');
                objSubTag.setAttribute('data', flashDetectObjectUrl);
                objSubTag.setAttribute('width', flashObject.flashWidth);
         			  objSubTag.setAttribute('height', flashObject.flashHeight);

                objSubTag.appendChild(objMovieParam);
                objTag.appendChild(objMovieParam);
                if(!browser.toLowerCase().match('internet explorer')){
                  objTag.appendChild(objSubTag);
                }
        			  divTag.appendChild(objTag);
              
            }else{ 
							//--------------------------------------------------
							// Build the html
                  var flashHTML = '';
                  
                  var mainFlashId = flashObject.flashId;
                  if(!browser.toLowerCase().match('internet explorer') && !(browserVendor.toLowerCase().match('google') || browserVendor.toLowerCase().match('apple'))){
                    mainFlashId = mainFlashId+'2';
                  }
                  
								   flashHTML += '<object id="' + mainFlashId + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + flashObject.flashWidth + '" height="' + flashObject.flashHeight + '" class="flashObject">';

                    flashHTML += '<param name="movie" value="' + flashObject.flashUrl + '" />';
                    flashHTML += '<param name="allowScriptAccess" value="always" />';

    								if (flashObject.flashBgColour == 'transparent') {
    									flashHTML += '<param name="wmode" value="transparent" />';
    								} else {
    									flashHTML += '<param name="bgcolor" value="' + flashObject.flashBgColour + '" />';
    								}
                    flashHTML += '<!--[if !IE]>-->';
                    flashHTML += '<object id="' + flashObject.flashId + '" type="application/x-shockwave-flash" data="' + flashObject.flashUrl + '" width="' + flashObject.flashWidth + '" height="' + flashObject.flashHeight + '" class="flashObject">';
                    if (flashObject.flashBgColour == 'transparent') {
    									flashHTML += '<param name="wmode" value="transparent" />';
    								} else {
    									flashHTML += '<param name="bgcolor" value="' + flashObject.flashBgColour + '" />';
    								}
                    flashHTML += '<!--<![endif]-->';
                    flashHTML += '<!--[if !IE]>-->';
                    flashHTML += '</object>';
                    flashHTML += '<!--<![endif]-->';
                  flashHTML += '</object>';

							//--------------------------------------------------
							// Add it to the holder

								objHolder.innerHTML = flashHTML;

              }
					//--------------------------------------------------
					// Restore visibility to this holder

						objHolder.style.visibility = 'visible';

				}
			}

		//--------------------------------------------------
		// Fix IE5+6 WIN where it will stops animated gifs

			if (flashReloadGifs) {
				var images = document.getElementsByTagName('img');
				for (var i=images.length; i--;){
					if (images[i].src.match(/\.gif/i)) {
						images[i].src = images[i].src;
					}
				}
			}

		//--------------------------------------------------
		// Add the flash enable and disable links

			flashDisableLinks();

	}

//--------------------------------------------------
// Function to restore the flash alternatives
// if we should give up.

	function flashRestoreAlt () {
		for (var k=(flashObjects.length - 1); k >= 0; k--) {
			var objHolder = document.getElementById(flashObjects[k].divId);
			if (objHolder) {

				objHolder.style.visibility = 'visible';
 				objHolder.style.width = 'auto';
 				objHolder.style.height = 'auto';

			}
		}
	}

//--------------------------------------------------
// Function to add the flash on / off links

	function flashDisableLinks () {
		
		//--------------------------------------------------
		// If there is a custom flashDisableLinksCust 
		// event handler
		
			if (typeof flashDisableLinksCust=="function") {
				flashDisableLinksCust(flashAvailable);
			}
		
		//--------------------------------------------------
		// Generic holder
	
			var flashDisableLinks = document.getElementById('flashDisableLinks');
			if (flashDisableLinks) {

				//--------------------------------------------------
				// Give up if the links already exist

					var linkE = document.getElementById('flashEnableLink');
					var linkD = document.getElementById('flashDisableLink');
					if (linkE || linkD) {
						return;
					}

				//--------------------------------------------------
				// Set the enable/disable link urls, while removing
				// any reference to the "flashReplace" variable

					var query = window.location.search;
					query = query.replace(/^\?/, '');
					query = query.replace(/(^|&)flashReplace=[^&]*/gi, '');

					if (query != '') {
						query = '&' + query;
					}

					var enableUrl = './?flashReplace=true' + query;
					var disableUrl = './?flashReplace=false' + query;

				//--------------------------------------------------
				// Create the link elements and nodes

					var enableLink = createElement('a');
					var disableLink = createElement('a');

					var beforeContent = document.createTextNode(flashBeforeLinkText);
					var enableContent = document.createTextNode(flashEnableLinkText);
					var betweenContent = document.createTextNode(flashBetweenLinkText);
					var disableContent = document.createTextNode(flashDisableLinkText);
					var afterContent = document.createTextNode(flashAfterLinkText);

				//--------------------------------------------------
				// Setup the links

					enableLink.setAttribute('href', enableUrl);
					enableLink.setAttribute('id', 'flashEnableLink');
					disableLink.setAttribute('href', disableUrl);
					disableLink.setAttribute('id', 'flashDisableLink');

				//--------------------------------------------------
				// Set one as current - setAttribute() does not
				// work with the class on IE5+6 WIN and IE5 MAC

					if (flashAvailable > 0) {
						cssjs('add', enableLink, 'current');
					} else {
						cssjs('add', disableLink, 'current');
					}

				//--------------------------------------------------
				// Add to the flashDisableLinks holder

					enableLink.appendChild(enableContent);
					disableLink.appendChild(disableContent);

					flashDisableLinks.appendChild(beforeContent);
					flashDisableLinks.appendChild(enableLink);
					flashDisableLinks.appendChild(betweenContent);
					flashDisableLinks.appendChild(disableLink);
					flashDisableLinks.appendChild(afterContent);

			}

	}

	
	
	
function searchUrl(re, str){
   if (str.search(re) != -1)
      return true;
   else
      return false;
}
	
	
var MM_contentVersion = 6;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
		var words = navigator.plugins["Shockwave Flash"].description.split(" ");
	    for (var i = 0; i < words.length; ++i)
	    {
		if (isNaN(parseInt(words[i])))
		continue;
		var MM_PluginVersion = words[i]; 
	    }
	var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
   && (navigator.appVersion.indexOf("Win") != -1)) {
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
	document.write('on error resume next \n');
	document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
	document.write('</SCR' + 'IPT\> \n');
}
if ( MM_FlashCanPlay ) {
} else{
	var noFlash = 1;
}
