/**
 * Flash Detection Script
 * 
 * This script detects Flash 4 and higher.
 * 
 * Place detect_flash() in your page initialisation to make this script active.
 * To add a flash object to a specific object use:
 * load_flash(obj, src, width, height, majorversion);
 * You can call this function everywere in your code at any time,
 * before or after you called detect_flash(), but it will only work once detect_flash() is called.
 * 
 * JavaScript written by Stefan Thoolen <stefan@netvlies.nl>
 * Flash Detector object written by Maarten Verstraeten <maarten@netvlies.nl>
 */

/**
 * Default message when the minimum flash player is not detected
 */
if(no_valid_flash_message == undefined) {
	var no_valid_flash_message = 'Voor het volledig weergeven van deze website dient u een flashplayer[MIN_VERSION] te hebben geinstalleerd. Deze kunt u <a href="http://www.adobe.com/shockwave/download/index.cgi?Lang=Dutch&P1_Prod_Version=ShockwaveFlash" target="_blank">hier</a> downloaden.';
}

/**
 * Path to the Flash Detector object
 */
var flashdetector_swf = 'swf/flashdetector.swf';

/**
 * This Object contains all Flash version information
 * 
 * Recursive print of this object:
 * <code>
 *    flashinfo {
 *      detected    Boolean
 *      ostag       String
 *      version {
 *        major     Int
 *        minor     Int
 *        revision  Int
 *      }
 *    }
 * </code>
 */
var flashinfo = new Object;

/**
 * Starts the flash detection
 */
function detect_flash() {
	flashinfo.detected=false;
	// For debugging, to check the non-flash version
	if(document.location.search.search('noflash')>-1) return false;
	// Checks 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') cf(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 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="'+flashdetector_swf+'" />';
		    htmlcode+='<embed src="'+flashdetector_swf+'" 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);
	}
}

/**
 * Loads a specific flash source into an object
 * @param	object	obj				The container in which the Flash object must be placed
 * @param	string	src				The source link of the Flash object
 * @param	int		width			The width of the Flash object
 * @param	int		height			The height of the Flash object
 * @param	int		majorversion	If set, the object will be loaded in this flash version and newer
 * @param	string	flash_id		If set, the object will get this id (for calling it with javascript)
 */
function load_flash(obj, src, width, height, majorversion, flash_id) {
	if(typeof obj=='string') var obj=document.getElementById(obj);
	if(!majorversion) var majorversion=0;
	
	if(!flashinfo.detected) {
		flash_objects[flash_objects.length]=new Object;
		var that=flash_objects[flash_objects.length-1];
		that.container=obj;
		that.src=src;
		that.width=width;
		that.height=height;
		that.majorversion=majorversion;
		that.id=flash_id;
	} else {
		if(majorversion<=flashinfo.version.major) {		
			obj.style.margin = 0;
			obj.style.padding = 0;
			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="'+width+'" ';
				htmlcode+='height="'+height+'"';
				if(flash_id != undefined) {
					htmlcode+=' id="'+flash_id+'"';
				}
				htmlcode+='>';
			    htmlcode+='<param name="movie" value="'+src+'" />';
			    htmlcode+='<param name="wmode" value="transparent" />';
			    htmlcode+='<param name="quality" value="high" />';
			    htmlcode+='<param name="allowScriptAccess" value="always" />';
			    htmlcode+='<param name="allowFullScreen" value="true" />';
			    htmlcode+='<embed ';
				htmlcode+='src="'+src+'" ';
				htmlcode+='wmode="transarent" ';
				htmlcode+='quality="high" ';
				htmlcode+='width="'+width+'" ';
				htmlcode+='height="'+height+'" ';
				htmlcode+='allowScriptAccess="always" ';
				htmlcode+='allowFullScreen="true" ';
				htmlcode+='type="application/x-shockwave-flash" ';
				htmlcode+='plug inspage="http://www.macromedia.com/go/getflashplayer"';
				if(flash_id != undefined) { 
					htmlcode+=' name="'+flash_id+'"';
				}
				htmlcode+='></embed>';
				htmlcode+='</object>';
				
			obj.innerHTML=htmlcode;
		} else {
			// No-flash
			if(majorversion != undefined) {
				no_valid_flash_message = no_valid_flash_message.replace('[MIN_VERSION]', ' (minimaal versie ' + majorversion + ')'); 
			} else {
				no_valid_flash_message = no_valid_flash_message.replace('[MIN_VERSION]', '');
			}
			obj.innerHTML = no_valid_flash_message;
		}
	}
}

/**
 * Contains all load_flash() calls until detect_flash() is called.
 * @access private
 */
flash_objects=new Array();

/**
 * Flash Callback Function
 * This function is triggered by flashdetector.swf with a version string
 * @param	string	version			The version string of Flash 
 * @access private
 */
function cf(version) {
	// Recording flash version into the cookies
	if(document.cookie.indexOf('flashversion')<0) document.cookie="flashversion="+version;
	var version=version.split(',');
	flashinfo.detected=true;
	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]);
	
	for(var i=0;i<flash_objects.length;i++) {
		that=flash_objects[i];
		load_flash(that.container, that.src, that.width, that.height, that.majorversion, that.id);
	}
	flash_objects=null;
}
