	$(function($) {

		var clickallowed = true;

		$('.albumBox').click(function() 
			{ 
				if (clickallowed)
				{
					href = $('#' + $(this).attr('id') + ' a').attr('href');
					window.location = href;
				}
			});

			$('html').click(function() { 
				$('.details').fadeOut(); 
				$('#lightboxfade').fadeOut('slow');
				});

			var showdetails = function(e)
			{
				parentid = $(this).parent().parent().attr('id');
				//console.log(parentid);
				showdetailswithid(parentid);
				e.stopPropagation();
			}

			var showdetailswithid = function(parentid)
			{				
				$('.details').css('display', 'none');
				$('#lightboxfade').fadeIn('fast');

				//$('#' + parentid).attr('top')

				var windowWidth = document.documentElement.clientWidth;
				var windowHeight = document.documentElement.clientHeight;
				var popupHeight = '200';
				var popupWidth = '450';

				//"top": windowHeight/2-popupHeight/2,

				$('#' + parentid + '_details').css({
					"top": 150,
					"left": (windowWidth-popupWidth)/2
				}).show();//.fadeIn();

				//only need force for IE6
				$('#' + parentid + ' .details').css({
					"height": windowHeight
				});

				$('html').bind('keypress', function (e) 
					{ 
						//alert(e.keyCode)
				      switch(e.keyCode) { 
				         // User pressed "esc"
				         case 27:
								$('.details').fadeOut(); 
								$('#lightboxfade').fadeOut('slow');
								break;
						}
					});	

					var anImage = new Image();
					anImage.src = homeURL + 'uploadedfiles/rect/' + parentid + '/80';

					anImage.onload = function() 
					{ 
						xpadding = (70 - anImage.width)/2;

						$('#' + parentid + ' img').each(function() 
						{ 
							$('.detailsthumb').css('margin-left', xpadding).css('margin-right', xpadding);
							$('#' + parentid + '_details img').each(function(i) { $(this).attr('src', anImage.src) }); 
						});
					};
			}

							$(".frame").hover(function(e)
					{	
						$(this).find(".detailsthumbnail").show().bind("click",showdetails);
					},
					function(e)
					{
						$(this).find(".detailsthumbnail").hide().unbind("click",showdetails);
					}
				);

					
		$("#treelink").toggle(function(e)
			{
				$("#tree").stop().slideDown();
			},
			function(e)
			{
				$("#tree").stop().slideUp();
			}
		);

});
