/**
 * Doc SWFObject : http://code.google.com/p/swfobject/wiki/documentation
 */

/**
 * Needed Flash version to play anims
 */
var sFlashVersion = '9.0.0';

/**
 * Special Flash used by swfobject
 */
var sExpressInstallUrl = '/flash/expressInstall.swf';

/**
 * Attributes of the tag, can be :
 * id (NOTE: when undefined, the object element automatically inherits the id from the alternative content container element)
 * name
 * styleclass (used instead of class, because this is also an ECMA4 reserved keyword)
 * align 
 */
var oDefaultAttributes = {
	align: 'middle'
};

/**
 * Parameters for the Flash (more info : http://kb2.adobe.com/cps/127/tn_12701.html), can be :
 * play
 * loop
 * menu
 * quality
 * scale
 * salign
 * wmode
 * bgcolor
 * base
 * swliveconnect
 * flashvars
 * devicefont
 * allowscriptaccess
 * seamlesstabbing
 * allowfullscreen
 * allownetworking 
 */
var oDefaultParameters = {
	allowScriptAccess: 'sameDomain',
	allowFullScreen: true,
	loop: true,
	quality: 'high',
	bgcolor: 'transparent',
	scale: 'exactfit',
	wmode: 'transparent',
	salign: 'tr'
};

/**
 * Load a flash
 * @param sUrl
 * @param sId
 * @param iWidth
 * @param iHeight
 * @param sFlashvars
 * @param oParameters
 * @param oAttributes
 */
function loadFlash(sUrl, sId, iWidth, iHeight, sFlashvars, oParameters, oAttributes) {
	if (typeof sFlashvars !== 'string') {
		sFlashvars = '';
	}
	if (typeof oParameters !== 'object') {
		oParameters = {};
	}
	if (typeof oAttributes !== 'object') {
		oAttributes = {};
	}
	// On écrase les "default" par leur valeur réglée
	oDefaultParameters = $.extend(oDefaultParameters, oParameters);
	oDefaultAttributes = $.extend(oDefaultAttributes, oAttributes, {name: sId});
	// Cas particulier de l'interstitiel
	if ('flashTransparent' == sId) {
		swfobject.embedSWF(sUrl, sId, iWidth, iHeight, sFlashVersion, sExpressInstallUrl, sFlashvars, oDefaultParameters, oDefaultAttributes, initFlashTrans);
	}
	else {
		swfobject.embedSWF(sUrl, sId, iWidth, iHeight, sFlashVersion, sExpressInstallUrl, sFlashvars, oDefaultParameters, oDefaultAttributes);
	}
}

/**
 * Look for flash to load in the document
 */
$(document).ready(function() {
	// Verifie si la personne a FLASH
	var playerVersion = swfobject.getFlashPlayerVersion();
	if (playerVersion.major != 0) {
		var i = 0;
		var aFlash = $('div[flashurl]');
		if (aFlash.length > 0) {
			// Parcours tous les markups de flash 
			aFlash.each(function() {
				var iId = $(this).attr('id');
				// On efface tout le contenu du parent au besoin (pour retirer les éléments "sous le flash")
				if ($(this).attr('flashreset') == 'true') {
					$(this).parent().children().each(function(){if(iId!=$(this).attr('id')){$(this).remove()}});
					$(this).parent().css('background-image', 'none');
				}
				// Lance l'animation
				loadFlash($(this).attr('flashurl'), $(this).attr('id'), $(this).attr('flashwidth'), $(this).attr('flashheight'), $(this).attr('flashvars'), $(this).attr('flashparameters'), $(this).attr('flashattributes') );
				if ('flashTransparent' == $(this).attr('id')) {
					iWidth = $(this).attr('flashwidth');
					iHeight = $(this).attr('flashheight');
				}
			});
		}
	}
	else {
		if ($('#noflashheader').length > 0) {
			$('#noflashheader').show();
		}
	}
});
