var Portfolio = Class.create ({
	
	initialize: function(container)
	{
		this.button = container;
		this.startItem = 8;
		this.maxCount = this.startItem * ($('pageCount').readAttribute('value'));
		
		this.displayButton();
	},
	
	displayButton: function()
	{	
		if(this.startItem <= this.maxCount)
		{
			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();

	    var URL = "/portfolio/data/?start=" + this.startItem;
	    
	    new Ajax.Request(URL, { method:'get', onSuccess: function(response) { $('portfolioListing').insert(response.responseText); } });
		
		this.startItem = this.startItem + 8;
			
		if(this.startItem >= this.maxCount)
		{	
			if (this.button.hasClassName('displayBlock')) 
			{
				this.button.removeClassName('displayBlock');
				this.button.addClassName('displayNone');
			}
		}
	}
});


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