function gPieChartRender(values, el, options)
{
	// Make sure we have everything we need (values and a jQuery selected element (of length 1))
	if(values == undefined || typeof values !== "object" || typeof el !== "object" || el.length > 1)
	{
		return false;
	}
	
	// Clear out the contents of el
	el.html('');
	
	// Setup the variables we need
	var chart = null,
		data = new google.visualization.DataTable(),
		defaults = {
			title : '',
			titleTextStyle : {
				fontSize : 10
			},
			width : 200,
			height : 275,
			chartArea : {
				top : 40,
				width : 100,
				height : 100
			},
			legend : {
				position : 'none'
			},
			tooltip : {
				text : 'percentage'
			},
			pieSliceText : 'label',
		};
	
	// Setup options for chart (allow passed in values)
	if(options == undefined)
	{
		options = defaults
	} else
	{
		options = $.extend(defaults,options);
	}
	
	data.addColumn('string', 'Type');
	data.addColumn('number', 'Votes');
	
	$.each(values, function(index,value)
	{
		data.addRow([index,parseFloat(value)]);
	});
	
	// Create the google visualization and associate it with the provided element
	// Convert the element from jQuery selector to DOM node
	chart = new google.visualization.PieChart(el.get(0));
	// Draw the chart
	chart.draw(data,options);
	
	// Let everyone know it succeeded
	return true;
	
}


// Controls the tools dropdown
$('#clickme').click(function() {
  $('#book').animate({
    opacity: 0.25,
    left: '+=50',
    height: 'toggle'
  }, 5000, function() {
    // Animation complete.
  });
});

//Dialog boxes

$(function(){
	// Dialog			
	$('#dialog-add_groups').dialog({
		modal:true,
		autoOpen: false,
		width: 500,
		buttons: {
			"I’m Done Here": function() { 
				$(this).dialog("close"); 
			} 
			
		}
	});
	$('#dialog-community').dialog({
		modal:true,
		autoOpen: false,
		width: 500,
		buttons: {
			"Join": function() { 
				$(this).dialog("close"); 
			} 
			
		}
	});
	$('#dialog-create').dialog({
		modal:true,
		autoOpen: false,
		width: 500,
		buttons: {
			"Create Group": function() { 
				$(this).dialog("close"); 
			} 
			
		}
	});

	
	// Dialog Link
	$('#dialog_link_add_groups').click(function(){
		$('#dialog-add_groups').dialog('open');
		return false;
	});
	$('#dialog_link_community').click(function(){
		$('#dialog-community').dialog('open');
		return false;
	});
	$('#dialog_link_create').click(function(){
		$('#dialog-create').dialog('open');
		return false;
	});


(function( $ ) {
		$.widget( "ui.combobox", {
			_create: function() {
				var self = this,
					select = this.element.hide(),
					selected = select.children( ":selected" ),
					value = selected.val() ? selected.text() : "";
				var input = this.input = $( "<input>" )
					.insertAfter( select )
					.val( value )
					.autocomplete({
						delay: 0,
						minLength: 0,
						source: function( request, response ) {
							var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
							response( select.children( "option" ).map(function() {
								var text = $( this ).text();
								if ( this.value && ( !request.term || matcher.test(text) ) )
									return {
										label: text.replace(
											new RegExp(
												"(?![^&;]+;)(?!<[^<>]*)(" +
												$.ui.autocomplete.escapeRegex(request.term) +
												")(?![^<>]*>)(?![^&;]+;)", "gi"
											), "<strong>$1</strong>" ),
										value: text,
										option: this
									};
							}) );
						},
						select: function( event, ui ) {
							ui.item.option.selected = true;
							self._trigger( "selected", event, {
								item: ui.item.option
							});
						},
						change: function( event, ui ) {
							if ( !ui.item ) {
								var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ),
									valid = false;
								select.children( "option" ).each(function() {
									if ( $( this ).text().match( matcher ) ) {
										this.selected = valid = true;
										return false;
									}
								});
								if ( !valid ) {
									// remove invalid value, as it didn't match anything
									$( this ).val( "" );
									select.val( "" );
									input.data( "autocomplete" ).term = "";
									return false;
								}
							}
						}
					})
					.addClass( "ui-widget ui-widget-content ui-corner-left" );

				input.data( "autocomplete" )._renderItem = function( ul, item ) {
					return $( "<li></li>" )
						.data( "item.autocomplete", item )
						.append( "<a>" + item.label + "</a>" )
						.appendTo( ul );
				};

				this.button = $( "<button type='button'>&nbsp;</button>" )
					.attr( "tabIndex", -1 )
					.attr( "title", "Show All Items" )
					.insertAfter( input )
					.button({
						icons: {
							primary: "ui-icon-triangle-1-s"
						},
						text: false
					})
					.removeClass( "ui-corner-all" )
					.addClass( "ui-corner-right ui-button-icon" )
					.click(function() {
						// close if already visible
						if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
							input.autocomplete( "close" );
							return;
						}

						// work around a bug (likely same cause as #5265)
						$( this ).blur();

						// pass empty string as value to search for, displaying all results
						input.autocomplete( "search", "" );
						input.focus();
					});
			},

			destroy: function() {
				this.input.remove();
				this.button.remove();
				this.element.show();
				$.Widget.prototype.destroy.call( this );
			}
		});
	})( jQuery );

	$(function() {
		$( "#combobox" ).combobox();
		$( "#toggle" ).click(function() {
			$( "#combobox" ).toggle();
		});
		
	});

	
//	$(function(){
		// Dialog			
//		$('#dialog-add_groups').dialog({
//			modal:true,
//			autoOpen: false,
//			width: 600,
//			buttons: {
//				"Ok": function() { 
//					$(this).dialog("close"); 
//				}, 
//				"Cancel": function() { 
//					$(this).dialog("close"); 
//				} 
//			}
//		});
		// Dialog Link
//		$('#dialog_link_add_groups').click(function(){
//			$('#dialog-add_groups').dialog('open');
//			return false;
//		});	
	
	//hover states on the static widgets
	$('ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }
	);
});















