registerNS("mediare.article");

mediare.article.MainManager = $extend({

	// 우연한 발견 키워드를 보여준다. 
	showChanceList : function(keywordList){
		this.logger.debug("showchanceList function started");
		var keywords = keywordList.split(",");
		this.logger.debug(keywords);
		var html = "";
		for(var i=0; i < keywords.length; i++){
			if(i < 3){
				html += "<li><a href=\"#\" class=\"blod\">" + keywords[i] + "</a></li>";
			} else {
				html += "<li><a href=\"#\">" + keywords[i] + "</a></li>";
			}
		}
		$("#keywordList").append(html);
		
		// 키워드를 클릭 하였을때에 이벤트를 걸어준다.
		$("#keywordList").find("a").each(function(i){
			$(this).bind("click", function(e){
				 $("#txtTopSearchStr").val($("#txtTopSearchStr").val() + " " + $(this).html());
				 // $$gnb.topSearch();
				 return false;
			});
		})
		
		this.logger.debug("showchanceList function ended");
	},
	
	// 현재 보이는 잇글의 이전 잇글 또는 다음 잇글을 보여준다.
	showNextSpotList : function(num){
		this.logger.debug("showNextSpotList function started");
		var _self = this;
		$(".jaschinListBox").each(function(){
			_self.logger.debug($(this).attr("id"));
			if($(this).attr("id") == "jaschinListBox" + num){
				$(this).show();
			} else{
				$(this).hide();
			}
		});
		
		this.friendStyle(num);
		
		this.logger.debug("showNextSpotList function ended");
		return false;
	},
	
	// 메인 페이지 초기화 
	initMain : function(keywordList){
		var _self = this;
		
		// 검색창 비워주기 
		$("#txtTopSearchStr").val("");
		
		// 마이스토리 or 회원가입 버튼 보여주기 및 이벤트 생성 
		if ($$user.isLogin){
			$(".header").find("#btnMystory").show();
			$(".header").find("#btnRegister").hide();
		} else {
			$(".header").find("#btnMystory").hide();
			$(".header").find("#btnRegister").show();
		}
		
		$(".header").find(".headerBtn").click(function(){
			if ($$user.isLogin) location.href = "/" + $$user.id;
			else $$gnb.openRegistLayer();

			return false;
		});
		
		// 0. 우연한 발견 키워드를 보여준다.
		this.showChanceList(keywordList);
		
		// 2. 잇글 리스트 보여주기
		this.showNextSpotList("1");
		
		// 3. 자스친 리스트 스타일	
		this.friendStyle(1);
				
	},
	
	// 3. 자스친 리스트 스타일
	friendStyle : function(num){
	
		// animate
		var il = $('#jaschinListBox' + num);
		var jl =$('.jaschinList');
		il.find('#listStep li').hide();
		jl.hide();
		il.find('li.listStep1').fadeIn('fast');
		il.find('li.listStep2').animate({'opacity':'1.0'},100).fadeIn('fast');
		il.find('li.listStep3').animate({'opacity':'1.0'},200).fadeIn('fast');
		jl.animate({'opacity':'1.0'},200).fadeIn(700);

		// block element clickable
		il.find('#listStep').hover(function(){
			$(this).addClass('hover');
		},function(){
			$(this).removeClass('hover');
		});
		il.find('#listStep').click(function(){
			window.location=$(this).find('li.listStep3 dl dt a').attr('href');
			return false;
		});
		
		return false;
	},
	
	toString : function(){
		return "mediare.article.mainmanager";
	}
	
},"$mainmanager");


