	// --------------------------------------------------------------------------
	//		Document ready 
	// --------------------------------------------------------------------------	 
	

	$(document).ready(function()
	{
	
		//	Favorite job switcher
		$('.favSwitch, .jobtable td.fav')
			.live('mouseover mouseout', function() 
			{
				iconFavoriteHover(this);
			}) 
			.live('click', function(event)
			{
				event.stopImmediatePropagation();
				
				elem = $(this).find('img');
				src = $(elem).attr('src');			
			    fullUrl = "/job/favorite/" + $(elem).attr('id').substr(3) + "/?action=";
			    
			    $(elem).attr('src', src.replace('clear.gif', 'loading.gif'));
			    
				if ( $(elem).hasClass('favoriteDelete') )
				{
				    fullUrl += 'remove';
					setIcon16(elem, 'favoriteAdd');
				}
				else
				{
				    fullUrl += 'add';
					setIcon16(elem, 'favoriteDelete');
				}
				
			    $.ajax({
			        url: fullUrl,
			        success: function() 
			        {
			            setTimeout(function()
			            {
			                $(elem).attr('src', src.replace('loading.gif', 'clear.gif'));
			            }, ajaxLoadingDelay)
			        }
			    })

				return false;
			})
			
		
		//	Delete favorite job
		
		$('#favorites td.delFav')
			.hover(function() 
			{
				iconFavoriteHover(this);
			}) 
			.click(function(event)
			{
				event.stopImmediatePropagation();
				
				elem = $(this).find('img');
				src = $(elem).attr('src');			
			    fullUrl = "/job/favorite/" + $(elem).attr('id').substr(3) + "/?action=remove";
			    
			    $(elem).attr('src', src.replace('clear.gif', 'loading.gif'));
			    	    
			    $.ajax({
			        url: fullUrl,
			        success: function() 
			        {
			            setTimeout(function()
			            {
			                table = $(elem).parents('table');
			                
			                $(elem).parents('tr.basic').fadeOut(750, function ()
			                {
			                    $(this).remove();
			                })
			                $(elem).parents('tr.basic').next('tr.extended').fadeOut(750, function()
			                {
			                    $(this).remove();
			                    
			                    if ($(table).find('tbody tr').length < 2)
			                    {
			                        window.location.reload(true);
			                    }
			                })
			            }, ajaxLoadingDelay)
			        }
			    })

				return false
			})
			
	})


	// --------------------------------------------------------------------------
	//		Functions
	// --------------------------------------------------------------------------	 
	
	
	function iconFavoriteHover(e)
	{
		if (! $(e).is('img'))
		{
			e = $(e).find('img.icon16')
		}
		
		if ($(e).hasClass('favorite') || $(e).hasClass('favoriteDelete'))
		{
			$(e).toggleClass('favorite').toggleClass('favoriteDelete')
		}
		else if ($(e).hasClass('favoriteOff') || $(e).hasClass('favoriteAdd'))
		{
			$(e).toggleClass('favoriteOff').toggleClass('favoriteAdd')
		}
		
		$(e).blur()
	}
	
