var deleteButton = Class.create();

deleteButton.prototype = 
{
	initialize: function(e) 
	{
		var p = e.rel.split('_');
		this.e = e;
		this.what = p[0];
		this.id = p[1];
		this.title = p[2];
		this.updateDiv = $('thumbnailContainer_' + p[1]);
		this.container = $('thumbnailContainer_' + p[1]);
		this.setEvents(e);
	},
	
	doRequest: function()
	{
		switch(this.what)
		{
			case 'deleteImage':
				var s = 'are you sure you want to delete\n' + this.title +'?';
				if(confirm(s))
				{
					var option = 
					{
						method : 
						'post',
						parameters :
						'?id=' + this.id,
						onComplete: 
						function(t)
						{
							activeButton.afterRequest(t);
						}
					};
					new Ajax.Request('ajax/delete.php', option);
				}
				break;
			default:
				error();
				writeResponse('ooops... foutje. probeer het nog een keer');
		}
	},
	
	afterRequest: function(t)
	{
		//alert(t.responseText);
		switch(t.responseText)
		{
			case 'imageDeleted':
				writeResponse('de afbeelding is verwijderd');
				success();
				this.updateAfterRequest();
				break;
			default:
				error();
				writeResponse('ooops... foutje. probeer het nog een keer');
		}
	},
	
	updateAfterRequest: function()
	{
		updateDiv = this.updateDiv;
		var option = 
		{
			startcolor: '#ff6666',
			endcolor: '#eee',
			duration: 1,
			afterFinish: function (){ Element.remove(updateDiv);}
		};
		new Effect.Highlight(this.updateDiv, option);
		
		refreshContent(new Array(4,5,6,'thumbHeader'));
	},
	
	setEvents: function(e)
	{
		Event.observe(e, 'mouseover', this.doMouseover.bindAsEventListener(this), false);
		Event.observe(e, 'mouseout', this.doMouseout.bindAsEventListener(this), false);
		Event.observe(e, 'click', this.doClick.bindAsEventListener(this), false);
		
		e.onclick = function()
		{
			return false;
		};	
		
		e.onmouseover = function()
		{
			return false;
		};
		
		e.onmouseout = function()
		{
			return false;
		};
	},
	
	doClick: function()
	{
		activeButton = this;
		this.doRequest();
		this.e.blur();
	},
	
	doMouseover: function()
	{
		this.container.style.backgroundColor = '#ff6666';
		this.element.style.cursor = 'pointer';
	},
	
	doMouseout: function()
	{
		this.container.style.backgroundColor = '#eeeeee';
	}
	
}
	
function initDeleteButton()
{
	buttons = document.getElementsByClassName('deleteButton');
	for(i = 0; i < buttons.length; i++)
	{
		button = new deleteButton(buttons[i]);
	}	
}


