var _photoProfileWidth = 640;
var _photoProfileHeight = 480;
var _oPhoto = null;

displayPhoto = function () {
	var oPhoto = _oPhoto;
	var photoProfile = $("#photoProfile");
	var photoFootnote = "This photo ";
	var photoProfileWidth = oPhoto.INTWIDTH + 200;
	var photoProfileHeight = oPhoto.INTHEIGHT + 10;
	var photoProfileImg = $("#photoProfile img");

	if ( photoProfile.css("display") != "none" )
	{
		//if ($.browser.mozilla || $.browser.msie)
		//{
			photoProfile.removeShadow();
		//}
	
		$("#photoFootnote").hide();
		if (oPhoto.ASTHEMES.length > 0)
		{
			photoFootnote += 'of '
						   + '<a href="/browse/?category=theme&value='
						   + oPhoto.ASTHEMES[0].INTID
						   + '">' + oPhoto.ASTHEMES[0].STRNAME
						   + '</a>'
						   ;
		}
		if (oPhoto.STRCITY.length > 0)
		{
			photoFootnote += ' in '
						   + '<a href="/browse/?category=location&value='
						   + oPhoto.INTCITYID
						   + '">' + oPhoto.STRCITY
						   + '</a> '
						   ;
		}
		photoFootnote += "was taken ";
		if (oPhoto.STRYEARTAKEN)
		{
			photoFootnote += 'in '
						   + '<a href="/browse/?category=year&value='
						   + oPhoto.INTYEARTAKENID
						   + '">' + oPhoto.STRYEARTAKEN
						   + '</a> '
						   ;
		}
		photoFootnote += 'by <a href="/user/?id=' + oPhoto.INTUSERID + '">'
					   + oPhoto.STROWNERFIRSTNAME + " " + oPhoto.STROWNERLASTNAME
					   + '</a>.'
					   ;
		$("#photoFootnote").css("width", oPhoto.INTWIDTH+"px");
		$("#photoFootnote").html(photoFootnote);
		$("#photoFootnote").show();
	
		$("#photoTitle").html(oPhoto.STRTITLE);
		$("#photoDescription").html(oPhoto.STRDESCRIPTION);
		$("#photoInfo").show();

		if ( $("#photoInfo").height() > oPhoto.INTHEIGHT )
		{
			photoProfileHeight = $("#photoInfo").height() + 10;
		}

		$("div.blockMsg").animate(
			{
				left: (($(window).width()+$(window).scrollLeft()-photoProfileWidth)/2) + "px",
				top: ($(window).scrollTop()+20) + "px"
			}
		);
		photoProfile.animate(
			{
				width: photoProfileWidth+"px",
				height: (photoProfileHeight+$("#photoFootnote").height())+"px"
			}
		);
	
		photoProfileImg.hide();
		photoProfileImg.attr("src", "http://"+oPhoto.STRSERVERNAME+"/img/upload"+oPhoto.STRFOLDERPATH+"/"+oPhoto.STRFILENAME);
		photoProfileImg.attr("height", oPhoto.INTHEIGHT);
		photoProfileImg.attr("width", oPhoto.INTWIDTH);
		photoProfileImg.css("margin", "0 0 0 20px");
		photoProfileImg.show();
	
	/*	
		if ($.browser.mozilla || $.browser.msie)
		{
			photoProfile.dropShadow();
		}
	*/
	}
};

hidePhotoProfile = function () {
	var photoProfile = $("#photoProfile");
	var photoProfileWidth = _photoProfileWidth;
	var photoProfileHeight = _photoProfileHeight;
	var photoProfileImg = $("#photoProfile img");

/*
	if ($.browser.mozilla || $.browser.msie)
	{
		photoProfile.removeShadow();
	}
*/
	photoProfile.removeShadow();
	photoProfile.hide();

	$.unblockUI();

	photoProfile.css("width", photoProfileWidth+"px");
	photoProfile.css("height", photoProfileHeight+"px");

	photoProfileImg.attr("src", "/img/loading.gif");
	photoProfileImg.attr("height", 100);
	photoProfileImg.attr("width", 100);
	photoProfileImg.css("margin", "190px 0 0 270px");

	$("#photoFootnote").hide();
	$("#photoFootnote").css("width", photoProfileWidth+"px");
	$("#photoFootnote").html("");

	$("#photoInfo").hide();
	$("#photoTitle").html("");
	$("#photoDescription").html("");
};

$(document).ready(function () {

	$("img.photo").click(function () {
		var imgID = $(this).attr("id");
		var photoID = imgID.substring(5, imgID.length);
		var photoProfile = $("#photoProfile");
		var photoProfileWidth = _photoProfileWidth;
		var photoProfileHeight = _photoProfileHeight;

		photoProfile.css("width", photoProfileWidth+"px");
		photoProfile.css("height", photoProfileHeight+"px");

		$.blockUI({
			message: photoProfile,
			css: {
				border: "none",
				cursor: "default",
				left: (($(window).width()+$(window).scrollLeft()-photoProfile.width())/2) + "px",
				top: ($(window).scrollTop()+20) + "px",
				textAlign: "left"
			},
			overlayCSS: {backgroundColor:"#666"},
			centerY: false
		});
		$("div.blockUI").css("cursor", "default");
		$("div.blockMsg").css("position", "absolute");

		//if ($.browser.mozilla || $.browser.msie)
		//{
			photoProfile.dropShadow();
		//}

		$.getJSON( "/_ui/RemoteService.cfc?"+Math.random()
				 , {method:"getPhoto", intID:photoID}
				 , function (oPhoto) {
					 _oPhoto = oPhoto;
					 setTimeout(displayPhoto, 1000);
				 });
	});

	$("#photoProfileClose").click(function () { hidePhotoProfile(); });
	$("#photoFootnote").click(function () { hidePhotoProfile(); });

	$("#photoProfileClose").hover(
		function () {
			$(this).addClass("hover");
		},
		function () {
			$(this).removeClass("hover");
		}
	);

});