/* Code by micksam7 */

var sfSections = new Array("sofurry", "watchlist", "groups", "market");
// For now
function sfNavSectionToggle(selected) {
	for ( var t in sfSections) {
		t = sfSections[t];
		var subsection = document.getElementById('sf-topbar-subsections-' + t);
		var section = document.getElementById('sf-topbar-' + t);
		if (t == selected) {
			subsection.style.display = "block";
			section.className = "sf-topbar-" + t + " sf-topbar-" + t
					+ "-active";
		} else {
			subsection.style.display = "none";
			section.className = "sf-topbar-" + t;
		}
	}
	return false;
}

(function($){
	
$.fn.sftext = function() {
	return this.each(function() {
		var that = $(this);
		that.focus(function() {
			that.prev('label').hide();
		}).blur(function() {
			if(that.val()=='') that.prev('label').show();
		});
		if (that.val() != '')
			that.prev('label').hide();
	});
};
	
})(jQuery);

$(document).ready(function(){
	$(".titlehover a").append("<span></span>");
	$(".titlehover a").hover(function() {
		var hoverText = $(this).attr("title");
		if (hoverText != '') {
			$(this).find("span").animate({opacity: "show"}, "fast");
			$(this).find("span").text(hoverText);
		}
	}, function() {
		$(this).find("span").animate({opacity: "hide"}, "fast");
	});
	
	// Add selecting buttons
	$('.watchlist-nuke')
		.append('<a href="#" class="js_select_all">Select All</a>')
		.append('<a href="#" class="js_select_none">Select None</a>')
		
	// Selecting all
	$('.js_select_all').click(function() {
		$('.watchlist_item :checkbox').each(function() {
			$(this).attr('checked', 'checked').show()
		})
		$('.watchlist_item').addClass('selected')
		$('.js_nuke_button').removeAttr('disabled')
	})
	
	// Selecting none
	$('.js_select_none').click(function() {
		$('.watchlist_item :checkbox').each(function() {
			$(this).attr('checked', '').hide()
		})
		$('.watchlist_item').removeClass('selected')
		$('.js_nuke_button').attr('disabled', 'disabled')
	})
	
	// Set default value
	$('.js_nuke_button').attr('disabled', 'disabled')
	$('.watchlist_item :checkbox:not(:checked)').delay(3000).fadeOut(400);
	
	// Detect checked items, add selected class and show their checkbox
	$('.watchlist_item :checkbox:checked').each(function () {
	  $(this).parent().parent().toggleClass('selected');
	  $(this).show();
	})
	
	// Change nuke button value if items are selected
	if( $('.watchlist_item :checkbox:checked').length > 0 ) {
    $('.js_nuke_button').removeAttr('disabled')
  } else {
    $('.js_nuke_button').attr('disabled', 'disabled')
  }
	
	// Handles when listitem items are selected
	$('.watchlist_item :checkbox').live('change', function() {
	  $(this).parent().parent().toggleClass('selected');
	  $(this).show();
	  if( $('.watchlist_item :checkbox:checked').length > 0 ) {
	    $('.js_nuke_button').removeAttr('disabled')
	  } else {
	    $('.js_nuke_button').attr('disabled', 'disabled')
	  }
	})
	$('.watchlist_item').hover(function() {
	  $(this).find(':checkbox').stop(true, true).show();
	}, function () {
	  $(this).find(':checkbox:not(:checked)').delay(1000).fadeOut(400);
	})
}); 

function sfScrollTop()
{
	$(window).scrollTop(0);
}

