jQuery().ready(function(){	

	//all hover and click logic for UI buttons
	jQuery(".sf_button:not(.ui-state-disabled)")
	.hover( 
		function(){ jQuery(this).removeClass('ui-state-default').addClass("ui-state-hover"); },
		function(){ jQuery(this).removeClass("ui-state-hover").addClass('ui-state-default'); }
	);

	/*
		Javascript for list view only
	*/
	if (jQuery('.sf_admin_list').length)
	{
		// actions menu on list view
		var $actions = jQuery('#sf_admin_actions_button');
		if ($actions.length)
		{
  		$actions.menu({ 
  			content: jQuery('#sf_admin_actions_menu').html(),
  			showSpeed: 300
  		});
		}
		// filter button to show the modal window of available filters
		jQuery('#sf_admin_filter_button a')
			.addClass('sf_button-toggleable')
			.click(function() {
				jQuery('.sf_admin_filter').dialog('isOpen') ? jQuery('.sf_admin_filter').dialog('close') : jQuery('.sf_admin_filter').dialog('open');
				return false;
			});

		// modal window for filters
		buttons = {};
		try
		{
		  filterLabel = AdminI18n.Filter;
		  resetLabel = AdminI18n.Reset;
		}
		catch (err)
		{
		  filterLabel = "Filter";
		  resetLabel = "Reset";
		}
		buttons[filterLabel] = function() { 
        jQuery(this).dialog("close"); 
        jQuery('#sf_admin_filter_submit').parents('form').submit();
    };
    buttons[resetLabel] = function() { 
        jQuery(this).dialog("close");
        var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'post'; f.action = jQuery('#sf_admin_filter_reset').attr('href');f.submit();return false;
    };
    
	  jQuery('.sf_admin_filter').dialog({
			autoOpen: false,
			width: 600,
			close: function(evt, ui){
				jQuery('#sf_admin_filter_button', '#sf_admin_filter_reset_button').removeClass('ui-state-active');
			},
			open: function(evt,ui){
				jQuery('#sf_admin_filter_reset, #sf_admin_filter_submit').hide();
				jQuery('#sf_admin_filter_button', '#sf_admin_filter_reset_button').addClass('ui-state-active');
			},
			buttons: buttons
		});

		// mouseover and click on table row
		jQuery('.sf_admin_list table tbody tr')
			.hover(
				function(){	jQuery(this).addClass('ui-state-hover') },
				function() { jQuery(this).removeClass('ui-state-hover') }
			)
		.click(function(e) {
			// change row color
			jQuery(this).toggleClass('ui-state-highlight');
			// change checkbox status
			var chx = jQuery(this).find('input:checkbox');
			if (jQuery(this).hasClass('ui-state-highlight')) jQuery(chx).attr('checked','checked');
			else jQuery(chx).removeAttr('checked');
		});
	}
	
	/*
		Javascript for form view only
	*/
	if (jQuery('.sf_admin_form').length)
	{
		// tabs for form edition
		var $tabs = jQuery('#sf_admin_form_tab_menu');
		if ($tabs.length)
		{
		  $tabs.tabs();
		}
	}

});

