//롤링배너
function rollFlashBanner(myurl, mywidth, myheight, isscroll, logid) {
	//alert("mywidth="+mywidth+"- myheight="+myheight+"- isscroll="+isscroll+"- myurl="+myurl);
	if (logid) try{_trk_clickTrace("EVT", logid);}catch(_e){};
	if(mywidth == "0" && myheight == "0") {
		if(isscroll == "0" ) {
			document.location.href= myurl;
		} else {
			window.open(myurl,"_blank");
		}
	} else {
		open_popup(myurl,mywidth,myheight,isscroll,"rollFlashBanner" );
	}
}

//메뉴Notice
function menuNotice(myurl,mywidth,myheight,isscroll) {
	if(mywidth == "0" && myheight == "0") {
		if(isscroll == "0" ) {
			document.location.href= myurl;
		} else {
			window.open(myurl,"_blank");
		}
	} else {
		open_popup(myurl,mywidth,myheight,isscroll,"menuNotice" );
	}
}

//Flash Banner Link
function open_popup(url, wid, hei, scroll, winName)
{
	var url = url;
	var posi = "width="+ wid +",height="+hei+",toolbar=no,location=no,status=no,menubar=no,top=10,left=50,scrollbars=" + scroll +",resizable=no" ;
	if (winName == "")
	{
		winName = popup;
	}
	window.open(url,winName,posi);
}

//롤링컨텐츠
var RollingDisplay = function(cid,count,interval,n) {
	this.cid = cid;
	this.count = count;
	if(n == "random")this.n = Math.floor(Math.random() * (this.count) + 1);
	else this.n = (n)? n:"1";
	this.onchange = null;

	for(var k=1; k<=this.count; k++) document.getElementById(this.cid+"_"+k).style.display="none";
	document.getElementById(this.cid+"_"+this.n).style.display="block";

	this.div = document.getElementById(this.cid);
	this.div.onmouseover = function(){this.isover=true; }
	this.div.onmouseout  = function(){this.isover=false;}
	this.btn_next = document.getElementById("btn_"+this.cid+"_next");
	this.btn_prev = document.getElementById("btn_"+this.cid+"_prev");
	
	if(document.getElementById(this.cid + "_current")){
		this.currentPageDiv = document.getElementById(this.cid + "_current");	
		this.currentPageDiv.innerHTML = "<strong id='"+ this.cid +"_count'>"+this.n+"</strong> /&nbsp;" + count;	
		this.currentPage = document.getElementById(this.cid + "_count");
	}

	var self=this;
	if(this.btn_next) this.btn_next.onclick=function(){self.next() }
	if(this.btn_prev) this.btn_prev.onclick=function(){self.prev() }
	//if(interval > 0) setInterval(function(){self.play()}, interval);
}
RollingDisplay.prototype = {
	play : function(){
		if(this.div.isover) return;
		this.next();
	},	
	prev : function(){
		document.getElementById(this.cid+"_"+this.n).style.display="none";
		this.n=(this.n==1)?this.count:--this.n;
		document.getElementById(this.cid+"_"+this.n).style.display="block";	
		if(document.getElementById(this.cid + "_current")){this.currentPage.innerText = this.n;}
	},
	next : function(){		
		document.getElementById(this.cid+"_"+this.n).style.display="none";
		this.n=(this.n==this.count)? 1:++this.n;
		document.getElementById(this.cid+"_"+this.n).style.display="block";
		if(document.getElementById(this.cid + "_current")){this.currentPage.innerText = this.n;}
	}
};

/* 오늘의 한마디 */ 
var talkRolling = function(junction, rollingHeight) {
	this.currentPage = 0;
	this.eff = 0;
	this.isRolling = true;
	this.load = function() {
		var that = this;
		this.banners = $(junction).select('li');
		$(junction).setStyle({'height' : this.banners.length * rollingHeight + 'px'});
		
		for(i=0 ; i<this.banners.length ; i++) {		
			this.banners[i].onmouseover = function(){that.isRolling = false;}
			this.banners[i].onmouseout = function(){that.isRolling = true;}
		}
		if(this.banners.length > 1) {
			setInterval(function(){
				if(that.isRolling === true) that.move(that.currentPage + 1);
			}, 4000);
		}
	};
	this.move = function(selectBanner) {
		if(this.banners.length <= selectBanner) this.currentPage = 0;
		else if(selectBanner < 0) this.currentPage = this.banners.length;
		else this.currentPage = parseInt(selectBanner);

		var banner = $(junction);
		var selectBannerTop = (banner.getStyle('top') === null) ? 0 : parseInt(banner.getStyle('top'));
		for(var i=0; i<this.banners.length; i++) {
			if (i === this.currentPage) {
				if (this.eff) this.eff.cancel();
				this.eff = new Effect.MoveBy(banner, -(rollingHeight * this.currentPage)-selectBannerTop,0, {duration:0.4});
			} else {
			}
		}
	};
};

// recent 탭메뉴
function recentTab(num){
	var tabMenu = $('ranking_navi');
	var tabList = tabMenu.getElementsByTagName('a');
	for (var i=1;i<=tabList.length; i++ )
	{
		if (num==i)
		{
			tabList[i-1].className="on";
			$('recent'+i).style.display="block";
		}
		else{
			tabList[i-1].className="off";
			$('recent'+i).style.display="none";
		}
	}
	currentList=num;
}

var rollStatus = true;
var currentList = 1;
var rollingRecent=function(){
	if (rollStatus!==true) return ;
	var recentNavi = $('ranking_navi');
	var recentNaviList = recentNavi.getElementsByTagName('a');
	for (var i=1; i<=recentNaviList.length ;i++)
	{
		if (currentList==i) {
			recentNaviList[i-1].className="on";
			$('recent'+currentList).style.display="block";
		}
		else {
			recentNaviList[i-1].className="off";
			$('recent'+i).style.display="none";
		}
	}
	currentList++;
	if (currentList>3){currentList=1;}
}

// 마이 러빗 레이어
function viewListLayer(lyrid,el){
	if(lyrid == lyrid) $(lyrid).toggle();
	if(lyrid == 'friendList') {
		$('famList').hide();
	}
	if(lyrid == 'famList') {
		$('friendList').hide();
	}
}

function newsList (){
	var news=$('news_navi');
	var newsList = news.getElementsByTagName('a');
	for (var i=0; i<newsList.length; i++)
	{
		newsList[0].onmouseover=function(){
			newsList[0].className="on";
			newsList[1].className="off";
			$("notice").style.display="block";
			$("update").style.display="none";
		}
		newsList[1].onmouseover=function(){
			newsList[0].className="off";
			newsList[1].className="on";
			$("notice").style.display="none";
			$("update").style.display="block";
		}
	}
}

function loungeList (num){
	var lounge=$('lounge_navi');
	var loungeList = lounge.getElementsByTagName('a');
	for (var i=1; i<=loungeList.length; i++)
	{
		if (num==i){
			loungeList[i-1].className="on";
			$("lounge_list"+i).style.display="block";
		}
		else{
			loungeList[i-1].className="off"
			$("lounge_list"+i).style.display="none";
		}
	}
}

window.onload=function(){
	if($('news_navi')){
		newsList();
	}/* 올 와우 적용 후 롤링 : 09.12.23예정
	if($('wrap_ranking')){
		var timer=setInterval(rollingRecent, 2000);
		Event.observe('wrap_ranking', 'mouseover',function(e) {
			rollStatus=false;
		});
		Event.observe('wrap_ranking', 'mouseout',function(e) {
			rollStatus=true;
		});
	}*/
}

var MainTabRoller = Class.create();
MainTabRoller.prototype = {
	initialize : function(tabIdx, tabSize, tabSelect, interval) {
		this.selectedTab = tabIdx;
		this.tabSize = tabSize;
		this.roller = null;
		this.tabSelect = tabSelect;
		this.interval = interval;
	},
	_startRolling : function() {
		var ctx		= this;
		ctx.roller = setInterval(function() {
				ctx._choiceTab();
			}, ctx.interval);
	},
	_stopRolling : function() {
		var ctx		= this;
		clearInterval(ctx.roller);
	},
	_choiceTab : function(){
		var ctx		= this;
		ctx.tabSelect(ctx.selectedTab);
		if ( ctx.selectedTab == ctx.tabSize ) {
			ctx.selectedTab = 1;
		} else {
			ctx.selectedTab += 1;
		}
	}
}

// notice 메뉴
function newsTab(num){
	var tabMenu = $('news_navi');
	var tabList = tabMenu.getElementsByTagName('a');
	for (var i=1;i<=tabList.length; i++ )
	{
		if (num==i)
		{
			tabList[i-1].className="on";
			$('news'+i).style.display="block";
		}
		else{
			tabList[i-1].className="off";
			$('news'+i).style.display="none";
		}
	}
	currentList=num;
}

// 우측 날개형 배너 - 공통
var random_banner = function(id) {
	this.obj = jQuery('#'+id).children();
	for (var i=0;i<this.obj.length;i++) { if (this.obj[i].className!='on') jQuery(this.obj[i]).remove(); }
	this.obj = jQuery('#'+id).children();
	this.bannerIdx = Math.floor(Math.random()*this.obj.length);
	for (var i=0;i<this.obj.length;i++) { if(i!=this.bannerIdx) jQuery(this.obj[i]).css('display','none'); }
}
jQuery(document).ready(function(){
	if (screen.width<1280 && jQuery('#rwing_banner').css('display')=='block') jQuery('#rwing_banner').children().remove();
});
