/*
 * jQuery UI Theme 1.0
 *
 * 2009-04-13
 *
 */
 jQuery.fn.uitheme_highlight = function( options ) {
	var settings = jQuery.extend( { icon: "info" }, options );
	if (settings.icon != false) {
		this.prepend( "<span class=\"ui-icon ui-icon-" + settings.icon + "\" style=\"float: left; margin-right: .3em\"></span>" );
	}
	this.wrap( "<div class=\"ui-widget\" style=\"margin-top: 10px; margin-bottom: 10px;\"><div class=\"ui-state-highlight ui-corner-all\" style=\"padding: 0 .7em;\"></div></div>" );
	
	return this;
};

jQuery.fn.uitheme_alert = function( options ) {
	var settings = jQuery.extend( { icon: "alert" }, options );
	this.css( "margin", "1em 0" );
	if (settings.icon != false) {
		this.prepend( "<span class=\"ui-icon ui-icon-" + settings.icon + "\" style=\"float: left; margin-right: .3em\"></span>" );
	}
	this.wrap( "<div class=\"ui-widget\" style=\"margin-top: 10px; margin-bottom: 10px;\"><div class=\"ui-state-error ui-corner-all\" style=\"padding: 0 .7em;\"></div></div>" );
	
	return this;
};

jQuery.fn.uitheme_button = function( options ) {
	var settings = jQuery.extend( { icon: false, width: false }, options );
	
	if (settings.icon != false)
		this.prepend( "<span class=\"ui-icon ui-icon-" + settings.icon + "\"></span>" );
	
	this.addClass( "ui-state-default ui-corner-all" ).hover( 
		function () { $(this).addClass( "ui-state-hover" ); }, 
		function () { $(this).removeClass( "ui-state-hover" ); } 
	).css( "cursor", "pointer" );
	
	if (settings.width != false)
		this.css( "width", settings.width );
	
	return this;
};

jQuery.fn.uitheme_form = function( options ) {
	var settings = jQuery.extend( { title: "", width: false, position: false, visible: true, buttons: {} }, options );
	var insideWidget = (this.closest(".ui-widget").size() > 0);
	var hasButtons = false;
	this.wrap( "<div class=\"ui-dialog" + (insideWidget ? "" : " ui-widget") + " ui-widget-content ui-corner-all\" style=\"" +
		(settings.width != false ? "width: " + settings.width + ";" : "") +
		(settings.position != false ? "position: absolute; top:" + settings.position[1] + "px; left: " + settings.position[0] + "px;" : "") +
		(settings.visible ? "" : "display: none;") +
		"\"></div>" ).addClass( "ui-dialog-content ui-widget-content" ).each( function () {
		var jthis = $(this);
		var title = settings.title || jthis.attr( "title" ) || "&nbsp;";
		jthis.before( "<div class=\"ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix\"><span class=\"ui-dialog-title\">" + title + "</span></div>" );
	} );
	
	((typeof settings.buttons == 'object') && (settings.buttons !== null) && $.each( settings.buttons, function () { return !(hasButtons = true); } ));
	if (hasButtons) {
		var uiButtonPane = $("<div></div>").addClass( "ui-dialog-buttonpane ui-widget-content ui-helper-clearfix" );
		$.each( settings.buttons, function (name, fn) {
			$("<button type=\"button\"></button>").addClass( "ui-state-default ui-corner-all" )
				.text( name )
				.click( function () { fn.apply( arguments ); } )
				.hover( function () { $(this).addClass( "ui-state-hover" ); }, function () { $(this).removeClass( "ui-state-hover" ); } )
				.appendTo( uiButtonPane );
		} );
		this.after( uiButtonPane );
	}
	
	return this;
}
