$(function()
{
	$('a.video, #video_menu a').click(function(){
		if (($(this).attr("class") == 'selected') || ($(this).attr("class") == 'selected pause') || ($(this).attr("class") == 'pause selected'))
		{
			player.sendEvent('PLAY');
			return false;
		}
		else
		{
			showVideo($(this).attr("name"));
			room_name = $(this).attr("title");
			room_name = room_name.replace("&", "&amp;");
			$('#video_menu a').each(function(){
				if ($(this).html() == room_name)
				{
					$(this).addClass("selected");
				}
				else if (document.URL.indexOf("_rooms")>-1 || document.URL.indexOf("pagename=rooms")>-1 || document.URL.indexOf("&")>-1) $(this).removeClass("selected");
			});
		}
	});
	var y = 0;
	$('a.video').click(function(e){
		if ($(this).attr("class") != 'selected')
		{
			room_name = $(this).attr("title");
			room_name = room_name.replace("&", "&amp;");
			$('#video_menu a').each(function(){
				if ($(this).html() == room_name)
				{
					$(this).addClass("selected");
				}
				else if (document.URL.indexOf("_rooms")>-1 || document.URL.indexOf("pagename=rooms")>-1 || document.URL.indexOf("&")>-1) $(this).removeClass("selected");
			});
		}
		if ($(this).attr("href") == '#shadow_top')
		{
			page_url = document.URL;
			pos = page_url.indexOf('#shadow_top');
			if (pos > 0)
			{
				page_url = page_url.substring(0, pos);
			}
			$(this).attr("href", page_url + $(this).attr("href"));
		}
		y = e.pageY - e.screenY;
		//return false;
	});
	
	$('#video_player a.close').click(function(){
		if (document.URL.indexOf("sanderson")==-1 && document.URL.indexOf("martin")==-1) player.sendEvent('STOP');
		hideVideo();
		$("html").scrollTo({top:y, left:0});
		return false;
	});
	
	$('#video_menu a').click(function(){
		$('#video_menu a').removeClass('selected');
		$('#video_menu a').removeClass('pause');
		$(this).addClass('selected');
		if (document.URL.indexOf("sanderson")>-1 || document.URL.indexOf("martin")>-1)
		   $(this).addClass('pause');
		setTimeout("setPause();", 1000);
		return false;
	});
	
	$("a.close_popup").click(function(){
		window.close();
		return false;
	});
});

function setPause()
{
	if (state == 'paused')
	{
		  $("#video_menu a.selected").addClass("pause");
	}
}

function showVideo(vid)
{
	$("#blackout").show();
	$("#video_player").show();
	$("select").addClass("ie6");
	if (vid.indexOf("panorama=")>-1) so.addParam('flashvars', vid);
	else so.addVariable('file', vid);
	so.write('mediaspace');
}

function showVideo2(vid,room_name)
{
	$("#blackout").show();
	$("#video_player").show();
	$("select").addClass("ie6");
	if (vid.indexOf("panorama=")>-1) so.addParam('flashvars', vid);
	else so.addVariable('file', vid);
	so.write('mediaspace');

	room_name = room_name.replace("&", "&amp;");
	$('#video_menu a').each(function(){
		if ($(this).html() == room_name)
		{
			$(this).addClass("selected");
		}
		else if (document.URL.indexOf("_rooms")>-1 || document.URL.indexOf("pagename=rooms")>-1 || document.URL.indexOf("&")>-1) $(this).removeClass("selected");
	});
}

function hideVideo()
{
	$("#blackout").hide();
	var check_black = 0;
	$("a.expand").each(function(){
		if ($(this).hasClass("open"))
		{
			check_black = 1;
		}
	});
	if (check_black == 1)
	{
		$("#blackout").show();
		$("#blackout").addClass("lighter");
	}
	$("#video_player").hide();
	$("select").removeClass("ie6");
}
