function Popup(object)
{
	this.object = (object != null && object != undefined) ? (typeof($(object).get(0) == "object")) ? $(object) : null : null;
	this.object_id = null;
	this.popup = $("#popup");
	this.load_icon = "<img src='/i/icons/done.gif' border='0' />";

	this.ShowPopup = function()
	{
		var page = new Page();
		page.SetPopupPosition();
		
		this.popup.css("display", "block");
		this.LoadInfo();		
	}
	
	this.getObject = function()
	{
		if (this.object != null && (typeof(this.object) == "object")) 
		{
			if (typeof(this.object.get(0)) == "object") return this.object;
		}

		this.object = $("a[rel="+this.getObjectId()+"]");
		if (typeof(this.object.get(0)) == "object" && this.object != null) return this.object;
		
		return false;
	}
	
	this.setObjectId = function(object_id)
	{
		this.object_id = object_id;
	}	
	
	this.getObjectId = function()
	{
		if (this.object_id != null) return this.object_id;
		if (this.object != null && (typeof(this.object) == "object")) 
		{
			if (typeof(this.object.get(0)) == "object") 
			{
				this.object_id = $(this.object).attr("rel");
				return this.object_id;
			}
		}
		
		return false;		
	}
	
	this.installRightArrow = function()
	{
		$.ajax({
			type: "GET",
			url: "/ajax.user.php?action=rightbtn&id=" + this.getObjectId(),
			cache: false,
			success: function(data){ 
				if (data == "true") $("#popup_right").css("visibility", "visible");
				else if (data == "false") $("#popup_right").css("visibility", "hidden");
			},
			error: function() { }
		});
	}
	
	this.installLeftArrow = function()
	{
		$.ajax({
			type: "GET",
			url: "/ajax.user.php?action=leftbtn&id=" + this.getObjectId(),
			cache: false,
			success: function(data){ 
				if (data == "true") $("#popup_left").css("visibility", "visible");
				else if (data == "false") $("#popup_left").css("visibility", "hidden");
			},
			error: function() { }
		});
	}
	
	this.LoadName = function()
	{
		$.ajax({
			type: "GET",
			url: "/ajax.user.php?action=getname&id=" + this.getObjectId(),
			cache: false,
			success: function(data){ $("#popup_name").html(data); },
			error: function() { }
		});
	}
	
	this.LoadContent = function()
	{
		$.ajax({
			type: "GET",
			url: "/ajax.user.php?action=getcontent&id=" + this.getObjectId(),
			cache: false,
			success: function(data){ $("#popup_content").html(data); },
			error: function() { }
		});
	}
	
	this.LoadMainImage = function()
	{
		$.ajax({
			type: "GET",
			url: "/ajax.user.php?action=getmainimage&id=" + this.getObjectId(),
			cache: false,
			success: function(data){ 
				$("#popup_main_image").html(data); 				
				$('a[rel=lightbox]').each(function(){
			 		$(this).lightbox();
			  	});	
			},
			error: function() { }
		});	
	}
	
	this.LoadAdditionalImage = function()
	{
		$.ajax({
			type: "GET",
			url: "/ajax.user.php?action=getimage1&id=" + this.getObjectId(),
			cache: false,
			success: function(data){ 
				$("#popup_image_1").html(data); 
				$('a[rel=lightbox]').each(function(){
			 		$(this).lightbox();
			  	});	
			},
			error: function() { }
		});
				
		$.ajax({
			type: "GET",
			url: "/ajax.user.php?action=getimage2&id=" + this.getObjectId(),
			cache: false,
			success: function(data){
				$("#popup_image_2").html(data); 
				$('a[rel=lightbox]').each(function(){
			 		$(this).lightbox();
			  	});		
			},
			error: function() { }
		});
				
		$.ajax({
			type: "GET",
			url: "/ajax.user.php?action=getimage3&id=" + this.getObjectId(),
			cache: false,
			success: function(data){ 
				$("#popup_image_3").html(data); 
				$('a[rel=lightbox]').each(function(){
			 		$(this).lightbox();
			  	});	
			},
			error: function() { }
		});
	}
	
	this.windowScrollAnimate = function()
	{
		var scroll_to_left = $(this.getObject()).position().left + 253;	
		if ($.browser.mozilla) scroll_to_left = scroll_to_left - 253;
		if ($.browser.opera) scroll_to_left = scroll_to_left - 253;
		scroll_to_left = scroll_to_left - 128 - ($(window).width() / 2);
		var difference = scroll_to_left - $.leftScroll();
				
		if (scroll_to_left > $.leftScroll())
		{
			var t = new p(difference, -0.0001, 3, difference / 35);		
			var y = $.leftScroll();
			
			t.go(10, function(j){
		   		y += j;
				window.scrollTo(y, 0);
			});
		}
		else if (scroll_to_left < $.leftScroll())
		{
			difference = difference * -1;
			var t = new p(difference, -0.0001, 3, difference / 35);		
			var y = $.leftScroll();
			
			t.go(10, function(j){
		   		y -= j;
				window.scrollTo(y, 0);
			});
		}		
	}
	
	this.Loading = function()
	{
		$("#popup_name").html(this.load_icon);
		$("#popup_content").html(this.load_icon);
		$("#popup_main_image").html(this.load_icon);
		$("#popup_image_1").html(this.load_icon);
		$("#popup_image_2").html(this.load_icon);
		$("#popup_image_3").html(this.load_icon);
	}
	
	this.LoadLeft = function(){
		var popup = this;
		var object_id = $("#popup_id").val();
		
		this.Loading();
		
		$.ajax({
			type: "GET",
			url: "/ajax.user.php?action=getleftid&id=" + object_id,
			cache: false,
			success: function(data){
			
				popup.setObjectId(data);
				popup.ShowPopup();
				
			},
			error: function(){
			}
		});
	}
	
	this.LoadRight = function(){
		var popup = this;
		var object_id = $("#popup_id").val();
		
		this.Loading();
		
		$.ajax({
			type: "GET",
			url: "/ajax.user.php?action=getrightid&id=" + object_id,
			cache: false,
			success: function(data){
			
				popup.setObjectId(data);
				popup.ShowPopup();
				
			},
			error: function(){
			}
		});
	}
	
	this.LoadInfo = function()
	{
		this.windowScrollAnimate();		
		this.Loading();				
			
		$("#popup_id").val(this.getObjectId());
		
		this.installRightArrow();
		this.installLeftArrow();
		this.LoadName();
		this.LoadContent();
		this.LoadMainImage();
		this.LoadAdditionalImage();		
	}
}

