/* 파비콘 */
var favicon_allowed_domain = ["lovebeat.plaync.co.kr"];
try {
	for (fvcn_i=0; fvcn_i<favicon_allowed_domain.length; fvcn_i++) {
		if (document.domain.match(favicon_allowed_domain[fvcn_i])) {
			try {
				var favicon1 = document.createElement("link");
				var favicon2 = document.createElement("link");
				favicon1.rel = "shortcut icon";
				favicon1.type = "image/x-icon";
				favicon1.href = "http://static.plaync.co.kr/common/plaync.ico";
				favicon2.rel = "icon";
				favicon2.type = "image/x-icon";
				favicon2.href = "http://static.plaync.co.kr/common/plaync.ico";
				document.getElementsByTagName("head")[0].appendChild(favicon1);
				document.getElementsByTagName("head")[0].appendChild(favicon2);
			}
			catch (e) {
				document.write('<link rel="shortcut icon" href="http://static.plaync.co.kr/common/plaync.ico" type="image/x-icon" /><link rel="icon" href="http://static.plaync.co.kr/common/plaync.ico" type="image/x-icon" />');
			}
		}
	}
}
catch (e) {}


/* 로그인 영역 팝업 */
function openDenyPopup(url, winW, winH, scroll, winName, status, location)
{
	if(status == null)	status = "no";
	if(location == null)	location = "no";

	var setup = "width=" + winW + ",height=" + winH + ",toolbar=no,location="+location+",status="+status+",menubar=no,top=20,left=20,scrollbars=" + scroll +",resizable=no";
	if (!winName) winName = "";
	var win = window.open(url, winName, setup);
	if (win == null) alert("차단된 팝업창을 허용해 주십시오.");
	win.focus();
}

/* 로그인 친구리스트 */
function friendListToggle(current) {
	var imgname = current.src.substring(current.src.lastIndexOf("_")+1, current.src.lastIndexOf("."));
	var divId = document.getElementById("friend_list_stage");
	if(imgname=="hidden"){
		current.src = current.src.replace("hidden", "view");
		divId.style.display = "none";
	} else if(imgname=="view") {
		current.src = current.src.replace("view", "hidden");
		divId.style.display = "block";
	}
}

/* 뮤직리스트 */
function musiclist(selectId) {
	selectId = document.getElementById(selectId);
	toggleImg = selectId.getElementsByTagName("dd")[1].getElementsByTagName("img")[0];
	toggleImg_before = toggleImg.src.substring(0, toggleImg.src.lastIndexOf("_")+1);
	for(i=1 ; i<6 ; i++) {
	try {
		currentId = document.getElementById("musiclist"+i);
		for(z=0 ; z<currentId.childNodes.length ; z++) {
			if(currentId.childNodes[z].className=="wrap_comment") {
				// comment가 현재 보여지고 있을때
				if(currentId==selectId && (currentId.childNodes[z].style.display=="none" || currentId.childNodes[z].style.display=="")) {
					currentId.childNodes[z].style.display = "inline";
					selectId.className += " current";
					toggleImg.src = toggleImg_before + "hide.gif";
				}
				else {
					currentId.childNodes[z].style.display = "none";
					currentId.className = currentId.className.replace(' current','');
					currentId.getElementsByTagName("dd")[1].getElementsByTagName("img")[0].src = toggleImg_before + "view.gif";
				}
			}
		}
	//	alert(commentId.className)
	} catch(e) { break; }
	}
}

// Tab Content
function initTabMenu(tabContainerID) {
	var tabContainer = document.getElementById(tabContainerID);
	var tabList = tabContainer.getElementsByTagName("li");
	var tabAnchor = tabContainer.getElementsByTagName("a");
	var i = 0;

	for(i=0; i<tabList.length; i++) {
		if (tabList.item(i).className == "")
			thismenu = tabList.item(i);
		else
			continue;
		thismenu.container = tabContainer;
		thismenu.targetEl = document.getElementById(tabAnchor.item(i).href.split("#")[1]);
		thismenu.targetEl.style.display = "none";
		thismenu.imgEl = thismenu.getElementsByTagName("img").item(0);
		thismenu.onclick = function tabMenuClick() {
			currentmenu = this.container.current;
			if (currentmenu == this)
				return;

			if (currentmenu) {				
				currentmenu.targetEl.style.display = "none";
				if (currentmenu.imgEl) {
					currentmenu.imgEl.src = currentmenu.imgEl.src.replace("_on.gif", ".gif");
				} else {
					currentmenu.className = currentmenu.className.replace("on", "");
				}
			}
			this.targetEl.style.display = "block";
			if (this.imgEl) {
				this.imgEl.src = this.imgEl.src.replace(".gif", "_on.gif");
			} else {
				this.className += "on";
			}
			this.container.current = this;
			return false;
		};
		if (!thismenu.container.first)
			thismenu.container.first = thismenu;
	}
	if (tabContainer.first)
		tabContainer.first.onclick();
}

// 공감/댓글 영역 탭메뉴 
function initTabMenuForBBS(tabContainerID, targetEl) {
	var tabContainer = document.getElementById(tabContainerID);
	var tabList = tabContainer.getElementsByTagName("li");
	var tabAnchor = tabContainer.getElementsByTagName("a");	
	var i = 0;
	var targetMenu = null;
	
	for(i=0; i<tabList.length; i++) {
		if (tabList.item(i).className == "") {
			thismenu = tabList.item(i);
		} else {
			continue;
		}
			
		thismenu.container = tabContainer;
		
		// dev
		var targetElId = tabAnchor.item(i).href.split("#")[1];		
		if (targetElId == targetEl) {	
			targetMenu = thismenu;
		} 
				
		// dev : 공감리스트 호출		
		if ('scrap' == targetEl) {
			getBookmarkUserList();
		}
		
		thismenu.targetEl = document.getElementById(targetElId);		
		thismenu.targetEl.style.display = "none";
		thismenu.imgEl = thismenu.getElementsByTagName("img").item(0);	
			
		thismenu.onclick = function tabMenuClick() {
			currentmenu = this.container.current;			
			if (currentmenu == this)
				return;

			if (currentmenu) {						
				// dev : 공감리스트 호출	
				if ((null != currentmenu.targetEl) && ('comment' == currentmenu.targetEl.className)) {
					getBookmarkUserList();
				}
				
				// dev : 코멘트리스트 호출시 scrap parameter제거.  2009.09.25
				if ((null != currentmenu.targetEl) && ('scrap' == currentmenu.targetEl.className)) {
					var params = location.search.replace('&targetTab=scrap','');
					location.href = location.pathname + params;
					return;
				}
				
				currentmenu.targetEl.style.display = "none";									
				if (currentmenu.imgEl) {
					currentmenu.imgEl.src = currentmenu.imgEl.src.replace("_on.gif", ".gif");
				} else {
					currentmenu.className = currentmenu.className.replace("on", "");
				}
			}
			this.targetEl.style.display = "block";
			if (this.imgEl) {
				this.imgEl.src = this.imgEl.src.replace(".gif", "_on.gif");
			} else {
				this.className += "on";
			}
			this.container.current = this;
			return false;
		};
		if (!thismenu.container.first) {
			thismenu.container.first = targetMenu;
		}
	}
	if (tabContainer.first) {
		tabContainer.first.onclick();
	}
}

// 메세지 view
function viewOn(id) {
	document.getElementById(id).style.display='block';
}
function viewOff(id) {
	document.getElementById(id).style.display='none';
	//callFlash(false);
}

//toggleLayer
function toggleLayer(targetId){
	var targetLayer = document.getElementById(targetId);
	targetLayer.style.display = (targetLayer.style.display == "block") ? "none" : "block";
}
function toggleImg(targetId){
	var targetImg = document.getElementById(targetId);
	var src = targetImg.src;
	src = (src.indexOf("_on.gif") > -1) ?
	src.replace(/_on.gif/,'.gif') : src.replace(/.gif/,'_on.gif');
	targetImg.setAttribute("src",src);
}

/* GM 스타일 대결 : Cube 아이템 초기화 */
function initItemCube(targetCubeID, itemsTag) {    
    var cube = document.getElementById(targetCubeID);
	var items = cube.getElementsByTagName(itemsTag);

    for(i = 1 ; i <= items.length ; i++){    	
	    if (null != document.getElementById('itemId_'+targetCubeID+'_'+i)) {
    	    var itemId = document.getElementById('itemId_'+targetCubeID+'_'+i).value;        
	        var thumbnailPath = document.getElementById('thumbnailPath_'+targetCubeID+'_'+i).value;       
	        var innerTag = "<a href='/style/itemlist/itemview?itemId=[itemId]' onclick='openDenyPopup(this, 450, 580); return false;'><img src='[thumbnailPath]'/></a>";
	        if (null != itemId && null != thumbnailPath) {
	            innerTag = innerTag.replace('[itemId]', itemId).replace('[thumbnailPath]', thumbnailPath);
	        }
	        items[i-1].innerHTML = innerTag;
        }
    }
}

/* GM 스타일 대결 : Cube 아이템 - Tooltip */
function cubeTooltip(targetCubeID,itemsTag){
	if(!document.getElementById(targetCubeID)) return false;
	var cube = document.getElementById(targetCubeID);
	var items = cube.getElementsByTagName(itemsTag);
	var tooltip = document.getElementById("tooltip_"+targetCubeID);

	for(i = 0 ; i < items.length ; i++){
		items[i].onmouseover = function(){
			// item 등록하지 않은 경우
			if (null == document.getElementById('tall_beat_'+targetCubeID+'_'+this.id)) {
				tooltip.style.display = "none";
			} 
			// item 등록한 경우
			else {
				var curX = this.offsetLeft;
				var curY = this.offsetTop;
				var curH = this.offsetHeight;
				tooltip.style.display = "block";
				tooltip.style.left = curX + "px";
				tooltip.style.top = (curY + 55 ) + "px";
	
				//dev
				var tall_beat_eng="tall";
				var tall_beat_kor="톨";
				if(document.getElementById('tall_beat_'+targetCubeID+'_'+this.id).value == 2){
					tall_beat_eng = "beat";
					tall_beat_kor = "비트";
				}
	
				var imgtag = "<img src='http://static.plaync.co.kr/lovebeat_v2/style/itemlist/ic_" + tall_beat_eng + ".gif' />";
	
				tooltip.getElementsByTagName('dt')[0].innerHTML = document.getElementById('itemname_'+targetCubeID+'_'+this.id).value;
				tooltip.getElementsByTagName('dd')[0].className = tall_beat_eng;
				tooltip.getElementsByTagName('dd')[0].innerHTML = imgtag + " " + document.getElementById('price_day_1_'+targetCubeID+'_'+this.id).value + tall_beat_kor;
			}
		}
		items[i].onmouseout = function(){
			tooltip.style.display = "none";
		}
	}
}

/* 도전 코디네이터 */
function rolloverCoordi(num) {
	var coordiView=$("coordiView").getElementsByTagName('li');
	for(var i=0; i<coordiView.length; i++){
		if((num-1)==i){
			coordiView[i].style.display="block";
		}
		else {
			coordiView[i].style.display="none";
		}
	}
}


// 아이템리스트
function itemListNav(navi){
	var maxLeft = "28", minLeft ="-1208";
	var nextImg=$("nextList"), prevImg=$("prevList");
	var currentList = $("wrapStyleList");
	var currentLeft = parseInt(currentList.style.left);
	if (navi == "nextList"){
		if (currentLeft <= minLeft) {
			nextImg.src=nextImg.src.replace("_on.gif", "_off.gif");
			return false;
		}
		else {
			currentList.style.left=(currentLeft-618)+"px";
			if (currentLeft <= minLeft) {
				nextImg.src=nextImg.src.replace("_on.gif", "_off.gif");
			}
			nextImg.src=nextImg.src.replace("_off.gif", "_on.gif");
			prevImg.src=prevImg.src.replace("_off.gif", "_on.gif");
		}
	}
	else if (navi == "prevList"){
		if (currentLeft >= maxLeft) {
			prevImg.src=prevImg.src.replace("_on.gif", "_off.gif");
			return false;
		}
		else {
			nextImg.src=nextImg.src.replace("_off.gif", "_on.gif");
			prevImg.src=prevImg.src.replace("_off.gif", "_on.gif");
			currentList.style.left=(currentLeft+618)+"px";
		}
	}
	
	currentLeft = parseInt(currentList.style.left);
	if (currentLeft <= minLeft) {
		nextImg.src=nextImg.src.replace("_on.gif", "_off.gif");
		return false;
	}
	else if (currentLeft >= maxLeft) {
		prevImg.src=prevImg.src.replace("_on.gif", "_off.gif");
		return false;
	}
}

function setPng24(obj) {
	obj.width=obj.height=1;
	obj.className=obj.className.replace(/\bpng24\b/i,'');
	obj.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src+"',sizingMethod='scale');"
	obj.src='http://static.plaync.co.kr/lovebeat_v2/common/png.gif';
	return '';
}

function listOn(id) {
	document.getElementById(id).style.display='block';
}
function listOff(id) {
	document.getElementById(id).style.display='none';
}

/* scroll top */
function fixedPositionForIE6(type,length){ //type:fixedSide or fixedBottom,  length:fixedSide=topCss or  fixedBottom:objHeight 
	var viewportScroll = (document.documentElement) ? document.documentElement.scrollTop : document.body.scrollTop;	
	var viewportHeight = (document.documentElement) ? document.documentElement.clientHeight : document.body.clientHeight;

	if( type == "fixedBottom"){				
		var objHeight = length;
		var objTop = viewportHeight - objHeight;		
		return objTop + viewportScroll + "px"
	}
}
function goTop(){document.documentElement.scrollTop = 0;} //top버튼 눌렀을때


/* 방명록 토글 */
function initToggle(tabContainer) {
	triggers = tabContainer.getElementsByTagName("a");
	for(i = 0; i < triggers.length; i++) {
		if (triggers.item(i).href.split("#")[1])
			triggers.item(i).targetEl = document.getElementById(triggers.item(i).href.split("#")[1]);
		if (!triggers.item(i).targetEl)
			continue;
		triggers.item(i).targetEl.style.display = "none";
		triggers.item(i).onclick = function () {
			if (tabContainer.current == this) {
				this.targetEl.style.display = "none";
				tabContainer.current = null;
			} else {
				if (tabContainer.current) {
					tabContainer.current.targetEl.style.display = "none";
				}
				this.targetEl.style.display = "block";
				tabContainer.current = this;
			}
			return false;
		}
	}
}

/* TOP 버튼 */
function getScrollY() {
	var scrollY;
	if (document.documentElement.scrollTop) {
		scrollY = document.documentElement.scrollTop;
		}
	else if (document.body.scrollTop) {
		scrollY = document.body.scrollTop;
		}
	else if (window.pageYOffset) {
		scrollY = pageYOffset;
		}
	else {
		scrollY = 0;
		}
	return scrollY;
}
function getUserWindowY()
{
	var winY;
	if (window.innerHeight)
	{
		winY = window.innerHeight;
	}
	else if (document.documentElement.clientHeight)
	{
		winY = document.documentElement.clientHeight;
	}
	else if (document.body.clientHeight)
	{
		winY = document.body.clientHeight;
	}
	return winY;
}
function scrollingBanner(obj, parent, offset) {
	var k = 0.1; // 동적계수
	var objH = parseInt(getStyleAtt(obj, "height")); // 배너 세로 사이즈 - 스타일 시트에서 가져옴
	if (isNaN(objH)) return false;
	if (parent) var parentEl=document.getElementById(parent); // 영역 지정
	setInterval(function()
	{
		var agentY = getUserWindowY(); // 사용자 창 높이
		var scrollY = getScrollY(); // 스크롤 현재 높이
		var objY = parseInt(getStyleAtt(obj, "top")); // 배너 현재 높이
		var targetY = agentY + scrollY - (objH + offset);
		var distanceY = objY - targetY; // 배너와 목표지점과의 Y축 차이
		var steps = Math.abs(distanceY) * k; // 반복적으로 이동할 거리
		if (objY < targetY) {
			if (parent) {
				if (parseInt(obj.style.top)<parentEl.clientHeight-obj.clientHeight - offset) objY += Math.ceil(steps);
			}
			else objY += Math.ceil(steps);
		} // 스크롤바를 아래로 움직인 경우
		else if (objY > targetY) objY -= Math.ceil(steps);// 스크롤바를 위로 움직인 경우
		obj.style.top = objY + "px";
	}, 1);
}
function goTop(){document.documentElement.scrollTop = 0;} //top버튼 눌렀을때