// <![CDATA[

var PlayerWidget = Class.create(
{
	initialize: function()
	{
		
		if(typeof swfobject == 'undefined')
		{
			return; 
		}
		else
		{
			var bg     = this.createBg();
			var videos = $$('#aside a.video');
			
			this.redraw();

			//this.player = swfobject.createSWF(att, par, pane.id);
			
			
//			swfobject.embedSWF("/flash/player_flv_maxi.swf", pane.id, "320", "240", "9.0.0", "/scripts/lib/swfobject/expressInstall.swf", null, {movie: '/flash/player_flv_maxi.swf', wmode: 'transparent'});
			videos.each(function(v)
			{
				v.observe('click', function(event){
					event.stop();
					
					if(this.bg.visible())
					{
						this.stopFLV();
					}
					else
					{
						this.playFLV(v.href);
					}
				}.bind(this));
			}.bind(this));
		}
	},
	
	togglePlayer: function()
	{
		if(this.bg.visible())
		{
			this.bg.fade({duration:.2});
		}
		else
		{
			this.bg.appear({duration: .2, from:0, to: .8});
		}
	},
	
	createBg: function()
	{
		this.bg = new Element('div', {id: 'ACOFI-player_bg'});
		
		$(document.body).insert({bottom: this.bg.hide()});
		
		this.bg.observe('window:resize', this.redraw.bind(this));
		this.bg.observe('click', this.stopFLV.bind(this));
		
		return this.bg;
	},
	
	createPane: function()
	{
		this.pane = new Element('div', {id: 'ACOFI-player_pane'});
		this.anim = new Element('div', {id: 'ACOFI-player_anim'});
		this.anim.update('<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>');
			
		$(document.body).insert({bottom: this.pane.insert(this.anim)});
		this.redraw();

		return this.anim;
	},
	
	removePane: function()
	{
		this.pane.remove();
	},
	
	redraw: function()
	{
		var scr = document.viewport.getDimensions();

		this.bg.setStyle({position: 'fixed', zIndex: 10000, top: '0px', left: '0px', width: scr.width + 'px', height: scr.height + 'px', backgroundColor: '#000000', opacity: .8});
		if(this.pane)
		{
			this.pane.setStyle({position: 'fixed', zIndex: 10001, width: '480px', height: '360px', left: ((scr.width-480)/2) + 'px', top: ((scr.height-360)/2) + 'px'});
		}
	},
		
	playFLV: function(filename)
	{
		var rand = new Date();
		var vars = {
			flv: filename + '?time=' + rand.getTime(),
			autoplay: 1,
			autoload: 1,
			buffermessage: '',
			showvolume: 1,
			showtime: 1,
			showplayer: 'autohide',
			showfullscreen: 1
		};
		var att  = {id: 'playerMovie', name: 'playerMovie'};
		var par  = {swliveconnect: 'true', wmode: 'transparent'};
		
		this.createPane();
		
		this.togglePlayer();
		swfobject.embedSWF("/flash/player_flv_maxi.swf", this.anim.id, "480", "360", "9.0.16.60", "/scripts/lib/swfobject/expressInstall.swf", vars, par, att);
		//o = swfobject.getObjectById('playerMovie');
		//o.SetVariable('player:jsPause', '');
	},
	
	stopFLV: function()
	{
		swfobject.removeSWF(this.anim.id);
		this.removePane();
		this.togglePlayer();
	}
});

document.observe('dom:loaded', function()
{
	new PlayerWidget();

	var vars = {
			flv: 'http://www.acofi.com/medias/anims/anim_cia.swf'
		};
		var att  = {id: 'PEA-immobilier', name: 'PEA-immobilier'};
		var par  = {swliveconnect: 'true', wmode: 'transparent'};

	swfobject.embedSWF("/medias/anims/anim_cia.swf", "PEA-immobilier", "196", "136", "9.0.16.60", "/scripts/lib/swfobject/expressInstall.swf", vars, par, att);
});

// ]]>