$(function() { //on page load...
	$(document).pngFix();
	if (typeof(show_confirmation)!="undefined") {
		var cp_url = document.URL;
		if (cp_url.match("#user_confirmed")) {
			tb_show("Test","register.confirmed.php?width=320&height=200&KeepThis=true&TB_iframe=true");
		}
	}
	$("img[alt=share]").click(function() {
		monitor_add('share');
	});

	$(".rate").click(function() {
		monitor_add('rate');
		var uid = cp_permitted();
		if (uid>0) {
			$(this).attr("src", cp_dirup+"images/btn-rate-on.gif");
			var m_id = $(this).attr("id").replace("r","");
			cp_rate_item(m_id);
		} else {
			cp_alert("Sorry, only registered users can rate posts.", "&login=true");
		}
		return false;
	});
	$("#bncode").focus(function() {
		this.select();
	});
	$("#bncode").click(function() {
		this.select();
	});
	$("a[href$='xml']").tooltip({
	    bodyHandler: function() { 
        	return "RSS stands for Really Simple Syndication.<br>An RSS feed is a document that contains either a summary of content from a web site or the full text of a website.<br>RSS feeds makes it possible for people to keep up with their favorite web sites automatically rather than checking them manually."; 
    	},
    	showURL:false,
    	fade:200
	});
});

//save user's settings (celebs and order)
function cp_save_my_settings() {
	var celebs = $('#sortable').sortable('toArray');
	var ca = new Array();
	var k = 0;
	if (typeof(celebs)!="undefined" && celebs.length>0) {
		jQuery.each(celebs, function() {
			ca[k] = this.replace("c","");
			k++;
	    });
	}
	$.ajax({
		type: "GET",
		url: "../ajax.save.my.settings.php",
		data: "action=save&c="+ca.join("-"),
		success: function(msg){
		$("#save").attr("disabled", true);
			alert(msg);
	   	}
	 });
}

function cp_delete_my_celeb(c_id) {
	if (!confirm("Please confirm celebrity removal.")) return;
	$.ajax({
		type: "GET",
		url: "../ajax.save.my.settings.php",
		data: "action=delete&c_id="+c_id,
		success: function(msg){
			$("#save").attr("disabled", true);
			$("li#c"+c_id).remove();
	   	}
	 });
}

function cp_alert(msg, params) {
	tb_show("Info", cp_dirup+"cp.alert.php?msg="+escape(msg)+params+"&KeepThis=true&TB_iframe=true&height=120&width=280");
}

function cp_permitted() {
	var uid = 0;
	$.ajax({
		type: "GET",
		url: cp_dirup + "ajax.permitted.php",
		async: false,
		success: function(msg){
			uid = msg;
			//alert(uid);
	   	}
	 });
	return uid;
}

function cp_rate_item(m_id) {
	$.ajax({
		type: "GET",
		url: cp_dirup + "ajax.rate.php",
		data: "m_id="+m_id,
		async: true,
		success: function(msg){
			if (msg!="") {
				$("#r"+m_id).attr("src", cp_dirup+"images/btn-rate.gif");
				cp_alert(msg);
			}
	   	}
	 });
}

//hide breaking news on my pursuits page
function cp_hide_my_bn() {
	$.cookie("cp_my_bn_off", true, {expires:1000});
	$("#breaking2").hide();
	return false;
}

function monitor_add(what) {
	$.ajax({
		type: "GET",
		url: cp_dirup + "ajax.monitor.php",
		data: "what="+what
	 });
}