function voting(postID, option) {
	if(!isNaN(parseInt(postID))) {
		$.ajax({
			type: "GET",
			url: "/ajax/post_agree_ajax1.php",
			data: "postid="+postID+"&option="+option,
			cache: false,
			success: function(html) {
				$("#agreebox"+postID).replaceWith(html);
				refreshScripts();
			}
		}); //close $.ajax(

		if(option != 2){		
			$.ajax({
				tpye: "GET",
				url : "/ajax/post_agree_ajax2.php",
				data: "postid="+postID+"&option="+option,
				cache: false,
				success: function(html){
					$("#petals"+postID).replaceWith(html);
					refreshScripts();
				}
			});
		}
	}
}

//respond post
function responding(postID) {
	//	$("#flash").show();
	//	$("#flash").fadeIn(400).html('<span class="loading">Loading respond...</span>');

	$.ajax({
		type: "POST",
		url: "/ajax/get_new_post.php",
		cache: false,
		success: function(html){
			$("#post"+postID).append(html);
			refreshScripts();
		}
	});
}


//Post question
function posting() {
	$.ajax({
		type: "POST",
		url: "/ajax/get_new_post.php",
		cache: false,
		success: function(html){
			$("#top").append(html);
			refreshScripts();
		}
	});
}

function refreshScripts() {
	$(".post_input").colorbox({opacity:0.8, width:930, height:580, iframe:true, scrolling:false, onClosed:function(){location.reload(true);}});
	$(".video_colorbox").colorbox({opacity:0.8, width:930, height:580, iframe:true, scrolling:false, onClosed:function(){location.reload(true);}});
	$(".agreeframe").colorbox({opacity:0.8, width:930, height:580, iframe:true, scrolling:false, onClosed:function(){location.reload(true);}});
	$(".fwd_invite").colorbox({opacity:0.8, width:930, height:580, iframe:true, scrolling:false});
	$(".postfwd_invite").colorbox({opacity:0.8, width:930, height:580, iframe:true, scrolling:false, onClosed:function(){posting();}});
	$(".respondfwd_invite").colorbox({opacity:0.8, width:930, height:580, iframe:true, scrolling:false, onClosed:function(){var id = $(this).attr("id"); responding(id);}});
	$(".vote_invite").colorbox({opacity:0.8, width:930, height:580, iframe:true, scrolling:false, onClosed:function(){var id= $(this).attr("id"); voting(id, 1);}});
	$(".vote_invite_frontpage").colorbox({opacity:0.8, width:930, height:580, iframe:true, scrolling:false, onClosed:function(){var id= $(this).attr("id"); voting(id, 0);}});
 	$(".corner5").corner('5px');
}

function poli_rating(pid, rating) {
	if( !isNaN(parseInt(rating)) && !isNaN(parseInt(pid)) ) {
		$.ajax({
			type: "POST",
			url: "/poli_rate.php",
			data: "pid="+pid+"&rating="+rating,
			success: function(html) {
				$("#poli-rating").html(html);
			}
		}); //close $.ajax(
	}
}

function get_videobox(videoid) {
	$.ajax({
		type: "GET",
		url: "/videobox.php",
		data: "vid="+videoid,
		success: function(html) {
			$("#video-"+videoid).html(html);
		}
	}); //close $.ajax(
	return false;
}

