function r_findImage()
{
	this.ajaxURL = "/ajax/r_find_image.php";
	this.container = null;
	this.isOpen = false;

	this.open = function(sid)
	{
		if (!this.isOpen)
		{
			this.isOpen = true;
			this.container = $(document.createElement("div"));
			
			this.container.addClass("popup");
			this.container.css({
				width: "500px",
				height: "300px",
				"margin-left": "-250px",
				"margin-top": "-150px",
				display: "none"
			});

			var title = $(document.createElement("div"));
			this.container.append(title);
			title.addClass("title");
			title.html("" +
				"<div style='float: left; width: 70%;'>" +
					"Find an Image" +
				"</div>" +
				"<div style='float: left; width: 30%; text-align: right;'>" +
					"<img class='png' src='http://zacisa.info/images/icons/cancel.png' onclick='r_findImage.close();' />" +
				"</div>" +
				"<div class='clear'></div>");
			
			var body = $(document.createElement("div"));
			this.container.append(body);
			body.addClass("body");
			body.css("padding", "0px");
			
			$("body").append(this.container);
			this.container.show(400);
			this.findImages(0, 1);
		}
	};
	
	this.close = function()
	{
		if (this.isOpen)
		{
			this.container.hide(400);
			
			setTimeout(function()
			{
				r_findImage.container.remove();
				r_findImage.isOpen = false;
			}, 401);
		}
	};
	
	this.findImages = function(album_sid, page)
	{
		$.post(this.ajaxURL,
			{ album_sid: album_sid, page: page },
			function(data)
			{
				r_findImage.container.children(".body").html(data);
			});
	};
	
	this.selectImage = function(hash)
	{
		$("#hash").val(hash);
		this.close();
	};
};
var r_findImage = new r_findImage();