﻿// JScript File

var prevItemID, nextItemID, currentItemID, webcastID, AudioURL, PostTestURL;

function GetScreen(itemID) {
	$("#a"+ webcastID).unbind("click");
	$("#a"+ webcastID).html("Resume");
	$("#player_wrapper").empty();
	var params = {};
	params["SN"] = "Website.Slots.GetScreen";
	params["TN"] = ":templates/GetScreen.xslt";
	params["GetScreen.ItemID"] = itemID;
	$.post("/Admin/SlotExecutor.aspx",
		params,
		function(data){
			currentItemID = itemID;
			RefreshButtons(data);
			if ($(data).find("#data").html() != null)   $('#ScreenData').html($(data).find("#data"));
			else    $('#ScreenData').html(data);

			PostTestURL = $(data).find("#PostTestURL").html().replace("&amp;","&");			

			$('#dark').css('opacity','0.8').height( $(document).height() ).fadeIn();
			$('#ScreenContainer').dialog("open");
			$(".dialog_content_container .table").each(function() {
				var divH = $(this).find(".table-content").height() + 28;
				$(this).css({"height":divH + "px"});
				$(this).find(".table-background").css({"height":divH + "px"});
			});
			$(".dialog_content_container .text, .table-content th, .table-content td").textShadow();
			$(".table-content th .jQueryTextShadow, .table-content td .jQueryTextShadow").each(function() {
				$(this).css({"top":$(this).parent().height()/2 - $(this).height()/2 + 5 + "px","margin-right":"-5px","width":$(this).parent().width() + 2 + "px"});
			});
			if ($.browser.msie && $.browser.version.slice(0,1) == "8") {
				$(".table-content td, .table-content th").boxShadow(4, 4, 10, "#333" );
			}
			$(".dialog_content_container").scrollTop(0);
			
		}
	);
}

function RefreshScreenNavigation(testID){
	$(".buttons_wrapper").css("display","block");
    var params = {};
	params["SN"] = "Website.Slots.GetScreen";
	params["TN"] = ":templates/GetScreen.xslt";
	params["GetScreen.TestID"] = testID;
	$.post("~/Admin/SlotExecutor.aspx",
		params,
		function(data){
			RefreshButtons(data);
		}
	);
}

function RefreshButtons(data) {
	prevItemID = parseInt($(data).find("#prevItemID").html());
	if (prevItemID == 0) $("#PreviosScreenLink").css("visibility","hidden");
	else $("#PreviosScreenLink").css("visibility","visible");
	nextItemID = parseInt($(data).find("#nextItemID").html());
	if (nextItemID == 0) $("#NextScreenLink").css("visibility","hidden");
	else $("#NextScreenLink").css("visibility","visible");
	webcastID = parseInt($(data).find("#WebcastID").html());
	$("#a"+ webcastID).click(function() {
		GetScreen(currentItemID);
	});
	PostTestURL = $(data).find("#PostTestURL").html().replace("&amp;","&");
	if(PostTestURL != null && PostTestURL.length > 0) {
		$("#NextScreenLink").attr("href", "#");
		$("#NextScreenLink").css("visibility","visible");
		$("#NextScreenLink").click(function() {
			$(".buttons_wrapper").css("display","none");
			$('#ScreenData').html("<p><br/><br/>Loading Post-Test</p>");
			location.href=PostTestURL;			
		});
	}
	else{
		$("#NextScreenLink").attr("href", "javascript:nextScreen();");
		$("#NextScreenLink").unbind("click");
	}
}

function previosScreen(){
	GetScreen(prevItemID);
}

function nextScreen(){
	GetScreen(nextItemID);
}


function closeDialog() {
	$('#ScreenContainer').dialog("close");
}




$(document).ready(function(){
	$(window).resize(function(){
		if($('body').find('.ui-dialog').css('display') == 'block'){
			$('body').find('.ui-dialog').position({
				my: "center",
				at: "center",
				of: window
			});
			if( parseFloat($('body').find('.ui-dialog').css('left')) < 0 ){
				$('body').find('.ui-dialog').css('left',0);
			}
			if( parseFloat($('body').find('.ui-dialog').css('top')) < 0 ){
				$('body').find('.ui-dialog').css('top',0);
			}
			$('#dark').height( $(document).height() );
		}
	});
});

