function bump(cid) {
	$.get("/rpc.php?act=bump&content_id=" + cid, function(data) {
		if ($("#" + data)) {
			$("#" + data).attr("class", "bumpedlink");
			$("#" + data).click(function() {
				alert("you have already bumped this content");
			});
		} 
	});
}

function vote(cid, v) {
	$.get("/rpc.php?act=vote&content_id=" + cid + "&vote=" + v, function(data) {
		$("#catvoter").html(data);
	});
}

function tag(cid) {
	$.get("/rpc.php?act=tag&do=tag&content_id=" + cid + "&tags=" + escape($("#tagfield").val()), function(data) {
		$.get("/rpc.php?act=load_tags&content_id=" + cid, function(data) {
			$("#tagfield").val('');
			$(".tags").html(data);
			$('#addTagForm').hide();
//			$("#catvoterhide").show();
		});
	});
}

function s2f(cid) {
	$("#s2fForm").ajaxSubmit({
		url: "/rpc.php?act=s2f",
		dataType: 'script'
	});
}

function initPage() {
	$("#loginForm").ajaxForm({
		url: '/rpc.php?act=login',
		dataType: 'script'
	});
	
	$("#registerForm").ajaxForm({
		url: '/rpc.php?act=register',
		dataType: 'script'
	});
	
	$(".bumplink").click(function() {
		bump($(this).attr("rel"));
	});
	
	$(".bumpedlink").click(function() {
		alert("you have already bumped this content");
	});
	
	$("a.cluetip").cluetip({
		splitTitle: '|', 
	    cluetipClass: 'jtip',
    	closePosition: 'title',
    	arrows: true,
    	closeText: "&nbsp;&nbsp;"
    }).click(function() {
		$('#cluetip').hide();
	});
	
	$(".favLink").click(function() {
		var link = $(this);
		
		$.get("/rpc.php?act=toggleFav&cid=" + $(this).attr("rel"), function(data) {
			var text = "";
			
			if (data == "1") {
				var text = "Added Favorite. Click here to remove it";
			} else if (data == "0") {
				var text = "Deleted Favorite. Click here to re-add it";
			} else if (data == "2") {
				alert('You must be logged in to access your favorites');
			} else {
				alert(data);
			}
			
			if (text != "") {
				link.text(text);
			}
		});
		
		return false;
	});
	
	$("#popularblock .links a").click(function(e) {
		e.preventDefault();
		
		$("#popularblock .links a").attr("class", "poplink");
		$(this).attr("class", "poplinkon");				
		$("#popularblock .body ul").hide();
		$("#popular_" + $(this).attr("href").replace(/#/, "")).show();
	});

	$("#popularblock ul").hide();	
	$("#popularblock .links a").attr("class", "poplink");
	$("#popdailylink").attr("class", "poplinkon");
	$("#popular_daily").show();	
}