
	/**
	 * Flash check script, for detecting flash (version) and placing a flash movie
	 *  
	 * @param	string		src				The source of the flash movie
	 * @param	string		id				The id of the flash movie
	 * @param	integer		width			The width of the flash movie
	 * @param	integer		height			The height of the flash movie
	 * @param	integer		majorversion	Minimal flash version required by client
	 * @author	Stephan van Opstal <stephan@netvlies.nl>
	*/

	function nvsFlash(src, id, width, height, majorversion)
	{
		// holds all the flash info (version , os etc.)
		var flashinfo = new Object;
	
		// set required movie attributes	
		var movie = {};
		movie['src'] = src;
		movie['id'] = id;
		movie['width'] = width;
		movie['height'] = height;
		movie['majorversion'] = majorversion;
		
		// set default options
		var options = {};
		options['detectorPath'] = '/swf/flashdetector.swf';
		options['message'] = 'Voor het volledig weergeven van deze website dient u een flashplayer[MIN_VERSION] te hebben ge&iuml;nstalleerd. Deze kunt u <a href="http://www.adobe.com/shockwave/download/index.cgi?Lang=Dutch&P1_Prod_Version=ShockwaveFlash" target="_blank">hier</a> downloaden.';
		
		// set default parameters\
		var params = {};
		params['quality'] = 'high';
		params['wmode'] = 'transparent';
		params['allowScriptAccess'] = 'always';
		params['allowFullScreen'] = 'true';
		
		// set functions to variables
		this.loadFlash = loadFlash;
		this.placeFlash = placeFlash;
		this.detectFlash = detectFlash;
		this.checkVersion = checkVersion;
		this.setParam = setParam;
		this.setOption = setOption;
		
		// set custom options
		function setOption(name, value)
		{
			options[name] = value;
		}
		
		// set the custom parameters		
		function setParam(name, value)
		{
			params[name] = value;
		}
		
		// LOAD FLASH
		function loadFlash(obj)
		{
			// remember the obj name for later use
			flashinfo.obj = obj;			
			// proceed to detecting flash
			this.detectFlash();
		}

		// detect if flash is installed
		function detectFlash()
		{
			// check if a detection cookie is set	
			var yumyum = document.cookie.split("; ");
			for(var i=0;i<yumyum.length;i++) if(yumyum[i].split("=")[0]=='flashversion') this.checkVersion(yumyum[i].split('=')[1]);
			
			// Flash is not previously detected in this session, adding detector
			if(!flashinfo.detected)
			{
				var div = document.createElement('div');
				div.style.position = 'absolute';
				div.style.left = '-100px';
				div.style.top = '-100px';
				
				var htmlcode ='<object id="xxx" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="1" height="1">';
					htmlcode+='<param name="movie" value="'+options['detectorPath']+'" />';
				    htmlcode+='<embed name="xxx" src="'+options['detectorPath']+'" width="1" height="1" type="application/x-shockwave-flash" plug inspage="http://www.macromedia.com/go/getflashplayer"></embed>'; 
				    htmlcode+='</object>';

				div.innerHTML = htmlcode;
				document.body.appendChild(div);
			}
		}
		
		// function trigger by detector swf for checking flash version
		function checkVersion(version)
		{
			// recording flash version into the cookies
			if(document.cookie.indexOf('flashversion') < 0) document.cookie = "flashversion="+version;
			flashinfo.detected = true;

			var version=version.split(',');
			flashinfo.ostag = version[0].split(' ')[0];
			flashinfo.version = new Object;
			flashinfo.version.major = parseInt(version[0].split(' ')[1]);
			flashinfo.version.minor = parseInt(version[1]);
			flashinfo.version.revision = parseInt(version[2]);
			
			// call core function to append flash object
			this.placeFlash(flashinfo.obj);
		}
		
		// place the actual flash movie		
		function placeFlash(obj)
		{
			// check if object is a string
			if(typeof obj == 'string') var obj = document.getElementById(obj);
			
			// set majorversion to 0 if not set
			if(!movie['majorversion']) movie['majorversion'] = 0;
			
			// continue if flash is detected
			if(flashinfo.detected == true)
			{
				// client flash version is higher than minimal version
				if(movie['majorversion'] <= flashinfo.version.major)
				{
					obj.style.margin = 0;
					obj.style.padding = 0;
					
					// create html object
					var htmlcode ='<object ';
						htmlcode+='classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
						htmlcode+='codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
						htmlcode+='width="'+movie['width']+'" ';
						htmlcode+='height="'+movie['height']+'"';
						
						if(movie['id'] != undefined) {
							htmlcode+=' id="'+movie['id']+'"';
						}
						
						htmlcode+='>';
						htmlcode+='<param name="movie" value="'+movie['src']+'" />';
						
						//add parameters for <param>
						for(var key in params) htmlcode += '<param name="'+ key +'" value="'+ params[key] +'" />';
						
					    htmlcode+='<embed ';
						htmlcode+='src="'+movie['src']+'" ';
						
						//add parameters for <embed>
						for(var key in params) htmlcode += ''+ key +'="'+ params[key] +'" ';

						htmlcode+='width="'+movie['width']+'" ';
						htmlcode+='height="'+movie['height']+'" ';
						htmlcode+='type="application/x-shockwave-flash" ';
						htmlcode+='plug inspage="http://www.macromedia.com/go/getflashplayer"';
						
						if(movie['id'] != undefined) { 
							htmlcode+=' name="'+id+'"';
						}
						
						htmlcode+='></embed>';
						htmlcode+='</object>';
					
					// append html object
					obj.innerHTML = htmlcode;

				}
				else // flash version too low
				{					
					if(movie['majorversion'] != undefined)
					{
						message = options['message'].replace('[MIN_VERSION]', ' '+movie['majorversion']);
					}

					// show message
					obj.innerHTML = message;
				}
			}
		}
	}
