function Auction(url, container)
{
	this.url = null;
	this.container = null;
	this.thickBoxWidth = 400;
	this.thickBoxHeight = 500;
	this.lastUrl = '';
	this.offsetTo = null;
	this.lastContainerUrl = null;
	
	var tthis = this;
	
	if (typeof url != 'undefined') {
		this.url = url;
	}
	if (typeof container != 'undefined') {
		this.container = $('#' + container);
	}
	
	this.container.parent().append('<div style="display: none" id="auctionThickboxInlineContainer"></div>');
	
	this.load = function(data)
	{
		tthis.container.html(data);
		tthis.hijackLinks(tthis.container);
		tthis.hijackForms(tthis.container);
		if (tthis.offsetTo !== null) {
			$('body').offset(tthis.offsetTo);
			tthis.offsetTo = null;
		} else {
			tthis.jumpToAnchor();
		}
		TB_init();
	};
	
	this.loadThickbox = function(data)
	{
		$('#auctionThickboxInlineContainer').html(data);
		if ($('#TB_ajaxContent').length > 0) {
			$('#TB_ajaxContent').html($('#auctionThickboxInlineContainer').html());
		} else {
			TB_show('', '#TB_inline?inlineId=auctionThickboxInlineContainer&height=' + tthis.thickBoxHeight 
				+ '&width=' + tthis.thickBoxWidth);
		}
		$('#auctionThickboxInlineContainer').html('');
		tthis.hijackForms($('#TB_ajaxContent'));
		$('#TB_closeWindowButton').unbind('click');
		$('#TB_closeWindowButton').click(function(e) {
			tthis.offsetTo = $('body').offset();
			e.preventDefault();
			tthis.callAjax(tthis.lastContainerUrl, '', 'GET', tthis.load);
			TB_remove();
			return false;
		});
		tthis.jumpToAnchor();
	};
	
	this.jumpToAnchor = function()
	{
		var url = this.lastUrl.split('#');
		if (url.length > 1) {
			window.location.hash = url[1];
			return true;
		}
		
		return false;
	};
	
	this.hijackLinks = function(container)
	{
		var links = container.find('a').not('.thickbox');
		if (links.length > 0) {
			$.each(links, function() {
				var href = $(this).attr('href');
				//if (typeof href != 'undefined' && href.indexOf(tthis.url) != -1) {
				if (typeof href != 'undefined') {
					if ($(this).hasClass('thickboxAuction')) {
						$(this).click(function(e) {
							tthis.callAjax(href, '', 'GET', tthis.loadThickbox);
							e.preventDefault();
						});
					} else {
						$(this).click(function(e) {
							tthis.lastContainerUrl = href;
							tthis.callAjax(href, '', 'GET', tthis.load);
							e.preventDefault();
						});
					}
				} 
			});
		}
	};
	
	this.hijackForms = function(container)
	{
		container.find('form').submit(function(e) {
			var action = $(this).attr('action');
			tthis.callAjax(action, $(this).serialize(), 'POST', tthis.loadThickbox);
			e.preventDefault();
		});
	};
	
	this.callAjax = function(url, query, type, worker, dataType, startLoader, throwErrors)
	{
		this.lastUrl = url;
		var urlPart = url.split('#');
		if (urlPart.length > 1) {
			url = urlPart[0];
		}

		if (typeof startLoader == 'undefined') {
			startLoader = false;
		}
		if (typeof type == 'undefined') {
			type = 'GET';
		}
		if (typeof throwErrors == 'undefined') {
			throwErrors = false;
		}
		
		var options = {
			'type' : type,
			'url' : url,
			'data' : query,
			'dataType' : dataType,
			'error' : function (XMLHttpRequest, textStatus, errorThrown) {
				try {
					//eval('var responseJSON = ' + XMLHttpRequest.responseText);
					//setStatusMessages(responseJSON);
				} catch(e) {
					if (throwErrors) {
						alert(translate.getTranslation('Error occured while processing your request.'));
					}
				} finally {
					if (startLoader) {
						loader.finish();
						unsetProcessMessage();
					}
				}
			},
			'success' : function (data, textStatus) {
				//setStatusMessages(data);
				if (worker) {
					worker(data);
				}
				if (startLoader) {
					loader.finish();
					unsetProcessMessage();
				}
			},
			'complete' : function (XMLHttpRequest, textStatus) {
			}
		};
		if (startLoader) {
			loader.start();
		}
		$.ajax(options);
	};
	
	// start
	this.callAjax(this.url, '', 'GET', this.load, 'html');
	this.lastContainerUrl = this.url;
}
