$(function() {	
	$(".playerimg").click(function() {
		var id = $(this).attr('class').match(/\d+/);
		show_vid(id);
		run_vid(id);
	});
	
	$('.videobox .close_btn').click(function() {
		hide_vid();
	});
	
	$('.videobox .close_btn').hover(
		function() {
			this.src = '/images/red_cross.gif';
		},
		function() {
			this.src = '/images/gray_cross.gif';
		}
	);
});

function run_vid(id) {
	var $this = $("#video_box" + id);
	var vid_link = $this.find("div").attr("title");
	var container = "player" + id;
	$f(
		container,
		"/comp/flowplayer/flowplayer-3.1.5.swf",
		{
			clip: {
				url: vid_link,
				autoPlay: true,
				autoBuffering: true
			}
		}
	);
}

function show_vid(id) {
	var width = $("#video_box" + id).css("width");
	$('#container').block({
		message: $('#video_box' + id),
		css: {
			top: '240px',
			width: width,
			left: '420px',
			cursor: 'default',
			border: '2px solid #ADA389',
			background: '#F6F4E7',
			padding: '20px'
		},
		overlayCSS: {
			cursor: 'default',
			backgroundColor: 'white'
		}
	});
	
	var y = $(window).height() / 2.0 - $('.blockMsg').outerHeight() / 2 + $(window).scrollTop();
	if (y < 0)
		y = 25;
	$('.blockMsg').css('top', y);
}

function hide_vid() {
	$('#container').unblock();
}