$j(document).ready(function(){
	$j("#commented-emailed .fmenu a").click(function(){
		var b = $j("#commented-emailed");
		if (this.id == "show-commented"){
			if($j(b).hasClass("emailed-visible")){
				$j(b).removeClass("emailed-visible").addClass("commented-visible");
			}
		} else {
			if($j(b).hasClass("commented-visible")){
				$j(b).removeClass("commented-visible").addClass("emailed-visible");
			}
		}
		return false;
	});
	$j("#search-string").focus(function(){
		if (this.value == "Search SF APPEAL") {
			this.value = "";
			$j(this).removeClass("inactive");
		}
	});
	if($j("#cat-title")){
		var titlesize = $j("#cat-title h1").height();
		if (titlesize < 50){
			$j("#cat-title h1").css("margin-top","29px");
		}
	}
	if($j(".stats-share")){
		$j(".stats-share a.open-share").click(function(){
			$j(".social_bookmarks_wrap").toggle();
			return false;
		});
	}
});


function insertSocialBookmarkLinks(pageUrl,title,whichOnes) {
	if( !pageUrl )
		pageUrl = location.href;
	if( !title )
		title = document.title;
	if(!whichOnes)
		whichOnes = ["facebook","delicious","stumbleupon","digg","newsvine","fark"];
	
	var info;
	var output = "";
	
	for( var i=0; i < whichOnes.length; i++ ) {
		info = null;
		switch( whichOnes[i] ) {
			case "delicious":
				info = getDeliciousInfo(pageUrl,title);
				break;
			case "digg":
				info = getDiggInfo(pageUrl,title);
				break;
			case "technorati":
				info = getTechnoratiInfo(pageUrl,title);
				break;
			case "reddit":
				info = getRedditInfo(pageUrl,title);
				break;
			case "stumbleupon":
				info = getStumbleUponInfo(pageUrl,title);
				break;
			case "slashdot":
				info = getSlashdotInfo(pageUrl,title);
				break;
			case "facebook":
				info = getFacebookInfo(pageUrl,title);
				break;
			case "newstrust":
				info = getNewsTrustInfo(pageUrl,title);
				break;
			case "newsvine":
				info = getNewsvineInfo(pageUrl,title);
				break;
			case "fark":
				info = getFarkInfo(pageUrl,title);
				break;
		}
		if( info ) {
			output += getListItem(info);
		}
	}
	document.write("<ul class=\"social_bookmarks\">" + output + "</ul>");
}
function getListItem(info) {
	var socialOnClick = "";
	if (info.onclick != "") { socialOnClick = "\" onclick=\"" + info.onclick; }
	var output = "<li><a href=\"" + info.href + socialOnClick + "\" class= \"" + info.handle + "\" title=\""+info.alt+"\">" + info.text + "</a></li>";
	return output;
}
function getDeliciousInfo(pageUrl,title) {
	var info = new Object();
	info.handle = "delicious";
	info.text = "del.icio.us";
	info.href = "http://del.icio.us/post?v=4&noui&jump=close&url="+encodeURIComponent(pageUrl)+"&title="+encodeURIComponent(title);
	info.onclick = "window.open(this.href,'"+info.handle+"','toolbar=no,width=700,height=400');return false;";
	info.alt = "del.icio.us";
	return info;
}
function getDiggInfo(pageUrl,title) {
	var info = new Object();
	info.handle = "digg";
	info.text = "Digg";
	info.href = "http://digg.com/submit?phase=2&url="+encodeURIComponent(pageUrl)+"&title="+encodeURIComponent(title)+"&topic=television";
	info.onclick = "";
	info.alt = "Digg!";
	return info;
}
function getTechnoratiInfo(pageUrl,title) {
	var info = new Object();
	info.handle = "technorati";
	info.text = "Technorati";
	info.href = "http://technorati.com/faves/?add="+encodeURIComponent(pageUrl);
	info.onclick = "";
	info.alt = "Technorati";
	return info;
}
function getRedditInfo(pageUrl,title) {
	var info = new Object();
	info.handle = "reddit";
	info.text = "reddit";
	info.href = "http://reddit.com/submit?url="+encodeURIComponent(pageUrl);
	info.onclick = "";
	info.alt = "Reddit";
	return info;
}
function getStumbleUponInfo(pageUrl,title) {
	var info = new Object();
	info.handle = "stumbleupon";
	info.text = "StumbleUpon";
	info.href = "http://www.stumbleupon.com/submit?url="+encodeURIComponent(pageUrl)+"&title="+encodeURIComponent(title);
	info.onclick = "";
	info.alt = "StumbleUpon";
	return info;
}
function getSlashdotInfo(pageUrl,title) {
        var info = new Object();
        info.handle = "slashdot";
        info.text = "Slashdot";
        info.href = "http://slashdot.org/bookmark.pl?url="+encodeURIComponent(pageUrl)+"&title="+encodeURIComponent(title);
        info.onclick = "";
        info.alt = "Slashdot It!";
        return info;
}

function getFacebookInfo(pageUrl,title) {
        var info = new Object();
        info.handle = "facebook";
        info.text = "Facebook";
        info.href = "http://www.facebook.com/share.php?u="+encodeURIComponent(pageUrl)+"&t="+encodeURIComponent(title);
        info.onclick = "";
        info.alt = "Share on Facebook";
        return info;
}

function getNewsTrustInfo(pageUrl,title) {
        var info = new Object();
        info.handle = "newstrust";
        info.text = "NewsTrust";
        info.href = "http://www.newstrust.net/submit?ref=pbs.org&url="+encodeURIComponent(pageUrl)+"&title="+encodeURIComponent(title);
        info.onclick = "";
        info.alt = "Review it on NewsTrust";
        return info;
}

function getNewsvineInfo(pageUrl,title) {
        var info = new Object();
        info.handle = "newsvine";
        info.text = "Newsvine";
        info.href = "http://www.newsvine.com/_tools/seed&save?u="+encodeURIComponent(pageUrl)+"&h="+encodeURIComponent(title);
        info.onclick = "";
        info.alt = "Seed a Link on Newsvine";
        return info;
}

function getFarkInfo(pageUrl,title) {
        var info = new Object();
        info.handle = "fark";
        info.text = "Fark";
        info.href = "http://cgi.fark.com/cgi/fark/farkit.pl?u="+encodeURIComponent(pageUrl)+"&h="+encodeURIComponent(title);
        info.onclick = "";
        info.alt = "Fark";
        return info;
}
