// ajax pattern in Game
var GameAjax=Class.create(); 
GameAjax.prototype={
initialize: function(){
						this.selectedDate	=new Date()
						if(arguments[0]){
							this.url	= arguments[0].url || this.url;
							this.method	= arguments[0].method || this.method;
							this.params = arguments[0].params || this.params;
							if(arguments[0].selectedDate){
									this.selectedDate.setYear(arguments[0].selectedDate.toString().substr(0,4));	
									this.selectedDate.setMonth(parseInt(arguments[0].selectedDate.toString().substr(4,2),10) -1 );
									this.selectedDate.setDate(parseInt(arguments[0].selectedDate.toString().substr(6,2),10));								
							} 
						}
						
 
						this.today			=this.setFormattedDate(this.selectedDate);
},
selectedDate:null,
today: null,
cache: new Array(),
url:"/game/Json4Test.htm",
method:"get",
params:{"date":this.today},
getAjaxData: function (url,method,params,func){
    var myAjax = new Ajax.Request( 
            url, 
            {   method: method, 
                parameters: params, 
                onComplete: eval(func)
            }
    ); 
},	
setFormattedDate: function(dateObj){
									var month	= (dateObj.getMonth()+1).toString().length < 2 ? "0"+(dateObj.getMonth()+1).toString() : (dateObj.getMonth()+1).toString();
									var day		=  dateObj.getDate().toString().length < 2 ? "0"+dateObj.getDate().toString() :  dateObj.getDate().toString();
									var formattedDate		=dateObj.getFullYear().toString()+  month +day; 
									return formattedDate;
},
getDataByDirection :  function(direction){ 
	this.selectedDate.setDate(this.selectedDate.getDate()+direction);
	this.getDataByDate(this.setFormattedDate(this.selectedDate)); 
},

getDataByDate : function(date){ 
	this.params={"date":date}
	this.getData(); 
	this.selectedDate.setYear(date.toString().substr(0,4));	
	this.selectedDate.setMonth(parseInt(date.toString().substr(4,2),10) -1,10 );
	this.selectedDate.setDate(parseInt(date.toString().substr(6,2),10));
},
getData: function(){
			if(this.cache[this.params.date]){
				this.callback(this.cache[this.params.date]);
			}
			else{			
				this.getAjaxData(this.url,this.method,this.params,
				function(originalRequest,pars){
					eval("var obj = " + originalRequest.responseText);
					this.callback(obj);
					this.cache[this.params.date]=obj;

				}.bind(this));				
			}
},
callback: function(obj){},
test:"ok",
testFunc: function(){ alert(this.test);}	
}
//  ( Game TopbestGameClips) GameAjax   
var TopBestGames=Class.create(); 
TopBestGames.prototype = new GameAjax({"url":"/game/json/Json4BestGameClips.do"});
TopBestGames.prototype.cache =  new Array(); // 여기서 선언 안 해주면 GameAjax 공유해버림. 
TopBestGames.prototype.callback = function(obj){
						var HTMLArray= new Array();
						var HTML;
						var title;
						var titleLength=30;
						$("bestGameClipsDate").innerHTML=obj[0].formattedDate;
						if(obj[0].noData==true){alert("자료가 없습니다.");return false;}
						obj.each(
						function(value, index){
							if(obj[index].title.length > titleLength){title=obj[index].title.substr(0,titleLength) +"..";}
							else{title=obj[index].title}
							HTML='	<dl>\
										<dd class="image" >\
										<a href="'+obj[index].linkUrl+'"><img width="89" height="67" alt="'+obj[index].title+'" src="'+obj[index].thumbUrl+'"/></a>\
										</dd>\
										<dt><a href="'+obj[index].categoryLinkUrl+'">'+obj[index].categoryName+'</a></dt>\
										<dd class="summary"><a href="'+obj[index].linkUrl+'">'+title+'<em class="comment_count">['+obj[index].commentCnt+']</em></a></dd>\
										<dd class=""><span class="play_ number">'+obj[index].playcnt+'</span></dd>\
									</dl>';
							HTMLArray.push(HTML);
						}
						);
					

						this.predate=obj[0].predate || "";
						this.nextdate=obj[0].nextdate || "";
						if(this.predate.trim() !=""){
							$("btnShowPrevBest").onclick=function(){this.getDataByDate(this.predate);return false;}.bind(this);;
						}
						else{
							$("btnShowPrevBest").onclick=function(){ showMsgBox({msg:"더 이상 목록이 없습니다.",interval:1000, wrapperObj:$('bestGameClipsWrapper'), top:100,left:160});   return false;}
						}
						if(this.nextdate.trim() !=""){
							$("btnShowNextBest").onclick=function(){this.getDataByDate(this.nextdate);return false;}.bind(this);;
						}
						else{
							$("btnShowNextBest").onclick=function(){ showMsgBox({msg:"더 이상 목록이 없습니다.", wrapperObj:$('bestGameClipsWrapper'), top:100,left:160});  return false;}
						}						
						$("bestGameClipsWrapper").innerHTML=HTMLArray.join("");
}
//  (공통 3단/Game Top) GameAjax   
var GameSchedule=Class.create(); 
GameSchedule.prototype = new GameAjax({"url":"/game/json/Json4MiniSchedule.do"});
GameSchedule.prototype.callback = function(obj){
	
				var HTML;
				var HTMLArray= new Array();
				var className, title, banner;
				var bannerNum =(parseInt(Math.random() * 10)  % 3) + 1;
				$("scheduleDate").innerHTML=obj[0].formattedDate;
				if(obj[0].noData==true){
					HTML ='<div class="message">'+obj[0].formattedDate+'은 <br/>생중계가 없습니다.</div>'

/*
 	@title : 스타 생중계 다음스포츠로 이관관련 삭제코드
 	@date : 2009/04/17 99corps
					HTML ='<div class="message">'+obj[0].formattedDate+'은 <br/>생중계가 없습니다.</div>\
					<div class="banner hideText banner'+ bannerNum +'">\
						<ul class="hidden">\
							<li>신한은행 프로리그  매주 월,화 오후 6시 30분 생중계</li>\
							<li>에버 스타리그  매주 금요일 오후 6시 30분 생중계</li>\
							<li>arena MSL  매주 목요일 오후 6시 30분 생중계</li>\
						</ul>\
					</div>'
*/
					$("scheduleContent").className="noList";
					$("scheduleContent").innerHTML=HTML;
				}
				else{				 

					obj.each(
						function(value, index){
																					
							className="";
							if(  index==0 ){
								className="first";	
							}
							if(obj[index].onair){
								className=className+" onair" 
								title= '<a href="/video/live/LivePopup.do?prgmid='+obj[index].programId+'" onclick="window.open(this.href,\'\',\'width=100,height=100\');return false;">'+obj[index].title+'</a>';
							}			
							else{title=obj[index].title;}							

							if( (index+1)==obj.length){
								className=className+ " last";	
							}						

							
							HTML='<li class="'+className+'">\
									<div class="time">'+obj[index].time+'</div>\
									<div class="gameTitle" title="'+obj[index].title+'">'+title+'</div>';
							if(obj[index].isTeam == "1" ){ 
								HTML=HTML+'	<div class="detailInfo">\
												<dl>\
												<dd><a href="'+ (obj[index].teamUrl1 || '#noHome')+'" title="'+obj[index].teamName1+'"><img alt="'+obj[index].teamName1+'" src="'+obj[index].teamLogo1.replace('142.gif','59.gif')+'" width="59" height="36"/></a></dd>\
												<dt><a href="'+ (obj[index].teamUrl1 || '#noHome')+'" title="'+obj[index].teamName1+'">'+obj[index].teamName1+'</a></dt>\
												</dl>\
												<dl class="right" >\
												<dd><a href="'+(obj[index].teamUrl2 || '#noHome')+'" title="'+obj[index].teamName2+'"><img alt="'+obj[index].teamName2+'" src="'+obj[index].teamLogo2.replace('142.gif','59.gif')+'" width="59" height="36"/></a></dd>\
												<dt><a href="'+(obj[index].teamUrl2 || '#noHome')+'" title="'+obj[index].teamName2+'">'+obj[index].teamName2+'</a></dt>\
												</dl>\
											</div>';
							} 
							HTML=HTML+'</li>';
							HTMLArray.push(HTML);
						}
					);
					//HTML = '<ul class="list_">'+HTMLArray.join('')+
					//		'<p class="hideText">\
					//			스타리그 생중계는 <strong>Daum스포츠</strong>에서 보실 수 있습니다.\
					//			<a target="_blank" class="goStarleagueBtn" href="http://sports.media.daum.net/general/center/e_starleague_live/index.html">스타리그</a>\
					//			<a target="_blank" class="goProleagueBtn" href="http://sports.media.daum.net/general/center/e_proleague_live/index.html">프로리그</a>\
					//		</p>';
					
					HTML ='<ul class="list_">'+HTMLArray.join('')+'</ul><a href="/video/live/PotplayerSpecFile.do?lu=ld_ppdownload_4" class="hideText btnDownloadPotPlayer">팟플레이어 다운로드 </a>';
					
					$("scheduleContent").className="contents";
					$("scheduleContent").innerHTML=HTML;
 
				}	
	
} 
// SLGameSchedule(SL Top.do only) GameSchedule 
var SLGameSchedule = Class.create(); 
SLGameSchedule.prototype = new GameSchedule({"url":"/game/json/CastScheduleJSON.do"});
//SLGameSchedule.prototype = new GameSchedule({"url":"/game/Json4SLTest.htm"});

SLGameSchedule.prototype.callback = function(obj){
				var HTML;
				var HTMLArray1= new Array();
				var className;
				var HTMLBtn = "";
				var btnShowTable = "";
				var games;
				var description;

				$("scheduleDate").innerHTML=obj[0].formattedDate;
				if(obj[0].noData==true){
					HTML ='<dl class="noData"><dt>등록된 일정이 없습니다.</dt></dl>'
					$("SLScheduleWrapper").innerHTML=HTML;
					return ;
				}
				else{		
						

					obj.each(
						function(value, index){
							var HTMLArray2= new Array();
							if(obj[index].tableUrl.trim() !="") {
								btnShowTable = '<a href="'+obj[index].tableUrl+'" class="hideText btnSeeTable">대진표 보기</a>';
							}
							else{btnShowTable="";}
							if(obj[index].status=="broadcasted"){
								//지난 방송 - 대진표 / 승패보기
								className="broadcasted";
								HTMLBtn=btnShowTable;
								if(obj[index].isWinner){HTMLBtn=HTMLBtn+'<a onclick="showSLResult('+index+');return false;" href="#" class="hideText btnSee">승패보기</a>';}
							}
							else if(obj[index].status=="onair"){
								//현재 방송중 - 대진표/생방송 보기
								className="onair";
								HTMLBtn=btnShowTable+'<a href="" class="hideText btnSee">방송보기</a>';
							}
							else {
								//방송 예정 - 대진표 
								className="";
								HTMLBtn=btnShowTable;
							}
							description= obj[index].description || '<a href="'+(obj[index].teamUrl1 || '#none')+'"  class="player playerLeft">'+obj[index].teamName1+'</a>\
												<span class="vs hideText" ><span class="winner winner'+obj[index].winner+'"></span></span>\
												<a  href="'+(obj[index].teamUrl2 || '#none')+'"  class="player playerRight">'+obj[index].teamName2+'</a>';

							HTMLArray2.push('<dl id="SLScheduleList_'+index+'" class="'+className+'">\
									<dt><div class="date">'+obj[index].formattedDate+'</div><div class="time">'+obj[index].time+'</div></dt>\
										<dd class="leagueName">\
											<div class="leagueInfo">\
												<div class="title">'+obj[index].leagueName+'</div>\
												<div class="team">'+description+'</div>\
												<div class="btn">'+HTMLBtn+'</div>\
											</div>\
											<ul>');
									games = obj[index].games;
									games.each(function(value, index_){
									var playerLeft= new Array();
									var playerRight= new Array();
									var game=games[index_];
									var raceClass;
									var btn;
	
									if(  obj[index].status=="broadcasted" ){
										if( game.linkUrl.trim() !=""){
											btn='<a href="#" onclick="showClipOption(event, {linkUrl:\''+(game.linkUrl||'')+' \',linkUrlHigh: \''+(game.linkUrlHigh||'')+' \' } );return false;" class="hideText btnSee " rel="replaybutton" title="다시보기">다시보기</a>';
										}
										else if(game.status =="R"){
											btn='<a href="#"  title="준비중입니다." onclick="showMsgBox({msg:this.title, wrapperObj:$(\'SLSchedule\'), top:100,left:160});return false;" class="hideText btnSee " rel="replaybutton" title="다시보기">다시보기</a>';
										}
										else {
											btn='<a href="#"  title="해당 경기는 진행되지 않았습니다." onclick="showMsgBox({msg:this.title, wrapperObj:$(\'SLSchedule\'), top:100,left:160});return false;" class="hideText btnSee " rel="replaybutton" title="다시보기">다시보기</a>';
										}		
																	
									}
									else{
										btn='<a class="hideText btnSee btnSeeDisabled">다시보기</a>'
									}
									game.playerLeft.each(function(value, index){
										if(game.playerLeft[index].race=="3"){raceClass="p"}
										else if(game.playerLeft[index].race=="2"){raceClass="z"}
										else {raceClass="t"}
										playerLeft.push('<a class="'+raceClass+'" href="'+(game.playerLeft[index].linkUrl || '#none')+'"  title="'+game.playerLeft[index].name+'">'+game.playerLeft[index].name+'</a>');
									})
									game.playerRight.each(function(value, index){
										if(game.playerRight[index].race=="3"){raceClass="p"}
										else if(game.playerRight[index].race=="2"){raceClass="z"}
										else {raceClass="t"}
										playerRight.push('<a class="'+raceClass+'"  href="'+(game.playerRight[index].linkUrl || '#none')+'"  title="'+game.playerRight[index].name+'">'+game.playerRight[index].name+'</a>');
									})			
								
									HTMLArray2.push('<li>\
													<div class="title">'+game.map+'</div>\
													<div class="team winner'+game.winner+'">\
														'+ (game.description || '<span class="player playerLeft ">'+playerLeft.join('')+'</span>\
														<span class="vs hideText" ><span class="winner winner'+game.winner+'"></span></span>\
														<span class="player playerRight ">'+playerRight.join('')+'</span>')+'\
													</div>\
													<div class="btn">'+btn+'</div>\
												</li>');	
									});
	
							HTMLArray2.push('</ul>\
										</dd>\
									</dl>');
							HTMLArray1.push(HTMLArray2.join(""));
						}
					);
					$("SLScheduleWrapper").innerHTML=HTMLArray1.join("");
				
					}
}

/******************** SLGameSchedule < GameSchedule  *****************************/



var showSLResult=function(index){$('SLScheduleList_'+index).addClassName("showWinner");}
var SLChangeTab=function(tab){ 
	 $("mainFeatTabWrapper").className="mainFeatTabWrapper mainFeatTabWrapper_"+tab; 
}  

var SpecialChannel = Class.create(); 
SpecialChannel.prototype={
visibleListCnt:2,
selectedIndex:1,
list:null,
initialize: function(){
	$("btnPrevSChannel").onclick=function(){this.show(-1);}.bind(this);
	$("btnNextSChannel").onclick=function(){this.show(1);}.bind(this);
	this.list =$$("#SChannelListWrapper li");
	this.selectedIndex=1;
},			
show:function(direction){
	var  first,last;
	var arr= new Array();
 	this.list.invoke('addClassName','hidden');
	if(direction==1){
			//this.selectedIndex = (this.selectedIndex + this.visibleListCnt)  % this.list.length;
			first = this.selectedIndex + 1
			if(first > (this.list.length -1) ){
				first = first - (this.list.length);
			}
			last  = first+1;
			if(last > ( this.list.length -1) ){
				last = last - (this.list.length);
			}			
			this.selectedIndex=last;

	}
	else{
			//this.selectedIndex= (this.list.length + (this.selectedIndex - this.visibleListCnt)) % this.list.length ;
			first = this.selectedIndex - 1
			if(first < 0 ){
				first = this.list.length -1;
			}
			last  = first-1;
			if(last <  0 ){
				last = this.list.length -1;
			}	
			this.selectedIndex=last;
				
	}
	arr.push(first);
	arr.push(last);
	arr.each(function(value, index){
		this.list[value].className="";
	}.bind(this));

}
}
/*********** 달력 *********************/
var SLCalendar = Class.create(); 
//SLCalendar.prototype = new GameAjax({"url":"/game/Json4Calendar.htm"});
SLCalendar.prototype = new GameAjax({"url":"/game/json/Json4Calendar.do"});
SLCalendar.prototype.initialize = function(){
	// SLGameScheduleInst가 가지고 있는 날짜로 정보요청 .
	$("btnShowCalendar").onclick=function(){SLCalendarInst.getDataByDate( SLCalendarInst.setFormattedDate(SLGameScheduleInst.selectedDate).substr(0,6) || SLCalendarInst.setFormattedDate(SLCalendarInst.selectedDate).substr(0,6)); return false;}
	new Insertion.After($("btnShowCalendar"),  '<div class="calendar" style="display:none;" id="SLCalendar"></div>');	
	GameAjax.prototype.initialize.apply(this);
}

SLCalendar.prototype.callback = function(obj){
		var HTMLArray = new Array();
		var selected, unit;
		var HTML =		'<span class="title"><a class="btnShow hideText" id="btnShowPrevMonth">이전달</a><div>'+obj[0].year+'년  '+obj[0].month+'월</div><a  id="btnShowNextMonth"  class="btnShow hideText" >다음달</a><a  onclick="$(\'SLCalendar\').hide();" id="btnCloseCal"  class="hideText" >닫기</a></span>\
						<span class="dateElement sun">일</span>\
						<span class="dateElement">월</span>\
						<span class="dateElement">화</span>\
						<span class="dateElement">수</span>\
						<span class="dateElement">목</span>\
						<span class="dateElement">금</span>\
						<span class="dateElement sat">토</span>';
		$R(1,(obj[0].daynum -1)).each(function(value,index){HTMLArray.push('<span class="dateElement"></span>');}) //앞쪽 공백 출력
		obj.each(
			function(value,index){
				selected="";
				this.next=obj[0].next;
				this.prev=obj[0].prev;
				if( SLCalendarInst.setFormattedDate(SLGameScheduleInst.selectedDate) ==obj[index].formattedDate){selected=" selected ";}
				if(!obj[index].schedule){  
					unit='<span class="dateElement noSchedule '+selected+'">'+obj[index].date+'</span>';
				}
				else{
					//if(obj[index].description.trim() !=""){title+="["+obj[index].description+"]"}
					unit='<a href="#" title="등록된 경기일정이  '+obj[index].schedule+'건 있습니다."  onclick="SLGameScheduleInst.getDataByDate('+obj[index].formattedDate+');$(\'SLCalendar\').hide();return false;" class="dateElement'+selected+'">'+obj[index].date+'</a>'
				}
				HTMLArray.push(unit);
			}.bind(this)
		);
		$("SLCalendar").innerHTML=HTML+HTMLArray.join("");
		$("btnShowPrevMonth").onclick=function(){this.getDataByDate(this.prev)}.bind(this);
		$("btnShowNextMonth").onclick=function(){this.getDataByDate(this.next)}.bind(this);
		$("SLCalendar").show();
}

/*  
 * @title: 대진표 및 리그리스트 등의 다시보기 버튼의 레이어 박스
 */
var matchResult = {
	// 대진표의 선수 표시
	showPlayer : function() {
		var tempArray = $$(".gamer");
		for(var i=0; i<tempArray.length; i++){
			if(tempArray[i].parentNode.tagName == "DL" && tempArray[i].parentNode){	
				var dtObjTemp = tempArray[i].previous("dt");
				var ddObjTemp = tempArray[i].up("DL").getElementsBySelector("dd:last-child")[0];
				if(dtObjTemp.className == "winner" && tempArray[i].up("td").getAttribute("id") == "match2Wrap") {
					tempArray[i].up("dl").toggleClassName("noLine");
					tempArray[i].next(".deco").down("em").toggleClassName("show");
				}
				if (dtObjTemp.className == "loser" && tempArray[i].up("td").getAttribute("id") == "match2Wrap") {
					tempArray[i].up("dl").toggleClassName("blur");
					tempArray[i].up("dl").toggleClassName("noLine");	
				}
				ddObjTemp.toggleClassName("temp1");
				ddObjTemp.toggleClassName("temp2");
										
			} else if(tempArray[i].parentNode.tagName == "UL" && tempArray[i].parentNode) {
				var liObj = tempArray[i].parentNode.getElementsByTagName("LI")[0];
				if (liObj.className == "winner") {
					tempArray[i].toggleClassName("win");
				}				
			}
		}
		matchResult.showWin();
	},
	// 대진표의 승,패 표시, 비표시
	showWin : function() {
		var winObj = $$(".winner");
		var loseObj = $$(".loser");
		var drawObj = $$(".draw");

		if(winObj.length == 0 && loseObj.length == 0 && drawObj.length == 0) {
			alert("현재 완료된 경기가 없습니다.");
		}
		
		if(winObj.length != 0) {
			for(var i=0; i < winObj.length; i++){
				var spanObj = $(winObj[i]).down("span");			
				if(spanObj.className == "") {
					domHelper.cssjs("add", spanObj, "off");
				} else {
					domHelper.cssjs("remove", spanObj, "off");
				}			
			}
		}
		
		if(loseObj.length != 0) {
			for(var i=0; i < loseObj.length; i++){
				var spanObj = loseObj[i].down("span");
				if(spanObj.className == "") {
					domHelper.cssjs("add", spanObj, "off");
				} else {
					domHelper.cssjs("remove", spanObj, "off");
				}			
			}
		}
		
		if(drawObj.length != 0) {
			for(var i=0; i < drawObj.length; i++){
				var spanObj = drawObj[i].down("span");
				if(spanObj.className == "") {
					domHelper.cssjs("add", spanObj, "off");
				} else {
					domHelper.cssjs("remove", spanObj, "off");
				}			
			}
		}
	}
}

/*  
 * @title: 스타리그 홈, 투표하기, 투표결과보기 페이지의 투표후의 메세지 처리
 * @desc: voteid, status를 마크업에서 넘겨줘야 함
 */
var voteInfor = {
	dlObj : "",
	url : "",
	clipid : "",
	chkFlg : false,
	msgTxt : "",
	votedClip : "",
	rtnMsg : "",
	status : "",
	init : function(voteid, status) {
		voteInfor.url = "/game/json/VoteCntUpXml.do?scVoteId=" + voteid + "&votedclip=";
		voteInfor.status = status;
		if(voteInfor.status == "C") {
			voteInfor.showAlert();
			return false;
		}	
		var rdObj = document.getElementsByName("votedclip");
		for(i=0; i<rdObj.length; i++) {
			if(rdObj[i].checked) {
				voteInfor.votedClip = rdObj[i].value;
				voteInfor.dlObj = rdObj[i]; 
				voteInfor.chkFlg = true;
				voteInfor.importFeedData();
			}
		}
		if(!voteInfor.chkFlg){
			voteInfor.showAlert();
			return false;
		}
		return false;
	},
	importFeedData : function() {
		var sendUrl = voteInfor.url + voteInfor.votedClip;
		if (voteInfor.rtnMsg == "no") {
			voteInfor.showAlert();
			return false;
		}
		getAjaxData(sendUrl, '', voteInfor.importData);
	},
	importData : function(orgRequest, pars) {
		var xmlData = orgRequest.responseXML;
		try {
			voteInfor.rtnMsg = xmlData.getElementsByTagName("result").item(0).firstChild.data
		}catch(e){ }
		voteInfor.showAlert();
	},
	showAlert : function() {
		if(!voteInfor.chkFlg){
			voteInfor.msgTxt = "투표하실 동영상을 선택하지 않으셨습니다."	;
		} else {
			if (voteInfor.rtnMsg == "no") {
				voteInfor.msgTxt = "이미 투표에 참여하셨습니다.";
			} else {
				if($("voteGrapgh")){
					voteInfor.addVoteCount();	
				}
				voteInfor.msgTxt = "투표하셨습니다.";		
			}
		}
		if (voteInfor.status == "C") {
			voteInfor.msgTxt = "투표기간이 종료되었습니다.";
		}
		var recommDiv = document.createElement("div");
		recommDiv.setAttribute("id", "sendResult");
		var recommTxt = document.createTextNode(voteInfor.msgTxt);
		recommDiv.appendChild(recommTxt);
		$("viewVoteBox").appendChild(recommDiv);
		var tem= setTimeout(voteInfor.hideAlert ,1500);
	},
	hideAlert : function() {
		$("viewVoteBox").removeChild($("sendResult"));
	},
	addVoteCount : function() {
		var ddItems = voteInfor.dlObj.parentNode.parentNode.getElementsByTagName("DD");
		var ddObj = ddItems[ddItems.length - 1];
		var countVal = parseInt($(ddObj).firstDescendant().innerHTML);
		var voteResultVal = parseInt($(ddObj).firstDescendant().innerHTML) + 1; 					
		var totalWidth = 498;
		$(ddObj).firstDescendant().innerHTML = voteResultVal; 
		
		var curBarWidth = $("voteGrapgh").down(2);
		var totalVoteCnt = parseInt($$(".votenum1")[0].firstDescendant().innerHTML) + parseInt($$(".votenum2")[0].firstDescendant().innerHTML);  
		var barWidth = Math.floor((totalWidth * parseInt($(ddObj).firstDescendant().innerHTML)) / totalVoteCnt);
	
		if (voteInfor.votedClip == 1) { 		
			curBarWidth.style.width = barWidth + "px";
		} else {
			curBarWidth.style.width = (totalWidth - barWidth) + "px";
		}			
	}
};

var gameList ={
	toggle :function(){ 
			if(this.isOpened){$('gamesWrapper').removeClassName('showAll');this.isOpened=false;}
			else{$('gamesWrapper').addClassName('showAll');this.isOpened=true;}	
	},
	selectedIndex:0,
	isOpened: false,
	indexMenuList: null,
	games:null,
	addBtnFlag : function (num)
	{
		if(this.games.length <=0){return;}	
		if(this.games[num].getElementsBySelector("li").length<9)
		{
			$("btnShowmore").style.display="none";
		}else{
			$("btnShowmore").style.display="block";
		}
	},
	show: function(index){
			
			if(index !=this.selectedIndex || index==null){
				if(index==null)
					index=0;
				this.games[index].show();
				this.indexMenuList[index].addClassName("selected");
				this.indexMenuList[this.selectedIndex].removeClassName("selected");
				this.games[this.selectedIndex].hide();
				this.selectedIndex=index;
				this.addBtnFlag(index);
			}
	},
	init : function ()
	{
		this.games=$$(".games");
		this.indexMenuList=$$(".indexMenuList");
		this.addBtnFlag(0);
	}
	
}


var showClipOption =function(evt,params ){
				var e 		= evt || window.event;
				var linkUrl = params.linkUrl || "";  
				var linkUrlHigh = params.linkUrlHigh || "";
				if(params.clipid){linkUrl = "/clip/ClipView.do?clipid="+params.clipid || "";}
				if(params.instid){linkUrlHigh = "/video/live/LivePopup.do?instid="+params.instid || "";}
				if(e.pageX){
					var top 	= e.pageY - 7;
					var left 	= e.pageX  -20;
				}
				else{
					var top		= parseInt(document.documentElement.scrollTop) + parseInt(e.clientY) - 7; 
					var	left	= parseInt(document.documentElement.scrollLeft) + parseInt(e.clientX)  -20;
				}
 
				var HTML ='<div id="clipOption" style="position:absolute;top:'+top+'px;left:'+left+'px">';
					HTML +='<span  class="btnWrap" style="display:block;">';
					if(linkUrl.trim()!=""){ HTML +='<a  href="'+linkUrl+'" id="directBtn" class="direct" value="바로보기">바로보기</a>';}
					else{ HTML +='<a id="directBtn" class="direct" style="color:#ccc;" value="바로보기">바로보기</a>';}
					if(linkUrlHigh.trim()!=""){ HTML +='<a href="'+linkUrlHigh+'" onclick="window.open(this.href,\'\',\'width=100,height=100\');return false;" id="highBtn" class="high" value="고화질보기">고화질보기</a>';}
					else{ HTML +='<a id="highBtn" class="high"  style="color:#ccc;"  value="고화질보기">고화질보기</a>';}
				HTML +='</span></div>';	
				e.stopPropagation? e.stopPropagation():e.cancelBubble = true; 
				if($("clipOption")){
					$("clipOption").replace(HTML); 		
				}
				else{
					new Insertion.After($("wrap"),  HTML); 
					$("wrap").observe('click',function(){$("clipOption").hide()})
				}	
}	
var showMsgBox = function(){
					if(!$("msgBox")){
						var params = arguments[0] || "";
						var interval = params.interval || 1500;
						var HTML ='<div id="msgBox">'+(params.msg || '오류가 발생했습니다.')+'</div>';
						var top_=params.top || (parseInt(document.documentElement.scrollTop) +230);
						var left_=params.left || (document.body.clientWidth / 2 - (300/2)); 
						if(params.wrapperObj){
							$(params.wrapperObj).setStyle({position:'relative'}).insert(HTML);
						}else{
							new Insertion.After($("wrap"),  HTML);
						}
						$("msgBox").setStyle({top: top_+ 'px',left: left_+ 'px'});
						setTimeout("if($('msgBox')){$('msgBox').remove()}",interval);
					}
 
}


var Rolling = Class.create();
Rolling.prototype={
visibleListCnt:0,
totalSetCnt:0,
selectedSetIndex:0,
direction:1,
list:null,
initialize: function(){
	if(arguments[0]){
		this.visibleListCnt = arguments[0].visibleListCnt || this.visibleListCnt;
		this.selectedSetIndex	= arguments[0].selectedSetIndex || this.selectedSetIndex;
		this.direction	= arguments[0].direction || this.direction;
		this.list	= arguments[0].list || this.list;
	}
	else{ return false;}

	this.totalSetCnt = parseInt(((this.list.length -1)  / this.visibleListCnt)+1);
},			
show:function(){
	var direction = arguments[0] || this.direction;
	this.selectedSetIndex = (this.selectedSetIndex  + this.totalSetCnt  + direction) % this.totalSetCnt
	var first	= this.selectedSetIndex * this.visibleListCnt;
	var last	= first +  this.visibleListCnt  ;
	this.list.each(function(value,index){
		
			if(index >= first && index < last){
				if(value) value.show();
			}
			else{ 
				if(value) value.hide();
			}
	}.bind(this));	
}
}

var GameRanking = Class.create();
Object.extend(GameRanking.prototype,Rolling.prototype);	
GameRanking.prototype.initialize =  function(){
		$("btnPrevRanking").onclick=function(){this.show(-1);}.bind(this);
		$("btnNextRanking").onclick=function(){this.show(1);}.bind(this);
		Rolling.prototype.initialize.apply(this,arguments );
		setInterval(this.show.bind(this) ,5000) ;	
}
var RollingLiveList = Class.create();
Object.extend(RollingLiveList.prototype,Rolling.prototype);	
RollingLiveList.prototype.initialize =  function(){
		var btn ='<button id="btnPrevLiveList" class="btnRolling btnShowPrev" type="button"><span class="hidden">이전</span></button>\
				  <button id="btnNextLiveList"  class="btnRolling btnShowNext"  type="button"><span class="hidden">다음</span></button>'			
		new Insertion.After($("liveListTitle"), btn);	
		$("btnPrevLiveList").onclick=function(){this.show(-1);}.bind(this);
		$("btnNextLiveList").onclick=function(){this.show(1);}.bind(this);
		Rolling.prototype.initialize.apply(this,arguments );
}




var GameDir = Class.create();
GameDir.prototype ={
initialize:function(){
	this.dirMenu=$$("#dirMenu li");
	this.dirGameList=$$("#dirGameList ul");
},
selectedIndex:0,
isOpened: false,
indexMenuList: null,
games:null,
dirMenu:null,
dirGameList:null,
show: function(index){
		if(this.selectedIndex != index){
			this.dirMenu[this.selectedIndex].style.fontWeight='normal';
			this.dirMenu[index].style.fontWeight='bold'
			this.dirGameList[this.selectedIndex].hide();
			this.dirGameList[index].show();
			this.selectedIndex=index;
		}
}
}

// 다음게임노출연동 09.09.18 by romanyrye
var PlayGame = {
	channel:"",
	gameNums:[],
	focus:0,
	init: function(){
		this.channel = "rpg";
		this.gameNums["rpg"] = $$(".playGame ul.rpg li").length;
		this.gameNums["action"] = $$(".playGame ul.action li").length;
		this.gameNums["board"] = $$(".playGame ul.board li").length;
		this.gameNums["casual"] = $$(".playGame ul.casual li").length;
		this.gameNums["flash"] = $$(".playGame ul.flash li").length;
		this.gameNums["pack"] = $$(".playGame ul.pack li").length;
		this.focus = 0;
		this.changeButtons();

		$$("dt.channel a").each(function(obj){
			obj.observe("click", function(e){
				for(var i=0; i < this.gameNums[this.channel]; ++i){
					if(i < 4){
						$$(".playGame ul."+this.channel+" li")[i].show();
					}else{
						$$(".playGame ul."+this.channel+" li")[i].hide();
					}
				}
				$$("dt."+this.channel)[0].addClassName("hiddenChannel");
				$$("dd."+this.channel)[0].setStyle({"visibility":"hidden"});
				this.channel = this.findChannel(obj.up(0));
				$$("dt."+this.channel)[0].removeClassName("hiddenChannel");
				$$("dd."+this.channel)[0].setStyle({"visibility":"visible"});
				this.focus = 0;
				this.changeButtons();
				e.stop();
			}.bind(this));
		}.bind(this));
		
		$$(".playGame .btnPrev")[0].observe("click", function(e){
			if(!$$(".playGame .btnPrev")[0].hasClassName("prevDisable")){
				$$(".playGame ul."+this.channel+" li")[this.focus-1].show();
				$$(".playGame ul."+this.channel+" li")[this.focus+3].hide();
				--this.focus;
				this.changeButtons();
			}
			e.stop();
		}.bind(this));
		
		$$(".playGame .btnNext")[0].observe("click", function(e){
			if(!$$(".playGame .btnNext")[0].hasClassName("nextDisable")){
				$$(".playGame ul."+this.channel+" li")[this.focus].hide();
				$$(".playGame ul."+this.channel+" li")[this.focus+4].show();
				++this.focus;
				this.changeButtons();
			}
			e.stop();
		}.bind(this));
	},
	changeButtons: function(){
		if(this.focus == 0){
			$$(".playGame .btnPrev")[0].addClassName("prevDisable");
		}else{
			$$(".playGame .btnPrev")[0].removeClassName("prevDisable");
		}
		if(this.focus == this.gameNums[this.channel] - 4){
			$$(".playGame .btnNext")[0].addClassName("nextDisable");
		}else{
			$$(".playGame .btnNext")[0].removeClassName("nextDisable");
		}
	},
	findChannel: function(target){
		if(target.hasClassName("rpg")){
			return "rpg";
		}else if(target.hasClassName("action")){
			return "action";
		}else if(target.hasClassName("board")){
			return "board";
		}else if(target.hasClassName("casual")){
			return "casual";
		}else if(target.hasClassName("flash")){
			return "flash";
		}else if(target.hasClassName("pack")){
			return "pack";
		}
	}
}