///////////////////////////////////////////////////////////////////////
// Open API Connect
///////////////////////////////////////////////////////////////////////

var jjOpenAPIConnect = { 

	twitterCallbackFunc : null,
	me2dayCallbackFunc : null,

	// 트위터...
	checkTwitter : function (callback)
	{	
		var whereIs = "";
		// 스튜디오에서 접속
		if(document.URL.indexOf("/studio/") != -1){
			whereIs = "S";
		}
		else{
			whereIs = "H";
		}
		//alert(whereIs);
		this.twitterCallbackFunc = callback;
		var filepath;
		filepath = "/hompy.setup.jjang?cmd=twitterStep1&whereIs="+whereIs;
		width = screen.width;
		height = screen.height;
		vleft = (width-900)/2;
		vtop = (height-400)/2;
		option = "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=900,height=400,top="+vtop+",left="+vleft;
		window.open(filepath,'twitterStep1',option);
	},
	removeTwitter : function (callback)
	{	 
		this.twitterCallbackFunc = callback;
		jQuery.post(
			"/hompy.setup.jjang?cmd=twitterClear",
			{
			},
			function(json, textStatus) {
				if( textStatus == "success" ) {
					if( json.result == "OK" ) {
						callback(false);
					}
				}
			},
			"json"
		);
	},	
	sendTwitter : function (msg, callback)
	{
		jQuery.post(
			"/hompy.setup.jjang?cmd=twitterSendMessage",
			{
				msg :	msg
			},
			function(json, textStatus) {
				if( textStatus == "success" ) {
					if( json.result == "OK" ) {
						callback(true);
					} else {
						callback(false);
					}
				}
			},
			"json"
		);
	},
	
	twitterCallback : function (result)
	{
		if(this.twitterCallbackFunc != null)
			this.twitterCallbackFunc(result);
		this.twitterCallbackFunc = null;
	},
	
	// 미투데이...
	checkMe2day : function (callback)
	{
		this.me2dayCallbackFunc = callback;
		var filepath;
		filepath = "/hompy.setup.jjang?cmd=me2dayStep1";
		width = screen.width;
		height = screen.height;
		vleft = (width-350)/2;
		vtop = (height-270)/2;
		option = "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=350,height=270,top="+vtop+",left="+vleft;
		window.open(filepath,'twitterStep1',option);
	},
	
	removeMe2day : function (callback)
	{
		this.me2dayCallbackFunc = callback;
		jQuery.post(
			"/hompy.setup.jjang?cmd=me2dayClear",
			{
			},
			function(json, textStatus) {
				if( textStatus == "success" ) {
					if( json.result == "OK" ) {
						callback(false);
					}
				}
			},
			"json"
		);
	},
	
	sendMe2day : function (msg, tag, callback)
	{
		jQuery.post(
			"/hompy.setup.jjang?cmd=me2daySendMessage",
			{
				msg :	msg,
				tag :	tag
			},
			function(json, textStatus) {
				if( textStatus == "success" ) {
					if( json.result == "OK" ) {
						callback(true);
					} else {
						callback(false);
					}
				}
			},
			"json"
		);
	},
	
	me2dayCallback : function (result)
	{
		if(this.me2dayCallbackFunc != null)
			this.me2dayCallbackFunc(result);
		this.me2dayCallbackFunc = null;
	},

		// 페이스북
	checkFacebook : function (callback)
	{
		this.facebookCallbackFunc = callback;
		var filepath;
		filepath = "/hompy.setup.jjang?cmd=facebookStep1";
		width = screen.width;
		height = screen.height;
		vleft = (width-600)/2;
		vtop = (height-500)/2;
		option = "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=600,height=500,top="+vtop+",left="+vleft;
		window.open(filepath,'facebookStep1',option);
	},
	
	removeFacebook : function (callback)
	{
		this.facebookCallbackFunc = callback;
		jQuery.post(
			"/hompy.setup.jjang?cmd=facebookClear",
			{
			},
			function(json, textStatus) {
				if( textStatus == "success" ) {
					if( json.result == "OK" ) {
						callback(false);
					}
				}
			},
			"json"
		);
	},
	
	sendFacebook : function (msg, tag, callback)
	{
		jQuery.post(
			"/hompy.setup.jjang?cmd=facebookSendMessage",
			{
				msg :	msg,
				tag :	tag
			},
			function(json, textStatus) {
				if( textStatus == "success" ) {
					if( json.result == "OK" ) {
						callback(true);
					} else {
						callback(false);
					}
				}
			},
			"json"
		);
	},
	
	facebookCallback : function (result)
	{
		if(this.facebookCallbackFunc != null)
			this.facebookCallbackFunc(result);
		this.facebookCallbackFunc = null;
	},
		// 요즘
	checkYozm : function (callback)
	{
		this.yozmCallbackFunc = callback;
		var filepath;
		filepath = "/hompy.setup.jjang?cmd=yozmStep1";
		width = screen.width;
		height = screen.height;
		vleft = (width-600)/2;
		vtop = (height-500)/2;
		option = "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=600,height=500,top="+vtop+",left="+vleft;
		window.open(filepath,'yozmStep1',option);
	},
	
	removeYozm : function (callback)
	{
		this.yozmCallbackFunc = callback;
		jQuery.post(
			"/hompy.setup.jjang?cmd=yozmClear",
			{
			},
			function(json, textStatus) {
				if( textStatus == "success" ) {
					if( json.result == "OK" ) {
						callback(false);
					}
				}
			},
			"json"
		);
	},

	sendYozm : function (msg, tag, callback)
	{
		jQuery.post(
			"/hompy.setup.jjang?cmd=yozmSendMessage",
			{
				msg :	msg,
				tag :	tag
			},
			function(json, textStatus) {
				if( textStatus == "success" ) {
					if( json.result == "OK" ) {
						callback(true);
					} else {
						callback(false);
					}
				}
			},
			"json"
		);
	},
	
	yozmCallback : function (result)
	{
		if(this.yozmCallbackFunc != null)
			this.yozmCallbackFunc(result);
		this.yozmCallbackFunc = null;
	}
};

