var Work = Class.create ({
	
	initialize: function(container)
	{
		this.button = container;
		this.startItem = 20;
		this.maxCount = $('pageCount').readAttribute('value');
		
		this.loaded = 1;
		
		this.displayButton();
	},
	
	displayButton: function()
	{	
		if (this.button.hasClassName('displayNone')) 
		{
			this.button.removeClassName('displayNone');
			this.button.addClassName('displayBlock');
		}
		
		this.button.observe("click", this.buttonClicked.bind(this));
	},
	
	buttonClicked: function(event)
	{	
		if(!event)
		{
			return false;
		}		
		event.stop();
		
		this.loaded++;
		
		if(window.location.search != "")
		{
			var URL = "/work/data/" + window.location.search + "&start=" + this.startItem;
		}
		else
		{
			var URL = "/work/data/?start=" + this.startItem;
		}
	    
	    new Ajax.Updater('workListing', URL, {
	    	method:'get',
	    	insertion: 'bottom',
	    });
	    
		this.startItem = this.startItem + 20;
			
		if(this.loaded >= this.maxCount)
		{	
			if (this.button.hasClassName('displayBlock')) 
			{
				this.button.removeClassName('displayBlock');
				this.button.addClassName('displayNone');
			}
		}
	}
});


document.observe('dom:loaded', function()
{	
	if ($("more"))
	{
		new Work($('more'));
	}
});
