// slides
(function(A){A.fn.slides=function(B){B=A.extend({},A.fn.slides.option,B);return this.each(function(){A("."+B.container,A(this)).children().wrapAll('<div class="slides_control"/>');var V=A(this),J=A(".slides_control",V),Z=J.children().size(),Q=J.children().outerWidth(),M=J.children().outerHeight(),D=B.start-1,L=B.effect.indexOf(",")<0?B.effect:B.effect.replace(" ","").split(",")[0],S=B.effect.indexOf(",")<0?L:B.effect.replace(" ","").split(",")[1],O=0,N=0,C=0,P=0,U,H,I,X,W,T,K,F;function E(c,b,a){if(!H&&U){H=true;B.animationStart(P+1);switch(c){case"next":N=P;O=P+1;O=Z===O?0:O;X=Q*2;c=-Q*2;P=O;break;case"prev":N=P;O=P-1;O=O===-1?Z-1:O;X=0;c=0;P=O;break;case"pagin":O=parseInt(a,10);N=A("."+B.paginClass+" a."+B.currentClass,V).attr("href").match("[^#/]+$");if(O>N){X=Q*2;c=-Q*2;}else{X=0;c=0;}P=O;break;}if(b==="fade"){if(B.crossfade){J.children(":eq("+O+")",V).css({zIndex:10}).fadeIn(B.fadeSpeed,B.fadeEasing,function(){if(B.autoHeight){J.animate({height:J.children(":eq("+O+")",V).outerHeight()},B.autoHeightSpeed,function(){J.children(":eq("+N+")",V).css({display:"none",zIndex:0});J.children(":eq("+O+")",V).css({zIndex:0});B.animationComplete(O+1);H=false;});}else{J.children(":eq("+N+")",V).css({display:"none",zIndex:0});J.children(":eq("+O+")",V).css({zIndex:0});B.animationComplete(O+1);H=false;}});}else{J.children(":eq("+N+")",V).fadeOut(B.fadeSpeed,B.fadeEasing,function(){if(B.autoHeight){J.animate({height:J.children(":eq("+O+")",V).outerHeight()},B.autoHeightSpeed,function(){J.children(":eq("+O+")",V).fadeIn(B.fadeSpeed,B.fadeEasing);});}else{J.children(":eq("+O+")",V).fadeIn(B.fadeSpeed,B.fadeEasing,function(){if(A.browser.msie){A(this).get(0).style.removeAttribute("filter");}});}B.animationComplete(O+1);H=false;});}}else{J.children(":eq("+O+")").css({left:X,display:"block"});if(B.autoHeight){J.animate({left:c,height:J.children(":eq("+O+")").outerHeight()},B.slideSpeed,B.slideEasing,function(){J.css({left:-Q});J.children(":eq("+O+")").css({left:Q,zIndex:5});J.children(":eq("+N+")").css({left:Q,display:"none",zIndex:0});B.animationComplete(O+1);H=false;});}else{J.animate({left:c},B.slideSpeed,B.slideEasing,function(){J.css({left:-Q});J.children(":eq("+O+")").css({left:Q,zIndex:5});J.children(":eq("+N+")").css({left:Q,display:"none",zIndex:0});B.animationComplete(O+1);H=false;});}}if(B.pagin){A("."+B.paginClass+" a."+B.currentClass,V).removeClass(B.currentClass);A("."+B.paginClass+" a:eq("+O+")",V).addClass(B.currentClass);}}}function R(){clearInterval(V.data("interval"));}function G(){if(B.pause){clearTimeout(V.data("pause"));clearInterval(V.data("interval"));K=setTimeout(function(){clearTimeout(V.data("pause"));F=setInterval(function(){E("next",L);},B.play);V.data("interval",F);},B.pause);V.data("pause",K);}else{R();}}if(Z<2){return ;}if(D<0){D=0;}if(D>Z){D=Z-1;}if(B.start){P=D;}if(B.randomize){J.randomize();}A("."+B.container,V).css({overflow:"hidden",position:"relative"});J.children().css({position:"absolute",top:0,left:J.children().outerWidth(),zIndex:0,display:"none"});J.css({position:"relative",width:(Q*3),height:M,left:-Q});A("."+B.container,V).css({display:"block"});if(B.autoHeight){J.children().css({height:"auto"});J.animate({height:J.children(":eq("+D+")").outerHeight()},B.autoHeightSpeed);}if(B.preload&&J.find("img:eq("+D+")").length){A("."+B.container,V).css({background:"url("+B.preloadImage+") no-repeat 50% 50%"});var Y=J.find("img:eq("+D+")").attr("src")+"?"+(new Date()).getTime();if(A("img",V).parent().attr("class")!="slides_control"){T=J.children(":eq(0)")[0].tagName.toLowerCase();}else{T=J.find("img:eq("+D+")");}J.find("img:eq("+D+")").attr("src",Y).load(function(){J.find(T+":eq("+D+")").fadeIn(B.fadeSpeed,B.fadeEasing,function(){A(this).css({zIndex:5});A("."+B.container,V).css({background:""});U=true;B.slidesLoaded();});});}else{J.children(":eq("+D+")").fadeIn(B.fadeSpeed,B.fadeEasing,function(){U=true;B.slidesLoaded();});}if(B.bigTarget){J.children().css({cursor:"pointer"});J.children().click(function(){E("next",L);return false;});}if(B.hoverPause&&B.play){J.bind("mouseover",function(){R();});J.bind("mouseleave",function(){G();});}if(B.generateNextPrev){A("."+B.container,V).after('<a href="#" class="btn '+B.prev+'"><span class="blind">Prev</span></a>');A("."+B.prev,V).after('<a href="#" class="btn '+B.next+'"><span class="blind">Next</span></a>');}A("."+B.next,V).click(function(a){a.preventDefault();if(B.play){G();}E("next",L);});A("#"+B.nextId,V).click(function(a){a.preventDefault();if(B.play){G();}E("next",L);});A("."+B.prev,V).click(function(a){a.preventDefault();if(B.play){G();}E("prev",L);});A("#"+B.prevId,V).click(function(a){a.preventDefault();if(B.play){G();}E("prev",L);});if(B.generatepagin){if(B.prependpagin){V.prepend("<div class="+B.paginClass+"></div>");}else{V.append("<div class="+B.paginClass+"></div>");}J.children().each(function(){A("."+B.paginClass,V).append('<a href="#'+C+'">'+(C+1)+"</a>");C++;});}else{A("."+B.paginClass+" a",V).each(function(){A(this).attr("href","#"+C);C++;});}A("."+B.paginClass+" a:eq("+D+")",V).addClass(B.currentClass);A("."+B.paginClass+" a",V).click(function(){if(B.play){G();}I=A(this).attr("href").match("[^#/]+$");if(P!=I){E("pagin",S,I);}return false;});A("a.link",V).click(function(){if(B.play){G();}I=A(this).attr("href").match("[^#/]+$")-1;if(P!=I){E("pagin",S,I);}return false;});if(B.play){F=setInterval(function(){E("next",L);},B.play);V.data("interval",F);}});};A.fn.slides.option={preload:false,preloadImage:"/img/loading.gif",container:"slides_container",generateNextPrev:false,next:"next",prev:"prev",pagin:true,generatepagin:true,prependpagin:false,paginClass:"pagin",currentClass:"cur",fadeSpeed:0,fadeEasing:"",slideSpeed:400,slideEasing:"",start:1,effect:"slide",crossfade:false,randomize:false,play:0,pause:0,hoverPause:false,autoHeight:false,autoHeightSpeed:350,bigTarget:false,animationStart:function(){},animationComplete:function(){},slidesLoaded:function(){}};A.fn.randomize=function(C){function B(){return(Math.round(Math.random())-0.5);}return(A(this).each(function(){var F=A(this);var E=F.children();var D=E.length;if(D>1){E.hide();var G=[];for(i=0;i<D;i++){G[G.length]=i;}G=G.sort(B);A.each(G,function(I,H){var K=E.eq(H);var J=K.clone(true);J.show().appendTo(F);if(C!==undefined){C(K,J);}K.remove();});}}));};})(jQuery);


//브라우저 별 키값 검사
function validateKey(e) {
	var keynum;
	var ismouseClick = 1;

	if (window.event) { //IE & Safari
		keynum = e.keyCode;
		//Safari의 경우 마우스클릭은 keynum 0 이 넘어옴
		if (keynum == 0){
			ismouseClick = 0;
		}
	}
		else if ( e.which ){ // Netscape/Firefox/Opera
		keynum = e.which;

		if (keynum == 1) {
			ismouseClick = 0;
		}
	}
	//마우스 클릭이거나 엔터키를 누른경우 true값 반환
	if ( ismouseClick == 0 || keynum == 13 ) {
		return true;
	}
	else{
		return false;
	}
}

//브라우저 별 키값 검사
function jsToggle(id,idx,ev){
	if(validateKey(ev)){
	
		var swObj = 	document.getElementById(id).getElementsByTagName("dd");
		var swLink = document.getElementById(id).getElementsByTagName("a");

		if(swObj[idx].style.display=="block"){
			swObj[idx].style.display = "none";
			swLink[idx].setAttribute("class","on");
		}
		else if(swObj[idx].style.display=="none"){
			for(var i=0; i<swObj.length; i++){						
				swObj[i].style.display = "none";
				swLink[i].setAttribute("class","");
			}
			swObj[idx].style.display = "block";
			swLink[idx].setAttribute("class","on");					
		}

		return false;
	}
}


 function hover_layer(n) {
	if ($("."+n).css("display") == "block")
	{
		$("."+n).hide();
	}else{
		$("."+n).show();
	}
}

function music_feel(n){
	$(".genre_step_result img").attr("src","/images/music/music_feel_tab_0"+n+".gif");
}

 $(document).ready(function () {
	$("#header li:first-child").addClass("hd-first");
	$("#footer li:first-child").addClass("ft-first"); 
	$("#header li:last").addClass("hd-last");
	$(".music_list_type04 th:last-child").addClass("last");
	$(".special_list_type01 th:last-child").addClass("last");

	
	$(".make_input").focus(function(){
		$(this).addClass("make_input_on");
		}		
	)
	$(".make_input").blur(function(){
		$(this).removeClass("make_input_on");
		}
	)	
		
	$("table.music_list_table tbody tr").hover(function(){
		$(this).addClass("bg");
	},function(){
		$(this).removeClass("bg");
	})

	$("table.music_list_type01 tbody tr").hover(function(){
		$(this).addClass("bg");
	},function(){
		$(this).removeClass("bg");
	})

	$("table.music_list_type02 tbody tr").hover(function(){
		$(this).addClass("bg");
	},function(){
		$(this).removeClass("bg");
	})

	$("table.music_list_type03 tbody tr").hover(function(){
		$(this).addClass("bg");
	},function(){
		$(this).removeClass("bg");
	})

	$("table.music_list_type04 tbody tr").hover(function(){
		$(this).addClass("bg");
	},function(){
		$(this).removeClass("bg");
	})

	$(".social_vote").hover(function(){
		$(this).find(".edit").show();
	},function(){
		$(this).find(".edit").hide();
	})
				
	for (i=0;i < $(".hot_photo_list img").length ;i++)
	{				
		$(".hot_photo_list .pic_p").css("bottom","0px");
		width = $(".hot_photo_list img").eq(i).width()-2;
		height = $(".hot_photo_list img").eq(i).height()-2;
		$(".hot_photo_list dl dt").eq(i).find(".pic_p").width(width);					
		$(".hot_photo_list dl dt").eq(i).find(".pic_p").height(height);					
		
	}
	for (i=0;i < $(".photo_list img").length ;i++)
	{				
		$(".photo_list .pic_p").css("bottom","0px");
		width = $(".photo_list img").eq(i).width()-2;
		height = $(".photo_list img").eq(i).height()-2;
		$(".photo_list li").eq(i).find(".pic_p").width(width);					
		$(".photo_list li").eq(i).find(".pic_p").height(height);					
		
	}
	$(".help_list .cb a").click(function(){
		if ($(this).next().css("display") == "none")
		{
			$(".help_list .cb a").removeClass("on");
			$(this).addClass("on");
			$(this).next().slideDown("fast");
		}else{
			$(".help_list .cb a").removeClass("on");
			$(this).next().slideUp("fast");
		}	
	})
		
	$(".artist_box a").hover(function(){
		$(".pop_artist_box").show();
		$(".pop_artist_box").css("left",$(this).position().left-7);
		$(".pop_artist_box").css("top",$(this).position().top-60);
		
	},function(){
		$(".pop_artist_box").hide();
	})
		
	
	$(".btn_star").click(function(){					
		$(".pop_star_point").css("left",$(this).position().left);
		$(".pop_star_point").css("top",$(this).position().top+26);
		$(".pop_star_point").show();
	})
	$(".star_type2").click(function(){					
		$(".pop_star_point").css("left",$(this).position().left+265);
		$(".pop_star_point").css("top",$(this).position().top+290);
		$(".pop_star_point").show();
	})
		
	$(".pop_star_point .point a").click(function(){					
		$(".pop_star_point .point a").removeClass("on");
		$(this).addClass("on");		
	})
	$(".list_box ul li a").click(function(){							
		
		if ($(this).parent().parent().height() == 32)
		{	
			$(this).parent().parent().animate({ "height": $(this).parent().next().height()+65 }, "fast");	
			$(this).parent().parent().addClass("on");
		}else{
			$(this).parent().parent().animate({ "height": 32}, "fast");	
			$(this).parent().parent().removeClass("on");
		}
	})
		
	$(".special_list_type01 tr td.title a").click(function(){
		if ($(this).parent().parent().next().find("td").css("display") == "none")
		{			
			$(this).parent().parent().next().find("td").slideDown("fast");
		}else{
			$(this).parent().parent().next().find("td").slideUp("fast");
		}	
	})
	
	
	
});

function slider_list(kind,n,many){
	num = Number($("."+kind+" .num").val());	
	
	if (many == null)
	{
		many = 5;
	}	
	if (n == "prev")
	{
		if (num == 1)
		{
			num = $("."+kind+" .con_slider_list ul > li").length - (many-1);
		}else{
			num = num - 1;
		}
		n = num;
	}
	
	if (n == "next")
	{
		if (num < $("."+kind+" .con_slider_list ul  > li").length - (many-1))
		{
			num = num +1;
		}else{
			num = 1
		}
		n = num;
	}		
	
	
	if ($("."+kind).children().hasClass("slider_dot"))
	{
		
		for (i=1; i <= $("."+kind+" .slider_dot img").length ; i++ )
		{
			
			if (i == n)
			{				
				imgname = $("."+kind+" .slider_dot img").eq(i-1).attr("src").split("off")[0];
				imgname = imgname.split("on")[0];
				$("."+kind+" .slider_dot img").eq(i-1).attr("src",imgname+"on.gif");
				
			}else{				
				imgname = $("."+kind+" .slider_dot img").eq(i-1).attr("src").split("off")[0];
				imgname = imgname.split("on")[0];
				$("."+kind+" .slider_dot img").eq(i-1).attr("src",imgname+"off.gif");
			}
		}
	}	

	$("."+kind+" .con_slider_list ul").animate({ "left": -$("."+kind+" .con_slider_list ul > li").eq(n-1).position().left  }, "fast");	
	$("."+kind+" .num").val(n);
}

function artist_con_tab(n){
	$(".tab_con").hide();
	$(".tab_con").eq(n-1).show();
	$(".artist_con_right .tab a").removeClass("on");
	$(".artist_con_right .tab a").eq(n-1).addClass("on");
	
}
function image_tab(n){
	$(".pop_imgae_select").hide();
	$(".pop_imgae_select").eq(n-1).show();
	$(".imgae_tab a").removeClass("on");
	$(".imgae_tab a").eq(n-1).addClass("on");
	
}
function myalbum_tab(n){
	if (n == 1)
	{
		$(".myalbum_search").show();
		$(".music_search").hide();		
	}else{
		$(".myalbum_search").hide();
		$(".music_search").show();			
	}
	
	$(".select_left .tab a").removeClass("on");
	$(".select_left .tab a").eq(n-1).addClass("on");
}


/* textarea clear */
function clearbg(id){
	document.getElementById(id).style.backgroundImage='none';
}

/* select */
function getClass(classname, tagname, tarID) {
	if (tarID == undefined) tarID = document;
	var element = this.nodeType == 1 ? this : tarID;
	var elements = [], nodes = tagname ? element.getElementsByTagName(tagname) : element.getElementsByTagName('*');
	for(var i=0; i<nodes.length; i++) {
		if(nodes[i].className.indexOf(classname) != -1)
			elements.push(nodes[i]);
	}
	return elements;
}

function addEvent( obj, type, fn ) {
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function removeEvent( obj, type, fn ) {
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}

function stopBubble(e){
	if(e) {
		e.stopPropagation();
	} else {
		window.event.cancelBubble = true;
	}
}

function selectMore(wrapper){
	var _d = document;
	var wrapper = _d.getElementById(wrapper);				// 링크박스
	var pointer = getClass('title','span',wrapper)[0];		// 타이틀
	var linkBox = getClass('linkbox','div',wrapper)[0];		// 목록
	var linkBoxList = linkBox.getElementsByTagName('label');	// 목록의 모든 라벨
	//	linkBox.style.display = 'none';		// 목록 숨김 초기화는 css로 지정함 : js제거시엔 작동 안함.

	function hideLinks(){			// 목록을 숨기는 함수
		if (linkBox.style.display == ''){
			linkBox.style.display = 'none';
		}
	}

	function toggleLinks(e){		// 목록 토글 함수
		if (linkBox.style.display == 'none'){
			linkBox.style.display = '';
			stopBubble(e);
			addEvent(document,'click',hideLinks);
		} else {
			linkBox.style.display = 'none';
			stopBubble(e);
			removeEvent(document,'click',hideLinks);
		}
		return false;
	}

	for (var i=0; i<linkBoxList.length; i++){
		linkBoxList[i].onclick = function(){
			pointer.childNodes[0].nodeValue = this.childNodes[0].nodeValue;		// 옵션 선택시 타이틀 value값 교체
			hideLinks();														// 선택시 목록 숨김
		}
		linkBoxList[linkBoxList.length-1].onblur = hideLinks;		// 링크목록의 마지막 링크에서 벗어나면 링크목록 숨김.
	}

	pointer.onclick = toggleLinks;			// 타이틀을 클릭 or 포커스 시 링크목록을 보이게 한다.
}


//2011.08.02
function hot_list_move(m, s, n){
	
	var num = $("."+m+" ."+s).index($("."+m+" ."+s+":visible"));
	var last = $("."+m+" ."+s).index($("."+m+" ."+s+":last"));
	
	var sindex = 0;
	if(n == 'prev') {
		if(num == 0) { 	sindex = last;	}
		else {			sindex = num-1;	}
		
	} else {
		if(num == last) {	sindex = 0;	} 
		else {				sindex = num+1;	}
	}
	$("."+m+" ."+s).hide();
	$("."+m+" ."+s).eq(sindex).show();
	
	$("."+m+" ."+s).parent().find("ul .num span").html(sindex+1);
}

//2011.08.02
function new_song_move(m, s, n){
	
	var num = $("."+m+" ."+s).index($("."+m+" ."+s+":visible"));
	var last = $("."+m+" ."+s).index($("."+m+" ."+s+":last"));
	
	var sindex = 0;
	if(n == 'prev') {
		if(num == 0) { 	sindex = last;	}
		else {			sindex = num-1;	}
		
	} else {
		if(num == last) {	sindex = 0;	} 
		else {				sindex = num+1;	}
	}
	$("."+m+" ."+s).hide();
	$("."+m+" ."+s).eq(sindex).show();
}

//2011.08.02
var photo = 1;
function slider_list_photo(kind,n,many){
	var num = photo;	

	if (many == null)
	{
		many = 7;
	}	
	if (n == "prev")
	{
		if (num == 1)
		{
			num = $("."+kind+" ul > li").length - (many-1);
		}else{
			num = num - 1;
		}
		n = num;
	}
	
	if (n == "next")
	{
		if (num < $("."+kind+" ul  > li").length - (many-1))
		{
			num = num +1;
		}else{
			num = 1;
		}
		n = num;
	}		

	$("."+kind+" ul").animate({ "left": -$("."+kind+" ul > li").eq(n-1).position().left  }, "fast");	
	photo = n;
	
}

// 2011.08.02
function top_photo_chg(n){ 
	$(".wrapbox_pht a").hide();
	$(".wrapbox_pht a").eq(n-1).show();	
	
	$(".slimg_desc a").hide();
	$(".slimg_desc a").eq(n-1).show();

	$(".photo_view .con_slider_list ul a span").removeClass("selected");
	$(".photo_view .con_slider_list ul a").eq(n-1).find("span").addClass("selected");
	
}

// 2011.08.02
function top_photo_slide(n){
	var num = $(".wrapbox_pht a").index($(".wrapbox_pht a:visible"));
	var last = $(".wrapbox_pht a").index($(".wrapbox_pht a:last"));
	
	var sindex = 0;
	if(n == 'prev') {
		if(num == 0) { 	sindex = last;	}
		else {			sindex = num-1;	}
		
	} else {
		if(num == last) {	sindex = 0;	} 
		else {				sindex = num+1;	}
	}
	$(".wrapbox_pht a").hide();
	$(".slimg_desc a").hide();
	$(".wrapbox_pht a").eq(sindex).show();
	$(".slimg_desc a").eq(sindex).show();

	$(".photo_view .con_slider_list ul a span").removeClass("selected");
	$(".photo_view .con_slider_list ul a").eq(sindex).find("span").addClass("selected");
}

//2011.08.02
function hot_list_move(m, s, n){
	
	var num = $("."+m+" ."+s).index($("."+m+" ."+s+":visible"));
	var last = $("."+m+" ."+s).index($("."+m+" ."+s+":last"));
	
	var sindex = 0;
	if(n == 'prev') {
		if(num == 0) { 	sindex = last;	}
		else {			sindex = num-1;	}
		
	} else {
		if(num == last) {	sindex = 0;	} 
		else {				sindex = num+1;	}
	}
	$("."+m+" ."+s).hide();
	$("."+m+" ."+s).eq(sindex).show();
	
	$("."+m+" ."+s).parent().find("ul .num span").html(sindex+1);
}



// 상단 스크롤
function textScroll(scroll_el_id){
    this.objElement = document.getElementById(scroll_el_id);
    this.objElement.style.position = 'relative';
    this.objElement.style.overflow = 'hidden';

    this.objLi = this.objElement.getElementsByTagName('li');
    this.height = 30;
    this.num = this.objLi.length;
    this.totalHeight = this.height * this.num;
    this.scrollspeed = 2;
    this.objTop = new Array();
    this.timer = null;

    for(var i=0; i<this.num; i++){
        this.objLi[i].style.position = 'absolute';
        this.objTop[i] = this.height * i;
        this.objLi[i].style.top = this.objTop[i]+'px';
    }
}

textScroll.prototype.move = function(){
    for(var i=0; i<this.num; i++){
        this.objTop[i] = this.objTop[i] - this.scrollspeed;
        this.objLi[i].style.top = this.objTop[i]+'px';
    }
    if(this.objTop[0] % this.height == 0){
        this.jump();
    }
    else{
        clearTimeout(this.timer);
        this.timer = setTimeout(this.name+".move()", 50);
    }
}

textScroll.prototype.jump = function(){
    for(var i=0; i<this.num; i++){
        if(this.objTop[i] == this.height*(-1)){
            this.objTop[i] = this.objTop[i] + this.totalHeight;
            this.objLi[i].style.top = this.objTop[i]+'px';
        }
    }
    clearTimeout(this.timer);
    this.timer = setTimeout(this.name+".move()", 2000);
}

textScroll.prototype.start = function(){
    this.timer = setTimeout(this.name+".move()", 3000);
}




