$(document).ready(function() {
	$("#dialog").dialog({ modal: true , 
						  resizable: false ,
						  });
	$("#dialog").dialog('close');
	$(".gallery li").click(function(){
		showGallery($(this).find("a").attr("title")); return false;
	});

	 $(".gallery li").hover(
		function(){
		  $(this).css("border", "1px solid #465a63").css("cursor", "pointer").css("background", "#a3c308")
		  $(this).find("img").css("border", "1px solid #465a63")
		  $(this).find("a").css("color", "white")

		},
		function(){
	   
		  $(this).css("border", "1px solid #a3c308").css("text-decoration", "none").css("cursor", "none").css("background", "#a3c308").css("background", "none")
		  $(this).find("a").css("color", "#465a63")
		  $(this).find("img").css("border", "1px solid #a3c308")

		});
});

function showGallery(document) {

//$.getJSON('/content/ajax/get_document/' , { "document": document } , function(data, textStatus, jqXHR){
//	alert('here');
//	alert('data');
//	documentPopupShow(data);
//});

$.ajax({
  	url: '/content/ajax/get_document/?document=' + document,
  	dataType: 'json',
  	data: {"document": document},
  	success: function(data, textStatus, jqXHR){
		documentPopupShow(data);
	}

});

return false;

};

function documentPopupWait(){

}

function documentPopupError(XMLHttpRequest, textStatus, errorThrown){

alert (errorThrown + ': ' + textStatus);

}

function documentPopupShow(response){

document.getElementById('ui-dialog-title-dialog').innerHTML = response.document[0].title;

var dialogcontent = '<img src="' + response.document[0].large_image + '" alt="" />';
if(response.document[0].short_description){
	dialogcontent += '<p>' + response.document[0].short_description + '</p>';
}
$("#dialog").html(dialogcontent);

var dialogwidth = 300;
dialogwidth = parseInt(response.document[0].large_image_width) + 20;

$("#dialog").dialog('option', 'width', dialogwidth);
$("#dialog").dialog('option', 'show', 'slide');
$("#dialog").dialog('open');

return true;

}

