﻿

(function($)
{
	$.GuideType = 
	{
		None : 0
	,	Tutorial : 1
	,	FeedRecommend : 2
	,	FeedGuide : 3
	};

	$.GuideCloseType = 
	{
		None : 0
	,	OK : 1
	,	Close : 2
	};

	$.Guide = {
		GetGuide : function( GuideType, callback )
		{
			var _callback = callback;
			$("body").ajaxNet(
				"/xsm/method/guidemethod.aspx?_vb=GetGuide",
				{
					"guideType": GuideType
				},
				_callback
			);
		},

		SetGuide : function( GuideType, GuideCloseType, callback )
		{
			var _callback = callback;
			$("body").ajaxNet(
				"/xsm/method/guidemethod.aspx?_vb=SetGuide",
				{
					"guideType": GuideType
				,	"closeType": GuideCloseType
				},
				_callback
			);
		},

		AddTutorialPing : function()
		{
			var NexonSNs = "";
			$("#Tutorial2>div.contents>div.recommend>ul.list>li").each( function()
			{
				if ( $(this).find("input:[type=checkbox]").attr("checked") )
				{
					NexonSNs += ( NexonSNs == "" ? "" : "," ) + $(this).find("input:[type=checkbox]").val();
				}
			});
			$("#Tutorial2").gLayer( "close" );
			if ( NexonSNs != "" )
			{
				$("#Tutorial2").addPing( NexonSNs, {
					isGuide:true,
					success: function() {
						$.Guide.SetGuide($.GuideType.Tutorial, $.GuideCloseType.OK, function(){} );
						if ( $("div.profile>div.info>dl.ping>dd>a").size() > 0 )
						{
							$("#Tutorial2").ajaxNet(
								"/xsm/method/pingmethod.aspx?_vb=GetPingCount",
							{},
							function(results, context) {
								$("div.profile>div.info>dl.ping>dd>a").text( results );
							});
						}
						$("#d_chatListWrapper").feed("getList");
					}
				} );
			}
		},

		AddChatListPing : function()
		{
			var NexonSNs = "";
			$("#m_ChatRecommendUser>div.recommend>ul.list>li").each( function()
			{
				if ( $(this).find("input:[type=checkbox]").attr("checked") )
				{
					NexonSNs += ( NexonSNs == "" ? "" : "," ) + $(this).find("input:[type=checkbox]").val();
				}
			});

			$("#m_ChatRecommendUser").addPing( NexonSNs, {
				success: function() {
					if ( $("div.profile>div.info>dl.ping>dd>a").size() > 0 )
					{
						$("#Tutorial2").ajaxNet(
							"/xsm/method/pingmethod.aspx?_vb=GetPingCount",
						{},
						function(results, context) {
							$("div.profile>div.info>dl.ping>dd>a").text( results );
						});
					}
					$("#d_chatListWrapper").feed("getList");
				}
			} );
		}
	};

	$.GuideViewer = {
		m_UserRecommend : null,
		UserRecommend : function( $elem, $nonElem )
		{
			if ( $.GuideViewer.m_UserRecommend == null )
			{
				$nonElem.ajaxNet(
					"/xsm/method/pingmethod.aspx?_vb=GetPingCount",
					{
					},
					function(results, context) {
						if ( results == 0 )
						{
							$nonElem.ajaxNet(
								"/xsm/method/guidemethod.aspx?_vb=GetRecommendUser",
								{
								},
								function(results, context) {
									$($elem).append( results );
									$.GuideViewer.m_UserRecommend = results;
								}
							);
						}
						else
						{
							$nonElem.show();
						}
					}
				);
			}
			else
			{
				if ( $("#m_ChatRecommendUser" ).size() > 0 )
				{
					$("#m_ChatRecommendUser" ).show();
				}
			}
		},

		m_ChatGuide : null,
		ChatGuide : function()
		{
			if ( $.GuideViewer.m_ChatGuide == null )
			{
				$.Guide.GetGuide( $.GuideType.FeedGuide, function(result, context)
				{
					if ( result.GuideCloseType == $.GuideCloseType.None )
					{
						$("body").ajaxNet(
							"/xsm/method/guidemethod.aspx?_vb=ChatGuide",
							{
							},
							function(results, context) {
								if ( $("#d_chatListWrapper>div.chatList").size() > 0 )
								{
									$("#d_chatListWrapper>div.chatList").prepend( results );
								}
								$.setPng24()
								$.GuideViewer.m_ChatGuide = results;
							}
						);
					}
				});
			}
			else
			{
				$("#m_ChatGuide" ).show();
			}
		},

		ChatGuide_Close : function()
		{
			if ( $( "#m_ChatGuide" ).size() > 0 )
			{
				$.Guide.SetGuide( $.GuideType.FeedGuide, $.GuideCloseType.OK, function(){ $( "#m_ChatGuide" ).remove(); } )
				
			}
		}
	};
})(jQuery);
