jQuery.fn.alignBox = function(direction)
{
	switch(direction)
	{
		case 'vertical':

			this.css('top', (this.parent().height() - this.innerHeight()) / 2 + 'px');
		break;

		case 'left':

			this.css('left', '0px');
		break;

		case 'right':

			this.css('left', this.parent().innerWidth() - this.outerWidth() + 'px');
		break;

		default:

			this.css('left', (this.parent().width() - this.innerWidth()) / 2 + 'px');
		break;
	}

    return this;
}

jQuery.fn.delayDisable = function()
{
	this.attr('contentEditable', 'false');
	this.parent().css('border', '1px dashed #ccc');
	this.parent().draggable('enable');

	if(RESET)
	{
		SELECTED_OBJECT = null;
		
		setAllSettings();
	}

	return this;
}

jQuery.fn.equals = function(compareTo)
{
	if(!compareTo || !compareTo.length || this.length != compareTo.length)
		return false;

	for(var i = 0; i < this.length; i++)
	{
		if(this[i] !== compareTo[i])
			return false;
	}

	return true;
}

jQuery.fn.save = function(page)
{
	var child = jQuery('.draggable', $(this));
	var pos = $(this).position();
	var left = pos.left;
	var top = pos.top;
	var string = '';
	var borderWidth = parseInt(child.css('border-width'));
	var type;

	if(child.hasClass('image'))
	{
		var img = jQuery('img', child);
	
		type = 'image';
	}
	else if(child.hasClass('rectangle'))
		type = 'rectangle';
		
	else
		type = 'textbox';		

	string += 'type[]=' + type;
	string += '&page[]=' + page;
	string += '&left[]=' + left;
	string += '&top[]=' + top;
	string += '&width[]=' + ($(this).outerWidth() - borderWidth);
	string += '&height[]=' + ($(this).outerHeight() - borderWidth);
	string += '&opacity[]=' + child.css('opacity');
	string += '&background[]=' + child.css('background-color');
	string += '&border[]=' + child.css('border-color');
	string += '&borderWidth[]=' + borderWidth;
	//string += '&borderStyle[]=' + child.css('border-style');

	var value = (type == 'image' ? escape(img.attr('src')) : '');

	string += '&image[]=' + value;
	string += '&text[]=' + escape(child.html());
	string += '&italic[]=' + child.css('font-style');
	string += '&bold[]=' + child.css('font-weight');
	string += '&underline[]=' + child.css('text-decoration');
	string += '&size[]=' + child.css('font-size');
	string += '&color[]=' + child.css('color');
	string += '&family[]=' + child.css('font-family');
	string += '&align[]=' + child.css('text-align');
	
	return string;
}