Videos = function()
{
	var data = null;
	var WIDTH = 415;
	var HEIGHT = 380;

	var curr_ind = 0;

	var players = {
		'cnbc': '<object height="' + HEIGHT + '" width="' + WIDTH + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+
				' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0">'+
				'<param name="type" value="application/x-shockwave-flash" />'+
				'<param name="allowfullscreen" value="true" />'+
				'<param name="allowscriptaccess" value="always" />'+
				'<param name="quality" value="best" />'+
				'<param name="scale" value="noscale" />'+
				'<param name="wmode" value="transparent" />'+
				'<param name="bgcolor" value="#000000" />'+
				'<param name="salign" value="lt" />'+
				'<param name="movie" value="http://plus.cnbc.com/rssvideosearch/action/player/id/[VID]/code/cnbcplayershare" />'+
				'<embed name="cnbcplayer"'+
				' pluginspage="http://www.macromedia.com/go/getflashplayer"'+
				' allowfullscreen="true"'+
				' allowscriptaccess="always"'+
				' bgcolor="#000000"'+
				' height="' + HEIGHT + '"'+
				' width="' + WIDTH + '"'+
				' quality="best"'+
				' wmode="transparent"'+
				' scale="noscale"'+
				' salign="lt"'+
				' src="http://plus.cnbc.com/rssvideosearch/action/player/id/[VID]/code/cnbcplayershare"'+
				' type="application/x-shockwave-flash"'+
				' />'+
				'</object>',

		'wjs': '<object width="' + WIDTH + '" height="' + HEIGHT + '">'+
				'<param name="movie" value="http://s.wsj.net/media/swf/main.swf"></param>'+
				'<param name="allowFullScreen" value="true"></param>'+
				'<param name="allowscriptaccess" value="always"></param>'+
				'<param name="FlashVars"'+
				' value="videoGUID={[VID]}&playerid=1000&plyMediaEnabled=1&configURL=http://wsj.vo.llnwd.net/o28/players/&autoStart=false"'+
				' base="http://s.wsj.net/media/swf/"&name="flashPlayer">'+
				'</param>'+
				'<embed src="http://s.wsj.net/media/swf/main.swf"'+
				' bgcolor="#FFFFFF"'+
				' flashVars="videoGUID={[VID]}&playerid=1000&plyMediaEnabled=1&configURL=http://wsj.vo.llnwd.net/o28/players/&autoStart=false"'+
				' base="http://s.wsj.net/media/swf/"'+
				' name="flashPlayer"'+
				' width="' + WIDTH + '"'+
				' height="' + HEIGHT + '"'+
				' seamlesstabbing="false"'+
				' type="application/x-shockwave-flash"'+
				' swLiveConnect="true"'+
				' pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'+
				'</embed>'+
				'</object>',

		'reuters': '<object type="application/x-shockwave-flash" data="http://static.reuters.com/resources/flash/include_video.swf?edition=US&videoId=[VID]"'+
					' width="' + WIDTH + '" height="' + HEIGHT + '">'+
					'<param name="wmode" value="transparent" />'+
					'<param name="movie" value="http://www.reuters.com/resources/flash/include_video.swf?edition=US&videoId=[VID]" />'+
					'<embed src="http://www.reuters.com/resources/flash/include_video.swf?edition=US&videoId=[VID]"'+
					' type="application/x-shockwave-flash"'+
					' wmode="transparent"'+
					' width="' + WIDTH + '"'+
					' height="' + HEIGHT + '">'+
					'</embed>'+
					'</object>'
	};

	return {
		get_thumbs_html: function(max_len)
		{
			var res = '<div style="overflow:hidden;">';

			for (var i = 0; i < Math.min(max_len, data.length); i++)
			{
				if (i!=0 && i%7==0) res += '<br style="clear:both;" />';

				res += '<img src="/images/videos/' + data[i][0] + '.jpg"'+
						' style="cursor:pointer;_cursor:hand;border:1px solid #000;float:left;margin:0 2px 2px 0;width:80px;height:59px;"'+
						' onclick="return Videos.show(' + i + ')"'+
						' alt="' + data[i][2] + '"'+
						' title="' + data[i][2] + '"'+
						' />';
			}

			res += '</div>';

			if (data.length > max_len) {
				res += '<a href="javascript:void(0)" onclick="return Videos.show_more()">More...</a>';
			}
			
			if (data.length == max_len) {
				res += '<a href="javascript:void(0)" onclick="return Videos.show_less()">Less..</a>';
			}

			return res;
		},

		get_html: function(_data, max_len)
		{
			data = _data;
			var res = '<div class="videos">';
			res += '<div id="video_thumbs" style="margin-bottom:10px;">' + Videos.get_thumbs_html(max_len) + '</div>';
			res += '<div style="text-align:center;">';
			res += '<img src="/images/prev_video.png" style="cursor:pointer;cursor:hand;" onclick="return Videos.prev()" alt="Prev" />';
			res += '<img src="/images/next_video.png" style="cursor:pointer;cursor:hand;" onclick="return Videos.next()" alt="Next" />';
			res += '</div>';
			//res += '<div id="video_title" style="font:bold 12px Verdana;text-align:center;background-color:#efefef;padding-top:5px;width:100%;border:1px solid #cccccc;"></div>';
			res += '<div style="background-color:#000;width:100%;overflow:hidden;"><div id="video_player" style="float:left;background-color:#000;width:415px;"></div><br />';
			res += '<div id="video_description" style="float:right;color:#fff;padding:6px; padding-right:9px; width:160px;font:normal 11px Verdana;line-height:18px;"></div></div>';
			res += '<div style="text-align:center;clear:both;">';
			res += '<img src="/images/prev_video.png" style="cursor:pointer;cursor:hand;" onclick="return Videos.prev()" alt="Prev" />';
			res += '<img src="/images/next_video.png" style="cursor:pointer;cursor:hand;" onclick="return Videos.next()" alt="Next" />';
			res += '</div>';
			
			res += '</div>';

			return res;
		},

		show_more: function()
		{
			document.getElementById('video_thumbs').innerHTML = Videos.get_thumbs_html(data.length);
			return false;
		},
		
		show_less: function()
		{
			document.getElementById('video_thumbs').innerHTML = Videos.get_thumbs_html(21);
			return false;
		},
		
		insert_here: function(_data)
		{
			document.write(Videos.get_html(_data, 3*7));
			setTimeout('Videos.show(0)', 1);
		},

		prev: function()
		{
			Videos.show((curr_ind + data.length - 1) % data.length);
			return false;
		},

		next: function()
		{
			Videos.show((curr_ind + 1) % data.length);
			return false;
		},

		show: function(ind)
		{
			curr_ind = ind;

			var guid = data[ind][1];
			var title = data[ind][3];
			var descr = data[ind][2];
			var date = data[ind][4];

			var spl = guid.split(':');
			var player_type = spl[0];
			var video_id = spl[1];

			document.getElementById('video_player').innerHTML = players[player_type].replace(/\[VID\]/g, video_id);
			document.getElementById('video_description').innerHTML = '<span style="font:bold 15px Verdana">'+ title +'</span><br />'+ date +'<br /><br />'+ descr;
			//document.getElementById('video_title').innerHTML = title;
			return false;
		}
	}
}();
