$(document).ready(function(){
	
})

function createDialog(){
	$("#movie_preview").dialog({
		autoOpen: false, 
		modal: true,
		width: "736px",
		height: "auto",
		resizable : true,
		close: function(ev, ui) { 
				//$("#myFlashDiv").remove();
				$(this).dialog('destroy'); 
			},
		buttons: {
			'Close' : function() {
				//$("#myFlashDiv").remove();
				$(this).dialog('destroy');  
			}
		}   
	})
}


function showPreview(keyword, trObj){
	
	var caller_url = document.location.href;
	var rowClicked = trObj != null ? trObj.rowIndex : 0;
	
	createDialog();
	$.ajax({
		cache: false,
		async: false, 
		type: "POST",
		url: "/demo.php",
		data: 	{swfFile:keyword, caller_url:caller_url, row_clicked:rowClicked},
		success: function(html){
				$("#movie_preview").html(html);
				$("#movie_preview").dialog('open');
		}
		
		
	});	
}

function showDemoLauncher(keyword) {
	$("#demo-preview").html("<div style='padding:5px;'>loading...</div>");
	
	var caller_url = document.location.href;
	$.ajax({
		cache: false,
		async: false, 
		type: "POST",
		url: "/demo.php",
		data: 	{swfFile:keyword, caller_url:caller_url},
		success: function(html){
			$("#demo-preview").html(html);
		}
	});
}


function showImagePreview(img){	
	$("#image_preview").html("<img src='"+$(img).attr("src")+"' border='0' height='600px'/>");
	$("#image_preview").css({marginLeft:$("#image_preview").width() / -2, marginTop:$("#image_preview").height() / -2}).show();
}

function showImagePreview_noResize(img){	
	$("#image_preview").html("<img src='"+$(img).attr("src")+"' border='0'/>");
	$("#image_preview").css({marginLeft:$("#image_preview").width() / -2, marginTop:$("#image_preview").height() / -2}).show();
}

//this means that the user came from the landing page so trigger the click event
function triggerTableRowElement_onClick(tableId, rowIndex){
	document.getElementById(tableId).rows.item(rowIndex).onclick();
}


