function cn_addLoadEvent(func) {
	if (window.addEventListener) {
		window.addEventListener("load", func, false);
	}
	else {
		if (window.attachEvent) {
			window.attachEvent("onload", func);
		}
	}
}

if (typeof(cn_write_flash)=="undefined") {
	cn_write_flash = function(src, width, height, version, wmode, id, vars) {
		if (wmode=="") { wmode="opaque"; }
		document.write('<object ');
		if (id!="") document.write('id="' + id + '" ');
		document.write('width="' + width + '" height="' + height + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="' + document.location.protocol + '//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + version + ',0,0,0" align="center">');
		document.write('<param name="movie" value="' + src + '"><param name="quality" value="high"><param name="wmode" value="' + wmode + '">');
		if (typeof(vars)!="undefined" && vars!="") { document.write('<param name="FlashVars" value="' + vars + '">'); }
		document.write('<EMBED width="' + width + '" height="' + height + '" src="' + src + '" quality="high" wmode="' + wmode + '" align="center" swLiveConnect="true" ');
		if (typeof(vars)!="undefined" && vars!="") { document.write(' FlashVars="' + vars + '" '); }
		if (typeof(id)!="undefined" && id!="") { document.write(' name="' + id + '" '); }
		document.write('type="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">');
		document.write('</embed></object>');
	}
}


if (typeof(cn_get_window_dimensions)=='undefined') {
	cn_get_window_dimensions=function()
	{
		var dimensions;
		if(window.innerWidth != null)
		{
			dimensions = new Array(window.innerWidth, window.innerHeight)
		}
		else if (document.documentElement && document.documentElement.clientWidth)
		{
			dimensions = new Array(document.documentElement.clientWidth, document.documentElement.clientHeight);
		}
		else if (document.body != null)
		{
			dimensions = new Array(document.body.clientWidth, document.body.clientHeight);
		}
		return dimensions;
	}
}


if (typeof(cn_write_flv_player)=="undefined") {
	cn_write_flv_player = function(url_flv, autostart, clicktext, width, height, num, intro_swf, intro_duration) {
		var id='cn_video_' + num;
		var window_dimensions = cn_get_window_dimensions();
		var big_width=window_dimensions[0];
		var big_height=Math.round(height*big_width/width)+18;

		var src='/commun/flvplayer/flvplayer3.swf?file=' + url_flv + '&displayheight=' + height + '&overstretch=fit&autostart=' + autostart + '&big_width=' + big_width + '&big_height=' + big_height + '&player_id=' + id + '&intro_swf=' + intro_swf + '&intro_duration=' + intro_duration + '&clicktext=' + clicktext;
		var vars='';
		var version=9;
		var wmode='opaque';
		
		document.write('<object ');
		if (id!="") document.write('id="' + id + '_flash" ');
		document.write('width="' + width + '" height="' + height + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="' + document.location.protocol + '//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + version + ',0,0,0" align="center">');
		document.write('<param name="movie" value="' + src + '"><param name="quality" value="high"><param name="allowfullscreen" value="true"><param name="allowscriptaccess" value="always"><param name="wmode" value="' + wmode + '">');
		if (typeof(vars)!="undefined" && vars!="") { document.write('<param name="FlashVars" value="' + vars + '">'); }
		document.write('<embed width="' + width + '" height="' + height + '" src="' + src + '" allowfullscreen="true" allowscriptaccess="always" quality="high" wmode="' + wmode + '" align="center" swLiveConnect="true" ');
		if (typeof(vars)!="undefined" && vars!="") { document.write(' FlashVars="' + vars + '" '); }
		if (typeof(id)!="undefined" && id!="") { document.write(' name="' + id + '_flash" '); }
		document.write('type="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">');
		document.write('</embed></object>');
	}
}


if (!cn_video_dimensions) {
	var cn_video_dimensions=new Array(10);
}

if (typeof(cn_toggle_zoom_player)=="undefined") {
	cn_toggle_zoom_player=function(player_id) {
		var expression = /(\d+)/;
		expression.exec(player_id);
		num_id=RegExp.$1;
		if (cn_video_dimensions[num_id]) {
			if (cn_video_dimensions[num_id]['is_zoomed']) {
				cn_unzoom_player(player_id);
			}
			else {
				cn_zoom_player(player_id);
			}
		}
		else {
			cn_zoom_player(player_id);
		}
	}
}

if (typeof(cn_zoom_player)=="undefined") {
	cn_zoom_player=function(player_id) {
		var window_dimensions = cn_get_window_dimensions();
		scroll(0,0);
		var expression = /(\d+)/;
		expression.exec(player_id);
		num_id=RegExp.$1;
	
		cn_video_dimensions[num_id]=new Array();
		cn_video_dimensions[num_id]['width']=parseInt(document.getElementById(player_id).style.width);
		cn_video_dimensions[num_id]['height']=parseInt(document.getElementById(player_id).style.height);
		cn_video_dimensions[num_id]['is_zoomed']=true;
	
		// masquer toutes les anims flash (because wmode = pas toujours opaque)
		flash_objects = document.getElementsByTagName('object');
		for (var i = 0; i < flash_objects.length; i++) {
			if (flash_objects[i].id.indexOf('cn_video_')==-1) {
				flash_objects[i].style.display='none';
			}
		}
		
		document.getElementById(player_id).style.position='absolute';
		document.getElementById(player_id).style.overflow='visible';
		document.getElementById(player_id).style.zindex=999999;
		document.getElementById(player_id).style.top='0px';
		document.getElementById(player_id).style.left='0px';
		document.getElementById(player_id).style.width=parseInt(window_dimensions[0])+'px';
		document.getElementById(player_id).style.height=parseInt(window_dimensions[1])+'px';
		document.body.style.overflow='hidden';
		if ((navigator.userAgent.indexOf('MSIE')>0) || (navigator.userAgent.indexOf('Opera')>0)) {
			document.getElementById(player_id+'_flash').Play();
		}
	}
}

if (typeof(cn_unzoom_player)=="undefined") {
	cn_unzoom_player=function(player_id) {
		var expression = /(\d+)/;
		expression.exec(player_id);
		num_id=RegExp.$1;
		cn_video_dimensions[num_id]['is_zoomed']=false;
		document.getElementById(player_id).style.position='relative';
		document.getElementById(player_id).style.zindex=1;
		document.getElementById(player_id).style.width=cn_video_dimensions[num_id]['width']+'px';
		document.getElementById(player_id).style.height=cn_video_dimensions[num_id]['height']+'px';
		document.body.style.overflow='auto';
		if ((navigator.userAgent.indexOf('MSIE')>0) || (navigator.userAgent.indexOf('Opera')>0)) {
			document.getElementById(player_id+'_flash').Play();
		}
		
		// on réaffiche tous les flash
		flash_objects = document.getElementsByTagName('object');
		for (var i = 0; i < flash_objects.length; i++) {
			if (flash_objects[i].id.indexOf('cn_video_')==-1) {
				flash_objects[i].style.display='block';
			}
		}
		
	}
}

if (typeof(cn_write_mp3_player)=="undefined") {
	cn_write_mp3_player = function(url_mp3_or_xml, autostart, repeat, width, num) {
		var id='cn_mp3_' + num;
		
		var src='/commun/mp3player/mp3player.swf?file=' + url_mp3_or_xml + '&repeat=' + repeat + '&autostart=' + autostart + '&player_id='+ id;
		var vars='';
		var version=8;
		var wmode='opaque';
	
		document.write('<object ');
		if (id!="") document.write('id="' + id + '" ');
		document.write('width="' + width + '" height="20" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="' + document.location.protocol + '//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + version + ',0,0,0" align="center">');
		document.write('<param name="movie" value="' + src + '"><param name="quality" value="high"><param name="wmode" value="' + wmode + '">');
		if (typeof(vars)!="undefined" && vars!="") { document.write('<param name="FlashVars" value="' + vars + '">'); }
		document.write('<EMBED width="' + width + '" height="20" src="' + src + '" quality="high" wmode="' + wmode + '" align="center" swLiveConnect="true" ');
		if (typeof(vars)!="undefined" && vars!="") { document.write(' FlashVars="' + vars + '" '); }
		if (typeof(id)!="undefined" && id!="") { document.write(' name="' + id + '" '); }
		document.write('type="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">');
		document.write('</embed></object>');
		
		var agt=navigator.userAgent.toLowerCase();
		var is_major = parseInt(navigator.appVersion);
		var is_minor = parseFloat(navigator.appVersion);
		var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
		var is_ie6 = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1));
		if (is_ie) {
			document.getElementById(id).outerHTML=document.getElementById(id).outerHTML;
		}
	}
}

if (typeof(gl_nav_flash_go)=="undefined") {
	gl_nav_flash_go = function(url, target) {
		if(target=='_self') {
			if(typeof(cn_doubledouv_dsp)!="undefined") {
				cn_doubledouv_dsp(url);
			}
			else {
				location.href=url;
			}
		}
		else {
			// on verra + tard si la nav en flash doit gérer des target _blank ou autre
			if(typeof(cn_doubledouv_dsp)!="undefined") {
				cn_doubledouv_dsp(url);
			}
			else {
				location.href=url;
			}
		}
	}
}


// vieux trucs


if (typeof(cn_write_flv_player_old)=="undefined") {
	cn_write_flv_player_old = function(url_flv, autostart, clicktext, width, height, num, intro_swf, intro_duration) {
		var id='cn_video_' + num;
		var window_dimensions = cn_get_window_dimensions();
		var big_width=window_dimensions[0];
		var big_height=Math.round(height*big_width/width)+18;

		var src='/commun/flvplayer/flvplayer3.swf?file=' + url_flv + '&autostart=' + autostart + '&big_width=' + big_width + '&big_height=' + big_height + '&player_id=' + id + '&intro_swf=' + intro_swf + '&intro_duration=' + intro_duration + '&clicktext=' + clicktext;
		var vars='';
		var version=8;
		var wmode='opaque';
		
		
		document.write('<div id="' + id + '" style="width:' + width + 'px; height:' + (height+18) + 'px; overflow:hidden;">');
		document.write('<object ');
		if (id!="") document.write('id="' + id + '_flash" ');
		document.write('width="100%" height="100%" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="' + document.location.protocol + '//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + version + ',0,0,0" align="center">');
		document.write('<param name="movie" value="' + src + '"><param name="quality" value="high"><param name="allowfullscreen" value="true"><param name="allowscriptaccess" value="always"><param name="wmode" value="' + wmode + '">');
		if (typeof(vars)!="undefined" && vars!="") { document.write('<param name="FlashVars" value="' + vars + '">'); }
		document.write('<embed width="100%" height="100%" src="' + src + '" allowfullscreen="true" allowscriptaccess="always" quality="high" wmode="' + wmode + '" align="center" swLiveConnect="true" ');
		if (typeof(vars)!="undefined" && vars!="") { document.write(' FlashVars="' + vars + '" '); }
		if (typeof(id)!="undefined" && id!="") { document.write(' name="' + id + '_flash" '); }
		document.write('type="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">');
		document.write('</embed></object></div>');
	}
}

