js.module('multimedia');

multimedia = {
	playVideo : function(el)
	{
		var wi=640;
		var hi=480;
		var wo = wi + 150;
		var ho = hi + 150;

		var vsrc =  $A(el, 'videosrc');
		var vid = $A(el, 'videoid');
		vid = $A(el, 'issite')=='1' ? '[video:' + vid + ']' : '[sitevideo:' + vid + ']';
		var vtitle = $A(el, 'title') ? $A(el, 'title') : ($A(el, 'videotitle') ? $A(el, 'videotitle') : '');

		visual.showFade(wo, ho, '<div><table cellpadding="0" cellspacing="0" border="0" align="center" width="93%"><tr><td align="center" class="deco_text">' + vtitle + '</td></tr></table><br /><br /><a style="display:block;width:'+wi+'px;height:'+hi+'px;" id="video_player"></a><br /><table cellpadding="0" cellspacing="0" border="0" width="93%" align="center"><tr><td align="center" style="color:gray;">'+js.strings.this_video_id+': <b>'+vid+'</b></td></tr><tr><td align="center" style="padding-top:10px;"><a class="deco_text" style="cursor:pointer" onclick="multimedia.hideVideo();">' + js.strings.button_close + '</a></td></td></tr></table></div>', function() { multimedia.initVideoPlayer($A(el, 'videosrc')); }, true);
	}
	,
	initVideoPlayer : function(curl)
	{
		flowplayer('video_player',
			{
				src :'/swf/flowplayer.swf',
				version: [10, 0],
				expressInstall : '/swf/flashinstall.swf',
				onFail : function() {
					$$('blend_td', '<div class="deco_text">'+js.strings.no_flash_player+'<br /><br /> <a href="http://get.adobe.com/flashplayer/" target="_blank">http://get.adobe.com/flashplayer/</a><br /><br /><a href="#" onclick="visual.hideFade(); return false;">'+js.strings.no_flash_player_close+'</a></div>');
				}
			}
					,
			{
				plugins: { controls: { width:'98%', borderRadius: '5', bottom:'5px' } },
				clip:  {
					url: curl,
					autoPlay: true,
					autoBuffering: true,
					onStart: multimedia.pauseOtherPlayers,
					onResume: multimedia.pauseOtherPlayers
				},
				play: { replayLabel: js.strings.play_again+'&nbsp;&nbsp;' }
			});
	}
	,
	hideVideo : function()
	{
		$f('video_player').stop();
		visual.hideFade();
	}
	,
	playAudio : function(el)
	{
		var wi = 500;
		var hi = 32;

		var wo = wi + 150;
		var ho = hi + 150 + 20;

		var vsrc =  $A(el, 'audiosrc');
		var aid = $A(el, 'audioid');
		aid = $A(el, 'issite')=='1' ? '[audio:' + aid + ']' : '[siteaudio:' + aid + ']';
		var atitle = $A(el, 'title') ? $A(el, 'title') : ($A(el, 'audiotitle') ? $A(el, 'audiotitle') : '');

		visual.showFade(wo, ho, '<div><table cellpadding="0" cellspacing="0" border="0" align="center" width="90%"><tr><td align="center" class="deco_text">' + atitle + '</td></tr></table><br /><br /><a style="display:block;width:'+wi+'px;height:'+hi+'px;" id="audio_player"></a><br /><table cellpadding="0" cellspacing="0" border="0" width="90%" align="center"><tr><td align="center" style="color:gray;">'+js.strings.this_audio_id+': <b>'+aid+'</b></td></tr><tr><td align="center" style="padding-top:10px;"><a class="deco_text" style="cursor:pointer" onclick="multimedia.hideAudio();">' + js.strings.button_close + '</a></td></tr></table></div>', function() { multimedia.initAudioPlayer($A(el, 'audiosrc')); }, true);
	}
	,
	initAudioPlayer : function(curl)
	{
		flowplayer('audio_player',
			{
				src :'/swf/flowplayer.swf',
				version: [10, 0],
				expressInstall : '/swf/flashinstall.swf',
				onFail : function() {
					$$('blend_td', '<div class="deco_text">'+js.strings.no_flash_player+'<br /><br /> <a href="http://get.adobe.com/flashplayer/" target="_blank">http://get.adobe.com/flashplayer/</a><br /><br /><a href="#" onclick="visual.hideFade(); return false;">'+js.strings.no_flash_player_close+'</a></div>');
				}
			}
					,
			{
				canvas : { backgroundColor: '#FFFFFF' },
				plugins: { controls: { fullscreen:false, stop:true, width:'98%', borderRadius: '5', bottom:'5px' } },
				clip:  {
					url: curl,
					autoPlay: true,
					autoBuffering: true,
					onBeforeBegin: multimedia.pauseOtherPlayers,
					onResume: multimedia.pauseOtherPlayers
				},
				play: { replayLabel: js.strings.play_again+'&nbsp;&nbsp;' }
			});
	}
	,
	hideAudio : function()
	{
		$f('audio_player').stop();
		visual.hideFade();
	}
	,
	loadAudio : function(ids, autoplay)
	{
		if(autoplay==undefined)
			autoplay=false;

		if(ids && ids.length>0)
		{
			for(var i=0; i<ids.length; i++)
			{
				if(!$('audio_player_' + ids[i]))
					continue;

				flowplayer('audio_player_' + ids[i], '/swf/flowplayer.swf',
					{
						canvas : { backgroundColor: '#FFFFFF' },
						plugins: { controls: { fullscreen:false, stop:true, width:'98%', borderRadius: '5', bottom:'5px' } },
						clip:  {
							url: $A('audio_player_' + ids[i], 'audiosrc'),
							autoPlay: (autoplay && autoplay==ids[i] ? true : false),
							autoBuffering: false,
							onBeforeBegin: this.pauseOtherPlayers,
							onResume: this.pauseOtherPlayers
						},
						play: { replayLabel: js.strings.play_again+'&nbsp;&nbsp;' }
					});
			}
		}
	}
	,
	loadVideo : function(ids, autoplay)
	{
		if(autoplay==undefined)
			autoplay=false;

		if(ids && ids.length>0)
		{
			for(var i=0; i<ids.length; i++)
			{
				if(!$('video_player_' + ids[i]))
					continue;

				flowplayer('video_player_' + ids[i],
						{
							src :'/swf/flowplayer.swf',
							version: [10, 0],
							expressInstall : '/swf/flashinstall.swf',
							onFail : function() {
								alert('Please go to http://get.adobe.com/flashplayer/ and install the latest Flash Player');
							}
						}
						,
						{

						canvas : { backgroundColor: '#FFFFFF' },
						plugins: { controls: { stop:true, width:'98%', borderRadius: '5', bottom:'5px' } },
						clip:  {
							url: $A('video_player_' + ids[i], 'videosrc'),
							autoPlay: (autoplay && autoplay==ids[i] ? true : false),
							autoBuffering: false,
							onBeforeBegin: this.pauseOtherPlayers,
							onResume: this.pauseOtherPlayers
						},
						play: { replayLabel: js.strings.play_again+'&nbsp;&nbsp;' }
					});
			}
		}
	}
	,
	pauseOtherPlayers : function (clip)
	{
		var myid = this.id();
		$f(myid).getControls().css({ backgroundColor: '#1535cc' });

		$f("*").each( function() {
			if(myid!=this.id())
			{
				this.getControls().css({ backgroundColor: '#25353C' });
				this.pause();
			}
		} )
	}
};