function showFriendMenu(id) {
	var position = "#friend_menu_" + id;
	$(position).fadeIn(200);
}

function hideFriendMenu(id) {
	var position = "#friend_menu_" + id;
	$(position).fadeOut(100);
}

var data = [];
var alreadyFetched = {};

function showFlot(uid, gid, fid, fnick, pub) {
	var placeholder = $("#placeholder");
	$.plot(placeholder, data, options);

	var options = {
		lines: { show: true },
		points: { show: true },
		xaxis: {
			tickDecimals: 0, tickSize: 1,
			autoscaleMargin: 0.5,
			tickFormatter: function(val, axis) {
				return val;
			}
		},
		yaxis: {
			tickDecimals: 0,
			ticks	: [
				[ 0, "Rank"],
				[ 1, "30"], [ 2, "29"], [ 3, "28"], [ 4, "27"], [ 5, "26"],
				[ 6, "25"], [ 7, "24"], [ 8, "23"], [ 9, "22"], [10, "21"],
				[11, "20"], [12, "19"], [13, "18"], [14, "17"], [15, "16"],
				[16, "15"], [17, "14"], [18, "13"], [19, "12"], [20, "11"],
				[21, "10"], [22, "09"], [23, "08"], [24, "07"], [25, "06"],
				[26, "05"], [27, "04"], [28, "03"], [29, "02"], [30, "01"],
				[31, ""]]
		}
	};

	var placeholder = $("#placeholder");
	var floturl = "http://ishtar.me/none.web/proxy/supporter/getSupporterFlot.php";

	$.ajax({
		url: floturl,
		data: "uid=" + uid + "&gid=" + gid + "&fid=" + fid + "&fnick=" + fnick + "&pub=" + pub,
		cache: false,
		dataType: 'json',
		success: function(res) {
			var firstcoordinate = '(' + res.data[0][0] + ', ' + res.data[0][1] + ')';
			if (!alreadyFetched[res.label]) {
				alreadyFetched[res.label] = true;
				data.push(res);
			}
			placeholder.show();
			$.plot(placeholder, data, options);
		}
	});	
}

function getSupporter(uid, gid, pub, rev) {
	$("#supporter_area").html("");
	
	var msg = "지지자 목록 정리중";
	if(!rev) rev = 0;
	
	if(rev == 1) msg = "친한친구 목록 정리중";
	else if(rev == 2) msg = "절친 목록 정리중";

	$("#supporter_area").html("<div style='text-align:center; width:100%; padding-top:70px;'><img src='http://ishtar.me/none.web/images/loading.gif' /><br/>"+msg+"</div>");
	var strParam = "gid=" + gid + "&uid=" + uid + "&pub=" + pub + "&rev=" + rev;

	var supUrl = "http://ishtar.me/none.web/proxy/supporter/getSupporterHTML.php";

	$.ajax({
		url: supUrl,
		data: strParam,
		cache: false,
		success: function(res) {
			$("#supporter_area").html(res);
			$("#supporter_area").ready(
				function () {
					$('.mysupporter').mouseover(
						function() {
							$(this).find('span.friend_nick').hide();
							$(this).find('span.friend_id').show();
						}
					);
					$('.mysupporter').mouseout(
						function() {
							$(this).find('span.friend_nick').show();
							$(this).find('span.friend_id').hide();
						}
					);

					PEPS.rollover.init();
			});
		}
	});
}

function summonUser(userid, nickname) {
	var current = $("#postTextBox").val();
	var decoUserid = '"' + nickname + '"' + ":http://me2day.net/" + userid + " ";
	if(current.length > 0) $("#postTextBox").val(current + " " + decoUserid);
	else $("#postTextBox").val(decoUserid);
	watchDog();
}

function summonAllUser(postfix) {
	var current = $("#postTextBox").val();
	var decoUserid = "/" + userid + "/";
	if(current.length > 0) $("#postTextBox").text(current + "," + decoUserid);
	else $("#postTextBox").text(decoUserid);
}

function hasExpression(A) {
    var link_regex = /\"(.*?)\":(http[s]?:\/\/[^\s]*)(\s|$)([!]{0,})/;
	if (link_regex.test(A))	return true;
	else return false;
}

function replaceAll(A) {
    var link_regex = /\"(.*?)\":(http[s]?:\/\/[^\s]*)(\s|$)([!]{0,})/;

	var exists = true;
	var resText = A;

	if(link_regex.test(resText)) {
		while (exists) {
			resText = resText.replace(link_regex, "<a href='$2' title='$1' target='_blank'>$1</a>");
			exists = link_regex.test(resText);
		}
	}
	return resText;
}

PEPS = {};
PEPS.rollover =
{
   init: function() {
      this.preload();
     
      $(".ro").hover(
         function () { $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) ); },
         function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) ); }
      );
   },

   preload: function() {
      $(window).bind('load', function() {
         $('.ro').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
      });
   },
   
   newimage: function(src) {
      return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_o' + src.match(/(\.[a-z]+)$/)[0];
   },

   oldimage: function(src) {
      return src.replace(/_o\./, '.');
   }
};

function trim(str) { return str.replace(/(^\s*)|(\s*$)/g, ""); }

