/**
 * @fileoverview Daum Music
 *
 * @author  maart, edina 
 * @version 1.0
 */
var doc = document;
try{doc.domain="daum.net";}catch(e){}
try{doc.execCommand("BackgroundImageCache",false,true);}catch(ignored){}

function mOverPaging( obj ){obj.className+=" on";}
function mOutPaging( obj ){obj.className=obj.className.replace(" on","")}
function mOverRow( obj ){obj.style.backgroundColor="#F6F7FC";}
function mOutRow( obj ){obj.style.backgroundColor="";}
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='image');"
	obj.src='http://img-contents.daum-img.net/music/2008_home/common/blank.gif';
	return '';
}
function $(id){return doc.getElementById(id);}
function $C(node){return doc.createElement(node);}
function $T(text){return doc.createTextNode(text);}
function $A(iterable){
	if (!iterable) return [];
	var results=[];
	for (var i=0,length=iterable.length; i<length; i++)
		results.push(iterable[i]);
	return results;
}
/*
Thanks for JES
*/
Object.extend=function(a,b){for (var property in b) a[property]=b[property];return a;};
Function.prototype.bind=function(){
	var __method=this,args=$A(arguments),object=args.shift();
	return function() {
		return __method.apply(object,args.concat($A(arguments)));
	}
}
Function.prototype.bindAsEventListener=function()
{
	var __method=this,args=$A(arguments),object=args.shift();
	return function(event) {
		return __method.apply(object,[event || window.event].concat(args));
	}
}
var UI={};
UI.$=function(s){return doc.getElementById(s) };
UI.$C=function(node){return doc.createElement(node);}
UI.$T=function(text){return doc.createTextNode(text);}
UI.trim=function(s) {return s.replace(/(^\s*)|(\s*$)/g,"") };
UI.togle=function(id) { UI.$(id).style.display=(UI.getStyle(UI.$(id),'display')=='none') ? 'block':'none' };
UI.hide=function(id) { UI.$(id).style.display="none"; };
UI.show=function(id) { UI.$(id).style.display="block"; };
UI.getEl=function(e){var E=UI.getE(e);return E.target || E.srcElement}
UI.getE=function(e){return e || window.event}
UI.random=function(min, max){ return Math.floor(Math.random() * (max - min + 1) + min) };
UI.StringBuffer=function(){this.buffer=new Array()}
UI.StringBuffer.prototype={append:function(s){this.buffer.push(s)},toString:function(){return this.buffer.join("")}};
UI.setOpacity=function(el,value){ el.style.filter="alpha(opacity="+value+")"; el.style.opacity=(value/100); el.style.MozOpacity=(value/100); el.style.KhtmlOpacity=(value/100); };
UI.getCookie=function(name){
    name += "=";
    cookie = document.cookie + ";";
    start = cookie.indexOf(name);
    if (start != -1){
        end = cookie.indexOf(";",start);
        return unescape(cookie.substring(start + name.length, end));
    }
    return "";
};
UI.setCookie=function(name, value, expires, path, domain, secure){
    if(expires){//day로 설정
        var d=new Date(); d.setDate(d.getDate()+expires);
        expires = d.toGMTString();
    }
    document.cookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
};
UI.addComma=function(s){
    s=UI.delComma( s+'' );
    var re=new RegExp('(-?[0-9]+)([0-9]{3})');
    while(re.test(s)) s=s.replace(re,'$1,$2');
    return s;
};
UI.delComma=function(s){ s=s.replace(/,/gi, ""); return s; }
//add event
UI.addEvent=function(object,type,listener) {
	if(object.addEventListener) {if(type=='mousewheel')type='DOMMouseScroll'; object.addEventListener(type,listener,false)}
	else { object.attachEvent("on"+type,listener); }
};
//delete event
UI.delEvent=function(object,type,listener){
	if (object.removeEventListener) {if(type=='mousewheel')type='DOMMouseScroll'; object.removeEventListener(type,listener,false)}
	else object.detachEvent('on'+type,listener);
};
//stop event
UI.stopEvent=function(event) {
	var e=event || window.event;
	try {
		if(e.preventDefault) {e.preventDefault(); e.stopPropagation(); }
		else {e.returnValue=false; e.cancelBubble=true;}

	} catch (e) {}
};
UI.cleanNode=function(el){
	var child = el.firstChild;
	while (child){
        var nextNode = child.nextSibling;
        if (child.nodeType == 3 && !/\S/.test(child.nodeValue)){ el.removeChild(child); }
        child = nextNode;
	}
	return el;
};
UI.getBrowser=function(){
    var ua=navigator.userAgent.toLowerCase();
    var opera=/opera/.test(ua)
    UI._browser={
        ie:!opera && /msie/.test(ua),
        ie_ver: parseFloat(((ua.split('; '))[1].split(' '))[1]),
        opera:opera,
        ff:/firefox/.test(ua),
        chrome:/chrome/.test(ua),
        gecko:/gecko/.test(ua)
    };
    return UI._browser;
};
UI.parseQuery=function(s){ var str=s||location.search.substr(1); var r={},t=[]; var a=str.split('&'); for(var i=0;i<a.length;i++){t=a[i].split("=");r[t[0]] = t[1];} return r; };
UI.mouseOut=function(e, obj){
	var to = !!e.relatedTarget?e.relatedTarget:event.toElement; 
	while(to) { 
		if(to == obj) return false; 
		to = to.parentNode; 
	}
	return true;
};
UI.getStyle=function(el, style) {
	var value = el.style[style];
	if(!value)
	{
		if(document.defaultView && document.defaultView.getComputedStyle && !UI.getBrowser().opera) 
		{
			var css = document.defaultView.getComputedStyle(el, null);
			value = css ? css[style] : null;
		} 
		else if (el.currentStyle){
			if( style == "backgroundPosition" ){
				value = el.currentStyle["backgroundPositionX"] + " " + el.currentStyle["backgroundPositionY"] ;
			} else {
				value = el.currentStyle[style];
			}
		}
	}
	return value == 'auto' ? null : value;
};
UI.length=function(str,len,tail){
	if(!str) str="";
	if(!tail) tail="";
	var l=0,c=0,l2=0,u="",s="";
	if(len>0) l2=len;
	for(var i=0;u=str.charCodeAt(i);i++){
		if (u>127) l+=2;
		else l++;
		if(l2) {
			s+=str.charAt(i);
			if(l>=l2){
				if(l>l2) s=s.slice(0,-1);
				return s+tail;
			}
		}
	}
	return l2 ? s:l;
};
UI.html2str=function(s,m){
	var s1=["&amp;","&#39;","&quot;","&lt;","&gt;"];
	var s2=["&","'","\"","<",">"];
	var s3=[];
	if(m) {s3=s1;s1=s2;s2=s3;}
	for(var i in s1) s=s.replace(new RegExp(s1[i],"g"), s2[i]);
	return s;
};
UI.TabStatic=function(_id,_opts){
	var obj=UI.$(_id);
	if(!obj){return false;}
	var opts={
		index:0,
		elTag:"li",
		lnTag:"a",
		autoPos:true,
		autoBgPos:true
	}
	Object.extend(opts,_opts);
	var list=obj.getElementsByTagName(opts.elTag);
	if( list.length==0 )return false;
	var wt=0;
	for ( var i=0,j=list.length; i<j; i++ ){
		var anc=list[i].getElementsByTagName(opts.lnTag)[0];
		var w=parseInt(UI.getStyle(anc,"width"));
		if( isNaN(w) ) w=0;
		var val=(wt*-1)+"px 100%";
		if( i==opts.index ){
			val=(wt*-1)+"px 0%";
			anc.style.position="relative";
			anc.style.zIndex="2";
			anc.className += " on";
		}
		if( i>0 ){
			anc.style.marginLeft="-1px";
		}
		anc.style.display="block";
		if( opts.autoBgPos == true )anc.style.backgroundPosition=val;
		if( opts.autoPos == true )wt+=w-1;
	}
}


UI.TabDynamic=function(_id,_opts){
	if(!UI.$(_id)) {
		return false;
	}
	this.opts={
		evtType:"click",// event type on active [focus,mouseover]
		btnId:"tabBtn_",
		bodyId:"tabBody_",
		focusBlur:false,
		mode:"img",//img|css
		autoPos:true,
		autoBgPos:true,
		ptn:/((tab)[0-9]{1,2})(_on)*/ig // tab1,tab1_on,tab2,tab2_on ,...
	}
	this.prevTab = {
	   index : null,
	   tab : null,
	   body : null
	}
	this.currentTab = {
		index : null,
		tab : null,
		body : null
	}
	this.onComplete = function(){};

	Object.extend(this.opts,_opts);
	
	this.cid=_id; // root container id
	this.index=null; // current list index
	this.keyword=[];
	this.init();
}

UI.preventDefault = function(e){
	var e = e || window.event;
	if(e) e.returnValue = false;	
	if(e) { if(e.preventDefault) e.preventDefault(); }	
	return false;		
};
	
UI.TabDynamic.prototype = {
	init:function(){UI.addEvent(UI.$(this.cid),this.opts.evtType,this.action.bind(this));},
	addKey:function(name){this.keyword.push(name);},
	setIndex:function(val){this.index=val;},
	hiddenBody:function(){
		for( var i=0,j=this.keyword.length; i<j ; i++ ){
			var obj=UI.$(this.opts.bodyId+this.keyword[i]);
			if( obj )obj.style.display="none";
		}
	},
	render:function(){
		if( this.index==null ){
			if( this.opts.index == null ){
				this.index=this.keyword[0];
			} else if( isNaN( this.opts.index ) == true ){
				this.index=this.opts.index;
			} else {
				this.index=this.keyword[this.opts.index];
			}
		}
		this.resetPos();
		this.hiddenBody();
		this.on(this.index);
	},	
	resetPos:function(){
		var wt=0;
		
		for( var i=0,j=this.keyword.length; i<j ; i++ ){
			var obj=UI.$(this.opts.btnId+this.keyword[i]);
			obj.keyword = this.keyword[i];
			var w=parseInt(UI.getStyle(obj,"width"));
			if( isNaN(w) ) w=0;
			var val=(wt*-1)+"px 100%";
			if( this.keyword[i]==this.index ){
				val=(wt*-1)+"px 0%";
				//if( UI.getStyle(obj,"position") != "absolute" && UI.getStyle(obj,"position") != "relative" ){obj.style.position="relative";}
				obj.style.zIndex="1";
			} else {
				obj.style.zIndex="0";
			}
			if( i>0 ){

				//obj.style.marginLeft="-1px";
			}
			if( this.opts.autoBgPos==true ){obj.style.backgroundPosition=val;}
			if( this.opts.autoPos==true ){obj.style.top="0px";obj.style.left=wt+"px";}
			obj.style.display="block";
			wt+=w-1;
		}
	},
	action:function(evt) {
		var el = evt.target || evt.srcElement;
		var offsParent = el.offsParent;
		var offsDepth = 3;
		var isNothing = true;
		var trg = el;

		for ( var i=offsDepth; i>0 ; i-- ){
			if(trg.id.indexOf(this.opts.btnId)> -1) {
				var idx = trg.id.replace(this.opts.btnId, '');  			
				this.on(idx);
				isNothing = false;
				UI.stopEvent(evt);
				break;
			} else if ( trg == offsParent ){
				break;
			}
			trg = trg.parentNode;
		}
	},
	on:function(index) {  
		if(!UI.$(this.opts.btnId+index) || !UI.$(this.opts.bodyId+index)) {
			return false;
		}
		// set prev
		if (this.index==-1){                                                                              
			return false;                                                                                     
		} else if (this.index != null){         
			var preBtn = UI.$(this.opts.btnId+this.index); 
			var preBody = UI.$(this.opts.bodyId+this.index);
		
			if( this.opts.mode=="img")UI.setBgPos(preBtn,{y:"bottom"});
			else if( this.opts.mode=="css")preBtn.className=preBtn.className.replace(this.opts.ptn,"$1");        
			preBody.style.display="none";
			preBtn.style.zIndex="1";
			preBtn.className = preBtn.className.replace("tabOn","");
			this.prevTab.index = this.index;
			this.prevTab.tab = preBtn;
			this.prevTab.body = preBody;
			
		} 
		// set current    		   
		var curBtn = UI.$(this.opts.btnId+index);
		var curBody = UI.$(this.opts.bodyId+index);
		if( this.opts.mode=="img")UI.setBgPos(curBtn,{y:"top"});
		else if( this.opts.mode=="css")curBtn.className=curBtn.className.replace(this.opts.ptn,"$1_on");               
		curBody.style.display="block";
		curBtn.style.zIndex="3";
		curBtn.className += " tabOn";
		this.currentTab.index = index;
		this.currentTab.tab = curBtn;
        this.currentTab.body = curBody;
		
		this.index = index;                                                                        
		if (this.opts.focusBlur==true){                                                                
			curBtn.blur();                                                                        
		}
		if(typeof( this.onComplete ) == "function" ){
            this.onComplete(this);
		}
	}
}

UI.setBgPos=function(obj,pos){
	var bgPos=UI.getStyle(obj,"backgroundPosition").split(" ");
	if( pos.x )bgPos[0]=pos.x;
	if( pos.y )bgPos[1]=pos.y;
	obj.style.backgroundPosition=bgPos.join(" ");
}

/*
 * SimpleSlider
*/
/*
UI.SimpleSlider = function( list, opts ){
	this.list = list;
	this.opts = {
		index:0,
		loop:true
	}
	Object.extend( this.opts, opts );
	this.init();
}
UI.SimpleSlider.prototype = {
	init : function(){
		this.index = this.opts.index;
		this.cnt = this.list.length;
		for ( var i=this.cnt-1; i>=0 ; i-- ){
			if( i==this.index ){
				this.list[i].style.display = "block";
			} else {
				this.list[i].style.display = "none";
			}
		}
	},
	on : function( index ){this.list[index].style.display = "block";},
	off : function( index ){this.list[index].style.display = "none";},
	prev : function( objBtn ){
		this.off( this.index );
		this.index--;
		if( this.index < 0 ){
			if ( this.opts.loop == true ){ this.index = this.cnt-1;	} 
			else { this.index = 0 }
		}
		this.on( this.index );
	},
	next : function( objBtn ){
		this.off( this.index );
		this.index++;
		if( this.index >= this.cnt ){
			if ( this.opts.loop == true ){ this.index = 0; } 
			else { this.index = this.cnt-1; }
		}
		this.on( this.index );
	}

}
* */
/*
UI.togleMenu=function(id, objBtn) { 
	UI.togle( id );
	var disp = UI.$(id).style.display;
	if( disp == "none" ){
		UI.setBgPos( objBtn, {y:"100%"} );
	} else {
		UI.setBgPos( objBtn, {y:"0px"} );
	}
};
* */
UI.findParent=function(el, tagName, name) {     
    var t = tagName.toLowerCase();
    var n = name.toLowerCase();
    var p = el;
    if(n!="") {
        do {
            if(p.nodeType != 1) { p = null; break; } else { p = p.parentNode; }     
        } while(!(p.nodeName.toLowerCase() == t && (p.className.toLowerCase() == n || p.id.toLowerCase() == n)))
    } else {
        do {
            if(p.nodeType != 1) { p = null; break; } else { p = p.parentNode; }     
        } while(p.nodeName.toLowerCase() != t)
    }
    return p;
};
UI.Modal=function(url,options){
	this.options={
		type:'image',
		alt:'',
		loading:false,
		opacity:30,
		outer : true,	// 바깥 클릭시 닫힘
		inner : true,	// 안 클릭시 닫힘
		width:0,height:0
	};
	Object.extend(this.options, options);
	var options=this.options;

	if(!UI.$('UIModalB')) UI.Modal.print();
	UI.setOpacity(UI.$('UIModalB'), options.opacity);
	
	UI.Modal.setB();
	if(options.loading) UI.Modal.center(UI.$('UIModalL'));

	if(options.type=='image')
	{
		UI.$('UIModalF').innerHTML = '<img id="UIModalImage" src="'+url+'" alt="'+options.alt+'" />';
		if(options.loading) UI.$('UIModalImage').style.display='none';
		UI.addEvent(UI.$('UIModalImage'), 'load', UI.Modal.onload);
	}
	else if(options.type=='iframe')
	{		
		UI.$('UIModalF').innerHTML = '<iframe name="UIModalIframe" id="UIModalIframe" src="'+url+'" '+options.status+'></iframe>';
		if(options.loading) 
		{
			UI.$('UIModalIframe').style.display='none';
			UI.addEvent(UI.$('UIModalIframe'), 'load', UI.Modal.onload);
		}
		UI.Modal.center(UI.$('UIModalF'));
	}
	else if(options.type=='html')
	{
		UI.$('UIModalF').innerHTML = '<iframe src="about:blank" mce_src="about:blank" scrolling="no" frameborder="0"  style="width:'+options.width+';height:'+options.height+';position:absolute;z-index:0;border:none;display:block;FILTER:alpha(opacity=0);opacity:0;"></iframe>'+options.html;
	
		UI.Modal.center(UI.$('UIModalF'));
	}
	UI.Modal.self=this;
	if(options.outer) {	UI.addEvent(UI.$('UIModalB'), 'click', UI.Modal.reset); }
	if(options.inner) {	UI.addEvent(UI.$('UIModalF'), 'click', UI.Modal.reset); }
	UI.addEvent(window,'resize', UI.Modal.onresize);
	UI.addEvent(window,'scroll', UI.Modal.onscroll);
};

/**
2007-12-10
*/
UI.DynamicScript=function(url,enc){
    this.url=url||'';
    this.enc=enc||'';
    this.head=document.getElementsByTagName("head").item(0);
    if(this.url) this.call(this.url);
};
UI.DynamicScript.prototype={
    noCacheParam:function(){
        var b=(this.url.indexOf('?')==-1) ? '?':'&';
        return b+'nOcAchE='+(new Date()).getTime();
    },
    call:function(url){
        try{this.head.removeChild(this.script)}catch(e){};
        this.url=url;
        this.script = document.createElement("script");
        this.script.setAttribute("type", "text/javascript");   
        this.script.setAttribute("src", this.url+this.noCacheParam());
        if(this.enc) this.script.setAttribute("charset", this.enc);
        this.head.appendChild(this.script);
    }
};

UI.embedSWF=function(f,w,h,options){
	var param={	id:"UIswf_"+f,quality:'high',bgcolor:'#ffffff',allowScriptAccess:'always',allowFullScreen:'true',loop:'false',menu:'false',wmode:'transparent',swLiveConnect:'true'}
	Object.extend(param, options);

	var id='id="'+param.id+'"';
	var name = 'name="'+param.id+'"';
	var p='',e='';

	for(i in param)
	{
		if(i=='id')continue;
		p+='<param name="'+i+'" value="'+param[i]+'">\n';
		e+=i+'="'+param[i]+'" ';
	}
	var s='<object id="'+id+'" width="'+w+'" height="'+h+'" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">';
	s+='<param name="movie" value="'+f+'">'+ p;
	s+='<embed src="'+f+'" width="'+w+'" height="'+h+'" type="application/x-shockwave-flash" nowow="true" '+e+'/>';
	s+='</object>';
	if(param.containerId) {
		UI.$(param.containerId).innerHTML = s;
	} else {
		document.write(s);
	}
	return s;
};

UI.setOpacity=function(el,value){
	el.style.filter="alpha(opacity="+value+")";
	el.style.opacity=(value/100);
	el.style.MozOpacity=(value/100);
	el.style.KhtmlOpacity=(value/100);
};

UI.Modal.self={};
UI.Modal.onload=function(){
	UI.$('UIModalL').style.display='none';
	var pos=UI.getScroll();
	UI.Modal.center(UI.$('UIModalF'));	
	if(UI.Modal.self.options.type=='image')
	{
		UI.$('UIModalImage').style.display='block';
		UI.resizeImage(UI.$('UIModalImage'),pos.width,pos.height);	
	}
	else 
	{
		UI.$('UIModalIframe').style.display='block';
	}
	UI.Modal.center(UI.$('UIModalF'));
};
UI.Modal.print=function(){
	var d=document.createElement('div');
	var s='';
	s+='<div id="UIModalB" style="z-index:99998;width:100%;height:100%;position:absolute;left:0px;top:0px;display:none;background-color:#000;"></div>';
	s+='<div id="UIModalF" style="z-index:99999;position:absolute;display:none;"></div>';
	s+='<div id="UIModalL" style="z-index:99999;display:none;position:absolute;border:2px solid gray;">로딩중..</div>';
	d.innerHTML=s;
	document.getElementsByTagName('body')[0].appendChild(d);		
};
UI.Modal.setB=function(){
	if(UI.$('SearchCategory')) UI.$('SearchCategory').style.display='none'; //selectbox추가
	var w=UI.$('UIModalB');
    var htmlDoc = document.getElementsByTagName("html")[0];
    var Bw = htmlDoc.scrollWidth;
    var Bh = htmlDoc.scrollHeight;
    w.style.width = Bw+"px";
    w.style.height = Bh+"px";
	w.style.display='block';
};
UI.Modal.center=function(el){
	el.style.display='block';
	var pos=UI.getScroll();
	el.style.left=pos.width/2-el.offsetWidth/2+pos.left+'px';
	el.style.top=pos.height/2-el.offsetHeight/2+pos.top+'px';
};
UI.Modal.reset=function(){
	UI.Modal.self=null;
	UI.$('UIModalF').innerHTML='';
	UI.setOpacity(UI.$('UIModalB'),0);
	UI.$('UIModalB').style.display='none';
	UI.$('UIModalF').style.display='none';
	UI.$('UIModalL').style.display='none';
	if(UI.$('SearchCategory'))
		UI.$('SearchCategory').style.display='block';
	UI.delEvent(window,'resize',UI.Modal.onresize);
	UI.delEvent(window,'scroll',UI.Modal.onscroll);
};
UI.Modal.onresize=function(){
	var pos=UI.getScroll();
	if(UI.Modal.self.options.type=='image') UI.resizeImage(UI.$('UIModalImage'),pos.width,pos.height);
	UI.Modal.center(UI.$('UIModalF'));
	UI.Modal.setB();
};
UI.Modal.onscroll=function(){
	UI.Modal.onresize();
};

UI.Ajax = function(options) {
	this.options={
		method:'GET',
		param:'',
		onComplete:null,
		onError:null,
		asynchronous: true,
		contentType: 'application/x-www-form-urlencoded',
		encoding:'UTF-8',
		autoSend:true		
	}
	Object.extend(this.options, options);
	if(this.options.url && this.options.autoSend == true ) this.send();
};

UI.Ajax.prototype={
	getReq:function(){
		var req=null;
		try { req = new XMLHttpRequest(); }
		catch(e){
			try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
			catch(e){
				try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
				catch(e) { }
			}
		}
		return req;
	},
	send:function(){
		this.req = this.getReq();	
		var op=this.options;
		var url=op.url;
		var param=op.param;
		var method=op.method.toUpperCase();
		if(method=='GET' && param) url=url+"?"+param;
		this.req.open(method, url, op.asynchronous);
		this.req.setRequestHeader('Content-Type', op.contentType+';charset='+op.encoding);
		
		var self = this;
		this.req.onreadystatechange = function() { self.onStateChange.call(self) }
		this.req.send(method=='POST'?param:null);
	},
	onStateChange: function() {
		if(this.req.readyState==4){
			if(this.req.status=="200") this.options.onComplete(this.req);
			else {
				if(this.options.onError) this.options.onError(this.req);
				else alert("서버에러입니다! 잠시후에 다시 시도하세요! "+this.req.status);
			}				
		}
	}
};

/* 리스트 좌우 롤링
    1. html display block/none
        : template 값이 없어야함. 
    2. get data
        : template 꼭 있어야함. 외부에서 data 가져와야 할 경우에는 reqUrl 있어야 함. 
        <data format :: json 기반 string>
            "{'tot':50,'list':[[1argument,2argument,...],[1argument,2argument,...],...]}";
        <template format>
            '#{_0}, #{_1}, ...
    * TO DO
        : ajax 통신 
*/
UI.ListRoll = function(id, _opt) {
    this.listEl = UI.$(id),
    this.opt = {
    	init : true,			// 생성시 init() 할것인가
        data : [],              // data가 있을 경우
        reqUrl : null,          // data 요청할 url
        template : null,        // data 입힐 html
        type : (!_opt.template) ? "display" : "process",
        listTag : "LI",         // display block, none만 할때에 각 항목 구분 태그 
        amount : 4,         // 한페이지당 보여질 개수
        viewList : false,   // false : 무시, true : amount 개수에 관계 없이 모두 보여줌
        defaultIdx : 0,     // 초기 선택
        prevId : null,
        nextId : null,      
        loop : false,
        sort : 'asc',		// asc : 앞에서부터 정렬, desc : 뒤에서부터 정렬
        perGroup : true     // 이동단위 (true:그룹/false:아이템)
    }
    if(!this.opt.perGroup) this.opt.loop = false;       // 한칸씩 이동할때에는 loop 할수 없음
    Object.extend(this.opt, _opt);
    if(this.opt.init) this.init();
}
UI.ListRoll.prototype = {
    storage : [],
    init : function() {
        if(!this.listEl) return false;
        this.idx = this.opt.defaultIdx;     

        this.prevEl = UI.$(this.opt.prevId);
        this.nextEl = UI.$(this.opt.nextId);
        if(this.prevEl) {UI.addEvent(this.prevEl, "click", this.move.bind(this));}
        if(this.nextEl) {UI.addEvent(this.nextEl, "click", this.move.bind(this));}     
 
        this.set();
    },
    set: function() {
        if(this.opt.type == 'display') {            
            this.listAry = this.listEl.getElementsByTagName(this.opt.listTag);
            this.totIdx = this.listAry.length;  
        } else {    // process
            if(this.opt.data.length==0) {
            } else {
                this.opt.data = this.evalJson(this.opt.data);
                if(this.opt.data.tot) this.totIdx = this.opt.data.tot;
                else this.totIdx = this.opt.length;
                var _list = (this.opt.data.list) ? this.opt.data.list : this.opt.data;
                this.putData(_list);
            } 
        }       
        this.setLastIdx();
    },
    setLastIdx : function() {
        this.lastIdx = (this.opt.perGroup)? Math.ceil(this.totIdx/this.opt.amount)-1 : this.totIdx - this.opt.amount;
        this.totPage = Math.ceil(this.totIdx/this.opt.amount);
        if(this.idx > this.lastIdx) { return false; }
    },
    render : function() {           
        if(this.opt.type == 'display') this.display();
        else this.dataChk();
        
        this.isBtn();
    },
    display : function() {
    	if(this.opt.sort == "asc") {
	        var start = (this.opt.perGroup) ? this.idx*this.opt.amount : this.idx;
	        var end = (this.opt.perGroup) ? (this.idx*this.opt.amount) + this.opt.amount : this.idx + this.opt.amount;
	    } else {		// desc sort
	        var start = this.totIdx - (this.opt.amount * (this.totPage-this.idx));
	        var end = start + this.opt.amount;
	    }

        if(!this.opt.viewList) {
            for ( var i=0; i<this.totIdx ; i++ ){
                if( i>=start && i<end ){this.listAry[i].style.display = "block";} 
                else { this.listAry[i].style.display = "none"; }
            }
        }
    },
    move : function(evt) {
        var el = evt.target || evt.srcElement;
        if(el.id == this.prevEl.id) {
            if(!this.isPrev) return false;
            this.idx--;
            if( this.idx < 0 ){
                this.idx = (this.opt.loop) ? ((this.opt.perGroup) ? this.lastIdx : this.totIdx) :0;
            }
        } else {    //next
            if(!this.isNext) return false;
            this.idx++; 
            if( this.idx > this.lastIdx ){
                this.idx = (this.opt.loop) ? 0: this.lastIdx;               
            }
        }
        
        this.render();
    },
    isBtn : function() {
        if(!this.opt.loop) {        
            if(this.idx<=0) this.isPrev = false;
            else this.isPrev = true;
            if(this.idx>=this.lastIdx) this.isNext = false;
            else this.isNext = true;        
        } else {
            this.isPrev = true;
            this.isNext = true;
        }
        this.onOff(this.idx);
    },    
    clickIdx : function(idx) {
        this.idx = idx;
        this.render();
    },
    onOff : function(el, val) {
        if(this.isPrev) this.applyStyle(this.prevEl, 'on');
        else this.applyStyle(this.prevEl, 'off');
        if(this.isNext) this.applyStyle(this.nextEl, 'on');
        else this.applyStyle(this.nextEl, 'off');
    },    
    applyStyle : function(el, val) {
        var pos = UI.getStyle(el,"backgroundPosition").split(' ');  
        if(val == 'on') {
        	el.style.backgroundPosition = pos[0] + ' 0px';
        	el.style.cursor = 'pointer';
        	el.disabled = false;
        } else {
        	el.style.backgroundPosition = pos[0] + ' 100%';
        	el.style.cursor = 'default';
        	el.disabled = true;
        }
    },    
    evalJson : function(jsonStr) {
        return (new Function('', 'return ' + jsonStr + ';'))();
    },
    eval : function(data) {
        var _rp = '';
        for(var i=0,len=data.length; i<len; i++) {
            _rp += '.replace(/#{_'+i+'}/g, "'+data[i]+'")';
        }
        return eval('this.opt.template'+_rp);
    },

    putData : function(_list) {
        var _idx = 0;
        if(this.totIdx<=_list.length) this.storage = _list;
        else {
            for(var i=0,len=_list.length; i<len; i++) {
                _idx = (this.idx * this.opt.amount) + i;
                this.storage[_idx] = _list[i];
            }
        }
    },

    dataChk : function() {
        var _s = this.idx * this.opt.amount;
        var _e = (this.totIdx <= (this.idx * this.opt.amount) + this.opt.amount) ? this.totIdx : (this.idx * this.opt.amount) + this.opt.amount;
        var _isdata = true;
        for(var c=_s; c<_e; c++) {
            if(!this.storage[c]) {
                _isdata = false;
                continue;
            }
        } 
        if(_isdata) {
            //  have data
        } else {
            // get data
            // data make start ================= TO DO ajax
            var _dd = [];
            _dd['tot'] = 50;
            _dd['list'] = [];
            var _str = null;
            for(var i=0;i<5;i++) {
                _str = (this.idx * this.opt.amount) + i;            
                _dd['list'].push([_str.toString()+_str.toString()+_str.toString(),_str]); 
            }
            // data make end==================
            var _list = (_dd['list']) ? _dd['list'] : _dd;
            if(_dd['tot']) this.totIdx = _dd['tot'];
            this.setLastIdx();
            this.putData(_list);
        }
        this.draw();
    },
    draw : function() {
        var _html = '';
        var _s = this.idx * this.opt.amount;
        var _e = (this.idx * this.opt.amount) + this.opt.amount;
        for(var i=_s; i<_e; i++) {
            _html += this.eval(this.storage[i]);
        }
        this.listEl.innerHTML = _html;
    }
}


/* for checkbox list  
    @ form = form's name
    @ checkbox = checkbox's name
*/
UI.CheckBoxList = function( form, checkbox ){
    this.form = eval('document.'+form);
    this.checkbox = eval('document.'+form + '.' + checkbox);
    this.init();
    
}
UI.CheckBoxList.prototype = {
    flag : false,
    
    init : function() {
        if(!this.checkbox) return false;
        if(this.checkbox.constructor != Object) {
            var chk = [];
            chk.push(this.checkbox);
            this.checkbox = chk;
        }
    },

    allCheck : function() {
        if(!this.checkbox) return false;
        this.flag = (this.flag) ? false : true;
        for(var i=0,len=this.checkbox.length; i<len; i++) {
            this.checkbox[i].checked = this.flag;
        }
    },
    
    getAllValue : function() {
        if(!this.checkbox) return false;
        var val = [];
        for(var i=0,len=this.checkbox.length; i<len; i++) {
            val.push(this.checkbox[i].value);
        }
        return val;
    },
    
    getValue : function() {
        if(!this.checkbox) return false;
        var val = [];
        for(var i=0,len=this.checkbox.length; i<len; i++) {
            if(this.checkbox[i].checked == true && this.checkbox[i].value != "" && this.checkbox[i].value != "undefined") val.push(this.checkbox[i].value);
        }
        return val;
    }
}
/*
UI.commonPopup=function(id) { 
	window.open("http://music.daum.net/popup/popupSample.do?popupType="+id,"musicPopup","top=0, left=0,width=10, height=10,resizable=no");
};
* */
UI.Popup=function(url, name, opt) {
	if(!url) url = "";
	if(!name) name = "musicPopup";
	if(!opt) opt = "width=400, height=260, resizable=yes";
	var winMusicPopId = window.open(url,name,opt);
	winMusicPopId.focus();
	return winMusicPopId;
};
/**
 * 팝업 내에서 opener로 링크 연결, opener가 없으면 새창으로 연결
 * @param {String}  url 연결될 URL
 * @param {Boolean} 완료시 팝업창 close 여부
 */
UI.openerWin = function(url, isClose) {  
    try {
    	// 열려진 팝업창이 2번째 이상의 팝업이라면 부모가 팝업창이므로 새창으로 연결.
        if( opener.top.opener ){
            window.open(url);           
        } else {
            if(url) opener.location.href = url;
            else opener.location.reload();
        }
    } catch(e) {
    	// opener객체가 없으면 새창으로 연결.
        window.open(url);
    }
    // 현재창 닫기 여부
    if(isClose) self.close();
};

UI.resizePopup = function( obj ) { 
	if(!obj)obj = document.getElementsByTagName('HTML')[0];
	var doc = document.getElementsByTagName('HTML')[0];
	var clientW = doc.clientWidth||doc.scrollWidth;
	var clientH = doc.clientHeight||doc.scrollHeight;
	var offsetW = obj.offsetWidth||obj.scrollWidth;
	var offsetH = obj.offsetHeight||obj.scrollHeight;
	//alert( clientW + " : " + clientH + " / " + offsetW + " : " + offsetH )   
    var gapWidth = offsetW - clientW ;
    var gapHeight = offsetH - clientH;
    if(gapWidth || gapHeight){
        window.resizeBy(gapWidth,gapHeight);
    }
};

UI.resizeImage=function(img,w,h){
	var t = new Image();
	t.src=img.src;	
	if(t.width==0 || t.height==0) return;
	if(t.width>w || t.height >h)
	{
		img.width=w;img.height=h;
		if((t.width/w) > (t.height/h) )	img.height=Math.round(t.height * (w / t.width));
		else img.width = Math.round(t.width *  (h / t.height));
	}
	else
	{
		img.width=t.width;
		img.height=t.height;
	}
	if(img.width==0 || img.height==0) setTimeout(function(){UI.resizeImage(img,w,h)},500);
};
UI.getScroll=function () {
	if(document.all && typeof document.body.scrollTop != "undefined")
	{
		var cont=document.compatMode!="CSS1Compat"?document.body:document.documentElement;
		return {left:cont.scrollLeft, top:cont.scrollTop, width:cont.clientWidth, height:cont.clientHeight}
	}
	else 
		return {left:window.pageXOffset, top:window.pageYOffset, width:window.innerWidth, height:window.innerHeight}
};

/**
 * 뮤직서비스 전용
 */
var Music = {};
/* 그냥 팝업을 띄우거나, 팝업에서 다른 팝업을 띄우거나 할 경우에 쓰면 좋음. */
Music.newWin = function(url, name, option, close) {
	if(name == "_blank") var _newWin = window.open(url, name);
	else var _newWin = window.open(url, name, option);
	
	if(_newWin) _newWin.focus();
	else alert("팝업이 차단되어 있습니다.\n차단된 화면이 결제 관련 화면인 경우, 정상결제가 이뤄지지 않을 수 있으니\n반드시 팝업 차단 설정을 해지 후 이용해 주세요.");
	
	if(name == "_blank" || close) self.close();
	
	return _newWin;
};

/**
 *  리스트형 테이블에서 버튼 액션 제어
 *  @param {String} 리스트의 고유 Id값
 *  @constructor
 */
Music.ControlListButton = function(){
    this.checkedList = [];
    this.init();
};
Music.ControlListButton.prototype = {
    init : function(){
		this.setCheckboxName("checkBoxItem");// 기본값 : checkBoxItem
    },
    setCheckboxName : function( name ){// 페이지 내 지정된 이름의 체크박스를 배열로 저장 (this.checkbox) 
        this.checkBoxName = name;
        this.checkbox = document.getElementsByName(this.checkBoxName);
    },
    allCheck : function( ctrlCheckBox ) {
        if(!this.checkbox) return false;
        var _flag = false;
        if( typeof( ctrlCheckBox ) == "object" ){
            _flag = ctrlCheckBox.checked;
        } else if ( typeof( ctrlCheckBox ) == "boolean" ){
            _flag = ctrlCheckBox;
        }
        
        for(var i=0,len=this.checkbox.length; i<len; i++) {
        	if( this.checkbox[i].disabled == false ){
                this.checkbox[i].checked = _flag;
        	}
        }
    },
    // 해당 idstr 값 가진 체크박스 선택하기
    idAllCheck : function( obj, idstr ) {
        if(!this.checkbox) return false;
        var _flag = obj.checked;
        
    	for(var i=0,len=this.checkbox.length; i<len; i++) {
    		if( this.checkbox[i].id.indexOf(idstr) > -1 ) {
    			this.checkbox[i].checked = _flag;
    		}
    	}
    },
    // 모든 체크박스 값 리턴
    getAllValue : function() {
        if(!this.checkbox) return false;
        var val = [];
        for(var i=0,len=this.checkbox.length; i<len; i++) {
            if( this.checkbox[i].value != "on" ){ val.push(this.checkbox[i].value); }
        }
        return val;
    },  
    // 선택된 체크박스 값 리턴
    getValue : function() {
        if(!this.checkbox) return false;
        var val = [];
        for(var i=0,len=this.checkbox.length; i<len; i++) {
            if( this.checkbox[i].value != "on" && this.checkbox[i].checked == true) { val.push(this.checkbox[i].value); }
        }
        return val;
    },
    // 유효한 체크박스 카운트 리턴 ( 선택대상이 없으면 false 리턴 )
    getEnableCheckboxCount : function(){
        if(!this.checkbox) return false;
        var cnt = 0;
        for(var i=0,len=this.checkbox.length; i<len; i++) {
            if( this.checkbox[i].value != "on" ) cnt = cnt + 1;
        }
        if( cnt > 0 ){
            return cnt;
        } else {
            return false;
        }
    },   
    // 선택된 체크박스의 특정 attribute 값이 있는것만 리턴   
    getAttrValue : function(attr) {
    	if(!this.checkbox) return false;
        var val = [];
        for(var i=0,len=this.checkbox.length; i<len; i++) {
            if( this.checkbox[i].value != "on" && this.checkbox[i].checked == true) { 
            	var attr_value = this.checkbox[i].getAttribute(attr); 
            	if(attr_value != "") val.push(attr_value); 
            }
        }
        return val;
    },     
    goAction : function( mode, el ){
    	if(el) this.objBtn = el;
		this.checkedList = this.getValue();
		switch(mode) {
		    case "chk_mp3" : this.mp3Items(); break;
		    case "chk_mp3_down" : this.mp3Down(); break;
		    case "chk_mp3_video" : this.mp3Video(); break;
		    case "chk_mp3_album" : this.mp3Group('album'); break;
		    case "chk_mp3_public" : this.mp3Group('public'); break;
		    case "chk_listen" : this.listenItems(); break;
		    case "all_listen" : this.listenItems('all'); break;
		    case "chk_bgm" : this.bgmItems(); break;
		    case "chk_bgm_video" : this.bgmVideo(); break;
		    case "chk_bgm_album" : this.bgmGroup('album'); break;
		    case "chk_bgm_public" : this.bgmGroup('public'); break;
		    case "chk_my" : this.myItems(); break;
		    case "chk_my_album" : this.myGroup('album'); break;
		    case "all_view" : this.viewItems('all'); break;
		    case "chk_view" : this.viewItems(); break;
		    case "chk_mark_mv" : this.markItems(); break;
		    case "chk_del" : this.delItems(); break;
		}
    },
    cartErrorMsg : function(type) {
    	Music.message( type )
    },
    // disable인 리스트 제외
    getAbleValue : function(data, id) {
    	var val = [];
    	for(var i=0,len=data.length; i<len; i++) {
    		if(UI.$(id+'_'+data[i])) {
    			if(UI.$(id+'_'+data[i]).disabled == false) val.push(data[i]);
    		} else {
    			val.push(data[i]);
    		}
    	}
    	return val;
    },
    // 삭제
    delItems : function(){
		var val = this.getValue();
		if( val.length == 0 ){
			if(_DEL_ERR) alert(_DEL_ERR);
			else this.cartErrorMsg();
			return false;
		}
		try{
			if(!confirm(_DEL_MSG)) return false;
		}catch(e){}
		
		Music.rebuildForm(val, "itemId", _DEL_ACTION);
    },
    // mp3 구매/선물
    mp3Items : function(val, whr) {
    	if(!val) { var val = this.getValue(); }
    	val = this.getAbleValue(val, 'mp3');		
    	if( val.length == 0 ){
    		this.cartErrorMsg('cart');
    		return false;
    	}
    	openLayerController("MP3", this.objBtn, val );
    },
    // mp3 다운
    mp3Down : function(val) {
        if(!val) { var val = this.getValue(); } 
        val = this.getAbleValue(val, 'mp3');        
        if( val.length == 0 ){
            this.cartErrorMsg('down');
            return false;
        }
        Music.openDownloader( val );
    },
    // mp3 다운 (앨범,공개앨범 리스트)
    mp3Group : function( group ){
    	this.getGroupList(group, this.mp3ItemList.bind(this));
    },
    mp3ItemList : function( req ){
    	eval(req.responseText);
    
    	for(var i=0, len=Songs.length; i<len; i++) {
    		this.itemGroup.push(Songs[i]['SongId']);
    	}    	
		this.itemLen--;
    	if(this.itemLen==0) {	// 마지막 앨범일때 장바구니 띄움
    		this.mp3Items(this.itemGroup, 'album');
    	}    	
    },
    // mp3 (뮤직비디오 songid 있는 곡만)
    mp3Video : function() {
    	var val = this.getAttrValue("songid");
        this.mp3Items(val);
    },
    // 앨범id로 음원 있는 songid 가져와서 callback
    getGroupList : function(group, callback) {	// group : album or public
    	var val = this.getAbleValue(this.getValue());
    	var url = "";
    	var param = "";
    	if(val.length == 0) {
    		this.cartErrorMsg('cart');
    		return false;
    	}
    	if(group == "album") url = "http://music.daum.net/json/playSongList.do";
    	else url = "http://music.daum.net/json/publicAlbumSongList.do";
  	
 		this.itemGroup = [];
 		this.itemLen = val.length;
   
   		for(var i=0, len=val.length; i<len; i++) {
			var param = "albumId=" + val[i];
			if( group != "album") {
                param += "&aodEnabledOnly=true";			 
			}
			new UI.Ajax({url:url,param:param,onComplete:callback});
   		}
    },    
    // 배경음악 
    bgmItems : function(val, whr){
		if(!val) { var val = this.getValue(); }
		val = this.getAbleValue(val, 'bgm');
		if(val.length == 0) {
    		this.cartErrorMsg('cart');
    		return false;
    	}
		openLayerController("BGM", this.objBtn, val );
    },
    bgmGroup : function(group){
    	this.getGroupList(group, this.bgmItemList.bind(this));
    },
    bgmItemList : function( req ){
    	eval(req.responseText);
    	for(var i=0, len=Songs.length; i<len; i++) {
    		this.itemGroup.push(Songs[i]['SongId']);
    	}    	
		this.itemLen--;
    	if(this.itemLen==0) {	// 마지막 앨범일때 장바구니 띄움
    		this.bgmItems(this.itemGroup);
    	}    	
    },
    // bgm (뮤직비디오 songid 있는 곡만)
    bgmVideo : function() {
    	var val = this.getAttrValue("songid");
        this.bgmItems(val);
    },
    // MY앨범담기
    myItems : function(val){
		if(!val) { var val = this.getValue(); }
		if(val.length == 0) {
    		this.cartErrorMsg('my');
    		return false;
    	}
        var url = '/my/album/add.do';
        UI.Popup("", "addPop");
		Music.rebuildForm(val, "itemId", url, "addPop");

    },
    myGroup : function( group ) {
    	this.getGroupList(group, this.myItemList.bind(this));
    },
    myItemList : function( req ){
    	eval(req.responseText);

    	for(var i=0, len=Songs.length; i<len; i++) {
    		this.itemGroup.push(Songs[i]['SongId']);
    	}  
		this.itemLen--;
    	if(this.itemLen==0) {	// 마지막 앨범일때 내앨범 담기 팝업 띄움 
    		this.myItems(this.itemGroup, 'album');
    	}    	
    },
    // 뮤직비디오찜(뮤비찜)
    markItems : function(){
        var val = this.getValue();
        bookmarkVideo( val );
        /*
        var url = '/my/bookmark/video/regadd.do';
        UI.Popup("", "addPop")
        Music.rebuildForm(val, "itemId", url, "addPop");
        */
    },
    // 듣기
    listenItems : function( mode ){
		if(mode == 'all') {
            this.allCheck(true);
            var val = this.getAbleValue(this.getAllValue(), 'listen');
        } else {
        	var val = this.getAbleValue(this.getValue(), 'listen');
        }
        if(val.length == 0) {
    		this.cartErrorMsg();
    		return false;
    	}
        Music.openPlayer( val );
    },
    // 뮤직비디오 보기
    viewItems : function( mode ){
        if(mode == 'all') {
        	this.allCheck(true);
        }   
        var val = this.getAbleValue(this.getAttrValue("vclipid"), 'video');  
        if(val.length == 0) {
       		this.cartErrorMsg('video');
       		return false;
       	}
        Music.openMvPlayer(val);  
    }
};

Music.message = function( type ){
    switch(type) {
        case "play" : alert('선택하신 곡이 없거나,\n선택하신 모든 곡의 음원이 없어 재생을 할 수 없습니다.\n\n확인 후 이용해 주세요.'); break;
        case "cart" : alert('선택하신 곡이 없거나,\n선택하신 모든 곡의 음원이 없어 장바구니에 담을 수 없습니다. \n\n확인 후 이용해 주세요.'); break;
        case "video" : alert('선택하신 뮤직비디오가 없습니다. \n\n확인 후 이용해 주세요.'); break;
        case "my" : alert('선택하신 곡이 없어 MY앨범에 담으실 수 없습니다. \n\n확인 후 이용해 주세요.'); break;
        case "down" : alert('PC에 다운로드 받을 곡을 선택 후 이용해 주세요.'); break;
        default : alert('선택하신 곡이 없거나,\n선택하신 모든 곡의 음원이 없습니다. \n\n확인 후 이용해 주세요.'); break;
    }       
}

/**
 * 이 정보에 직접 참여하기 팝업
 * @param {String} menuName 페이지 구분, tiles에서 분류된 $menuName
 * @param {String} id       해당 타입의 ID
 * @author maart
 */
Music.openReportPop = function( menuName, id ){
	var objType = "", objInfo = "";
	var objId = id;
    switch( menuName ){
        case "artistdetail":
            objType = "AR";
            break;
        case "albumdetail":
            objType = "AL";
            break;
        case "songdetail":
            objType = "SO";
            break;
        case "songreport":
            objType = "SO";
            objInfo = "E";
            break;
    }
    if( objType != "" ){
        UI.Popup( "http://music.daum.net/popup/userReport.do?objType="+objType+"&objId="+objId+"&infoType="+objInfo, "musicReport" )
    }
    
};

var playerWinHandle = null;
var mvPlayerWinHandle = null;
var downloaderWinHandle = null;
Music.openPlayer = function( songId ){
	if( !UI.getBrowser().ie ){
        alert("Daum뮤직 플레이어는 윈도우즈 XP 이상, \n인터넷 익스플로어 6.0 이상에서만 정상 사용 가능합니다.");
        return false;
	}
	UI.preventDefault();
	// xman 실행
	if( !UI.$("playerHandleAx") ){
        var template = $C("div");
        template.id = "playerHandleAx";//'<div class="conAx" id="playerHandleAx" name="playerHandleAx"></div>';
        template.style.display = "none";
        var objBase = UI.$("Daum_hd")||document.body;
        objBase.appendChild( template );
        var obj = getPlayerAx("PlayerHandle");
        obj.width=0;
        obj.height=0;     
        daumActiveXman(obj,'playerHandleAx');
    }
    if( typeof( PlayerHandle ) == "undefined" ){
     	return false;
    }
    
    // 팝업 기본값
    var url = "http://music.daum.net/player/player.do";
    var winName = "daumMusicPlayer";
    var winOpt = "width=350,height=597,resizable=no";
    if( screen.height < 768 ){
        winOpt = "width=367,height=597,resizable=no,scrollbars=yes";
    }
      
    // 입력된 songId가 배열형이 아니면 배열로 변경~
    if( typeof( songId ) != "object" ){
    	if( !!songId  ) songId = [ songId ];
    	else songId = [];
    }

	// 선택된 리스트를 플레이어에 추가
    if( PlayerHandle.IsRunPlayer() == 0 ){//최초실행 
    	UI.setCookie("daumMusicPlayerInit", "true", 0, "/", ".daum.net");
    	var param = "";
    	for( i=0, cnt=songId.length; i<cnt; i++ ){
    	   if(i>0) param += "&";
    	   param += "songIdList="+songId[i];
    	}
    	if( songId.length == 0 ) param = "";
    	else param = "?"+param;
        playerWinHandle = UI.Popup( url+param, winName, winOpt);
    } else {// 실행중
        playerWinHandle = UI.Popup( "", winName, winOpt);
        try {
            if( songId.length > 0 ) playerWinHandle.AddPlayerPlay( songId );
        } catch( e ){
        	playerWinHandle = UI.Popup( url+"?"+param, winName, winOpt);
        }
    }
    
    // 플레이어창에 포커스
    if( playerWinHandle != null ) playerWinHandle.focus();
};

Music.reloadPlayerFrame = function(){
	UI.preventDefault();
	
	// xman 실행
    if( !UI.$("playerHandleAx") ){
        var template = $C("div");
        template.id = "playerHandleAx";//'<div class="conAx" id="playerHandleAx" name="playerHandleAx"></div>';
        template.style.display = "none";        
        document.body.appendChild( template );
        var obj = getPlayerAx("PlayerHandle");
        obj.width=0;
        obj.height=0;
        daumActiveXman(obj,'playerHandleAx');
    }
    if( typeof( PlayerHandle ) == "undefined" ){
        return false;
    }
    
    // 플레이어가 실행중일때만 적용 
    if( PlayerHandle.IsRunPlayer() == 0 ){
        return false;
    } else {
    	playerWinHandle = UI.Popup( "", winName, winOpt);
    	playerWinHandle.reloadPlayerFrame();
    }
};

Music.openMvPlayer = function( mvId ){
    var url = "http://music.daum.net/player/videoPlayer.do";
    var winName = "daumMvPlayer";
    var winOpt = "width=891,height=657,resizable=no";
    if( screen.height < 768 ){
        winOpt = "width=908,height=657,resizable=no,scrollbars=yes";
    } 

    mvPlayerWinHandle = UI.Popup( "", winName, winOpt);
    if( typeof( mvId ) != "object" ){
        // 선택된 1개만 뮤비플레이어에 추가
        //alert( "선택된 1곡 뮤비플레이어 팝업 오픈 : " + mvId );
        try {
       		//document.location.href="#add";
            mvPlayerWinHandle.addPlayListPlay( mvId );
            //mvPlayerWinHandle.tabMvPlayer.on('playlist'); 새로고침 되는 형태이므로 탭 활성화 필요없음
        } catch( e ) {
        	//document.location.href="#pop";
            var param = "?videoId="+mvId;
            UI.setCookie("daumMusicMvPlaylist", "", 1, "/");
            mvPlayerWinHandle = UI.Popup( url+param, winName, winOpt);
        }
    } else {
        // 선택된 리스트를 뮤비플레이어에 추가
        //alert( "선택된 "+mvId.length+"곡 뮤비플레이어 팝업 오픈" );
        try {
        	var currentPlaylistLength = mvPlayerWinHandle.playListCtrl.playList.length;
        	for ( var i=0, cnt=mvId.length; i<cnt ; i++){
                mvPlayerWinHandle.addPlayList( mvId[i] );
        	}
            //mvPlayerWinHandle.tabMvPlayer.on("playlist");
        	if( mvId.length > 0 ){
                mvPlayerWinHandle.playSelectIndex( mvId[0] );
        	}
        } catch( e ) {
            var param = "";
            for ( var i=0, cnt=mvId.length; i<cnt ; i++){
            	if(i>0) param += "&";
            	param += "videoIdList="+mvId[i];
            }
            UI.setCookie("daumMusicMvPlaylist", "", 1, "/");
            mvPlayerWinHandle = UI.Popup( url+"?"+param, winName, winOpt);
        }
    }
    if( mvPlayerWinHandle != null ) mvPlayerWinHandle.focus();
};

Music.openDownloader = function( songId ){
	if( !UI.getBrowser().ie ){
        alert("Daum뮤직 다운로더는 윈도우즈 XP 이상, \n인터넷 익스플로어 6.0 이상에서만 정상 사용 가능합니다.");
        return false;
	}
	UI.preventDefault();
    var url = "http://music.daum.net/player/downloader.do";
    var winName = "daumDownloader";
    var winOpt = "width=701,height=557,resizable=no";
    if( screen.height < 768 ){
        winOpt = "width=720,height=557,resizable=no,scrollbars=yes";
    }    
    var songIdList = [];
    downloaderWinHandle = UI.Popup( "", winName, winOpt);
    
    if( typeof( songId ) == "string"){
    	songIdList.push( songId );
    } else {
    	songIdList = songId;
    }
    
    try {
        downloaderWinHandle.addDownloadItem( songIdList );
    } catch(e){
    	var param = "";
    	for ( var i=0, cnt=songIdList.length; i<cnt ; i++){
            if(i>0) param += "&";
            param += "songIdList="+songIdList[i];
        }
        downloaderWinHandle = UI.Popup( url+"?"+param, winName, winOpt);
    }
    if( downloaderWinHandle != null ) downloaderWinHandle.focus();
};

// data : value[], name : input's name, action : form's action url, open : if popup, popup's name. else, null
Music.rebuildForm = function(data, name, action, open) {
   	if(data.length==0) {
      	alert("선택된 목록이 없습니다.");
      	return false;
    }
    if(data.constructor == Array) {
    	var param = data;
    } else {
    	var param = [];
    	param[0] = data;
    }
   	var form = document.createElement("FORM");
	for(var i=0,len=param.length; i<len; i++) {
		var input = document.createElement("input");
		input.value = param[i];
		input.type = "hidden";
		input.name = name;
		form.appendChild( input );
	}
	document.body.appendChild(form);
	form.method = "post";
	form.action = action;
	if(open) {
		form.target = open;	
	} 
	if(UI.getBrowser().ie_ver == '6') {		// ie6이슈 : 다른 도메인간 하위 프레임 사용안함일 경우, 팝업이 about:blank -> music.daum.net~~ 페이지로 이동 시간차 
		try {
			form.submit();
		} catch(e){
			setTimeout(function() {form.submit()}, 500);
		}
	} else {
		form.submit();
	}
};
 
Music.makeInputTag = function(form, name, value, type) {
	if(!type) type = "hidden";
	if(UI.getBrowser().ie) {
		var input = document.createElement("<input type=\"" + type + "\" name=\"" + name + "\" value=\"" + value + "\">");   
	} else {
		var input = document.createElement("input");
		input.value = value;
		input.type = type;
		input.name = name;
	}
	form.appendChild(input);
};
Music.checkLogin = function(){
   	if( confirm("먼저 로그인 하셔야 합니다.\n로그인 페이지로 이동 하시겠습니까??") == true ){
    	var url = "http://www.daum.net/Mail-bin/login.html?url="+ escape( top.location.href );
    	top.location.href = url;
    }
}
Music.popupLogin = function( type ){
	var redirUrl = "http://music.daum.net/player/loginConfirmRedirect.html";
	if( type != undefined ){
        redirUrl += "?action="+type;
	}
	redirUrl = encodeURIComponent(redirUrl);
	
	return UI.Popup("http://www.daum.net/Mail-bin/login.html?category=music&popup=1&url="+redirUrl,"musicLoginPopup");
}
// 배경음악 미리듣기
Music.openPreview = function(val){
	if( !UI.getBrowser().ie ){
        alert("Daum뮤직 플레이어는 윈도우즈 XP 이상, \n인터넷 익스플로어 6.0 이상에서만 정상 사용 가능합니다.");
        return false;
	}
	if(!val){return false;}
	var url = "http://music.daum.net/player/preview.do";
	if( isNaN( val ) ){
		url += "?BGMLinkId="+val;
	} else {
        url += "?songIdList="+val;
	} 
	UI.Popup(url, "listen", "width=400, height=260, resizable=no");
}


// 단순링크
function goURL(url) {
	location.href=url;
}

// 가사보기
function lyricMini(id) {
	location.href="http://music.daum.net/song/song.do?songId="+id;
}

// 가사등록
function regLyric(id,title,infoType) {
	// 관리자용.. 이거 나중에 처리 다 되면 alert은 제거해 주셈;
	if( !infoType ){ alert( "infoType을 설정해 주세요"); }
	var url = "/popup/regLyric.do?objName="+encodeURIComponent(title)+"&objId="+id+"&infoType="+infoType;
	UI.Popup(url, "regLyric", "width=400, height=260, resizable=yes");
}
// 앨범정보
function albumMini(id) {
	location.href="http://music.daum.net/album/album.do?albumId=" + id;
}
// 곡명
function titleSong(id, isabled) {
	if(isabled) listenSong(id);
	else Music.message('play');
}
// 곡듣기
function listenSong(id) {
	Music.openPlayer(id);
} 
// 뮤직비디오 보기
function viewVideo(id, video_id) {
	if(video_id) {
		/* 하나의 songId에 여러개의 videoId가 있을경우에 |로 구분해서 보내주던거용임  => videoId없이 songId로만 넘김 */ 
		if( video_id.indexOf("|") > -1 ){
		   video_id = null;							
		}
	}
	var url = "http://music.daum.net/song/songVideo.do?songId=" + id;
	if(video_id) url += "&videoId=" + video_id;
	if(document.location.pathname.indexOf("/player/") > -1 || document.location.pathname == "/search/player.do" || document.location.pathname == "/search/albumPlayer.do" || document.location.pathname == "/search/artistPlayer.do" ) {
		window.open(url);
	} else {
		location.href = url;
	}
	//Music.openMvPlayer(id);
}
// 뮤직비디오찜 ( 뮤비찜 )
function bookmarkVideo( id ){
    var url = '/my/bookmark/video/regadd.do';
    if( id.length > 0 ) {
	    UI.Popup("", "addPop", "width=400, height=260, resizable=yes");
	    Music.rebuildForm(id, "itemId", url, "addPop");
    } else {
    	alert( "찜할 뮤비를 선택해 주세요.");
    }
}
function viewArtistBBS(id) {
    if(!id){
        return false;
    }
    location.href="http://bbs.music.daum.net/gaia/do/music/artist/list?searchKey=meta&searchValue=2%3A"+id+"&bbsId=M002";
} 
function viewAlbumBBS(id) {
    if(!id){
        return false;
    }
    location.href="http://bbs.music.daum.net/gaia/do/music/album/list?searchKey=meta&searchValue=1%3A"+id+"&bbsId=M001";
} 

// 앨범상세 페이지로 이동
function goAlbumDetail( albumId, tab ){
	if( !tab ) tab = "album";
    location.href = "http://music.daum.net/album/"+tab+".do?albumId="+albumId;
}
// 아티스트상세 페이지로 이동
function goArtistDetail( artistDetailId, tab ){
	if( !tab ) tab = "artist";
    location.href = "http://music.daum.net/artist/"+tab+".do?artistDetailId="+artistDetailId;
}
// 곡상세 페이지로 이동
function goSongDetail( songId ){
    location.href = "http://music.daum.net/song/song.do?songId="+songId;
}
// 수상아이콘 > 수상 리스트로 이동
function goAwardDetail( openId, openyear, songid ) {
	location.href = "http://music.daum.net/ranking/prize.do?openId="+openId+"&year="+openyear+"&songId="+songid+"#"+songid;
}

// 100자평쓰기
function write100(type, id){
	var url = "";
	switch( type ){
	case "artist":
    	url = "http://music.daum.net/artist/artist.do?artistDetailId="+id+"#commentFrame";
		break;
    case "album":
        url = "http://music.daum.net/album/album.do?albumId="+id+"#commentFrame";
        break;
    case "song":
        url = "http://music.daum.net/song/song.do?songId="+id+"#commentFrame";
        break;
	}
	if( url != "" ){
 		  top.location.href = url;
	} 
}
 
// 앨범 id로 플레이할 곡 리스트 가져오기
function listenAlbum(id, what) {
	var param = "albumId=" + id;
	switch(what) {
		case "my" : var url = "http://music.daum.net/json/myAlbumSongList.do"; param += "&aodEnabledOnly=true"; break;
		case "public" : var url = "http://music.daum.net/json/publicAlbumSongList.do"; param += "&aodEnabledOnly=true"; break;
		default : var url = "http://music.daum.net/json/playSongList.do"; break;
	}
	new UI.Ajax({url:url,param:param,onComplete:listenSongList});
}
// 앨범에 해당하는 곡 듣기
function listenSongList(req) {
	eval(req.responseText); 
	var val = [];
	var len = Songs.length;
	if(len == 0) {
		alert('해당 앨범에 들을 수 있는 곡이 없습니다.');
		return false;
	}
	for(var i=0; i<len; i++) {
		val.push(Songs[i]['SongId']);
	}
	eval("Music.openPlayer([" + val.join(',') + "])");
}
// 앨범찜
function bookmarkAlbum(id) {
	if(id) {
		var url = '/my/bookmark/album/regadd.do?itemId=' + id;			
		UI.Popup(url, "bookmarkPop", "width=400, height=260, resizable=yes");
	}
}
// 공개앨범찜
function bookmarkPublicAlbum(id) {
	if(id) {
		var url = '/my/bookmark/publicalbum/regadd.do?itemId=' + id;			
		UI.Popup(url, "bookmarkPop", "width=400, height=260, resizable=yes");
	}
}
// MY앨범 담기
function myAlbumAdd(id) {
	if(id) {
		var url = '/my/album/add.do?itemId=' + id;			
		UI.Popup(url, "addPop", "width=400, height=260, resizable=yes");
	}
}
function mp3Mini(id, objBtn) {
    openLayerController("MP3", objBtn, id );
}  
function mp3Down(id){
    if( UI.getBrowser().ie ){
	   Music.openDownloader( id );
    } else {
		var iframe = UI.$("mp3DownloadFrame");
		if( !iframe ) {
			iframe = $C("IFRAME");
			iframe.width = "1px";
			iframe.id = "mp3DownloadFrame"
			iframe.height = "1px";
			document.body.appendChild( iframe );
		}
        iframe.src = "http://player.music.daum.net/download.do?songId="+id;
    }
}

/* val : songid's array, cart : mp3 or bgm, gift : null or 'gift' */ 
function openCartPop(val, cart, gift){
	if( cart == "mp3" ) {
		if( gift ) { var url = 'http://music.daum.net/purchase/mp3cart/regadd.do?action=GIFT'; }
		else { var url = 'http://music.daum.net/purchase/mp3cart/regadd.do'; }
	} else {
		if( gift ) { var url = 'http://music.daum.net/purchase/bgmcart/regadd.do?action=GIFT'; }
		else { var url = 'http://music.daum.net/purchase/bgmcart/regadd.do'; }
	}	
	var open_url = 'http://music.daum.net/purchase/' + cart + 'cart.do';
	var pop = Music.newWin(open_url, "cart", "width=420, height=260, resizable=no, scrollbars=yes");
	if(!!val) {
		Music.rebuildForm(val, "songId", url, "cart");
	}
}

function bgmMini(id, objBtn) {
	openLayerController("BGM", objBtn, id );
}  
/*
function markMini(id) {
	alert("찜 - " + id);
}*/

// 아티스트찜
function bookmarkArtist(id) {
	if(id) {
		var url = '/my/bookmark/artist/regadd.do?itemId=' + id;			
		UI.Popup(url, "bookmarkPop", "width=372, height=200, resizable=yes");
		//UI.Popup(url, "bookmarkPop", "width=400, height=260, resizable=yes");
	}
}
// 아티스트의 앨범 보기
function artistAlbum(id) {
	goURL('/artist/album.do?artistDetailId=' + id);
}
/* for debug */
function FTdebugEvent() {
    var obj = UI.$("ftMessage");
    if( obj ){
	    var el = document.createElement("DIV");
		el.id = 'ftDebug';
		el.innerHTML = obj.innerHTML + '<br><input type="button" value="닫기" style="width:100%;background-color:#ECECEC;cursor:pointer;" onClick="UI.$(\'ftDebug\').style.display=\'none\';">'
		document.body.appendChild(el);  
	}
}
/* 다음캐쉬 */
function openDaumCash(url, popName) {
	//var returnURL = encodeURIComponent("http://music.daum.net/purchase/daumcash.html");
	var returnURL = (url)? url : location.href;
	if(popName) { var param = "&isPopup=1&popName=" + popName; } 
	else { var param = "&isPopup=0"; }
	var url = "https://bill.daum.net/Elf/cash/Credit.daum?popURL=" + returnURL + param;
	var winFeat = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=580,height=543";
	Music.newWin(url, "bill", winFeat);
}
/* 별 충전하기 */
function openStarCharge(url, popName) {
	var returnURL = (url)? url : location.href;
	if(popName) { var param = "&isPopup=1&popName=" + popName; } 
	else { var param = "&isPopup=0"; }
	var url = "http://mall.planet.daum.net/mall/member/account/c_star.jsp?popURL=" + returnURL + param;
	var winFeat = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=630,height=480";
	Music.newWin(url, "starBuy", winFeat);
}

/* CD구매 - 앨범가격비교 */
function buyAlbum(id){
new UI.Modal("/popup/albumPrice.do?albumId="+id,{type:"iframe",status:"width=565 height=255 frameborder=0 scrolling=no style='padding:0;'" });
}   

/* 퍼가기 - 앨범 */
function scrapAlbum(id){
new UI.Modal("/popup/albumScrap.do?albumId="+id,{type:"iframe",status:"width=468 height=468 frameborder=0 scrolling=no style='padding:0;'" });
}   

/* 퍼가기 - 아티스트 */
function scrapArtist(id){
new UI.Modal("/popup/artistScrap.do?artistDetailId="+id,{type:"iframe",status:"width=468 height=468 frameborder=0 scrolling=no style='padding:0;'" });
}   

/* 아티스트 맵*/
function artistMap(id,type){
new UI.Modal("http://music.daum.net/popup/artistMap.do?artistDetailId="+id+"&artistType="+type,{type:"iframe",status:"width=630 height=440 frameborder=0 scrolling=no style='padding:0;'" });
}

/* 다음 이미지검색 */
function searchImage(q){
	window.open("http://search.daum.net/search?w=img&q="+encodeURIComponent(q));
}

/* 다음 통합검색 */
var searchDaum = function(q){
	window.open("http://search.daum.net/search?q="+encodeURIComponent(q));
}


/* 이정보에 직접 참여 */
var userReport = function(type,id){
	var url = "/popup/userReport.do?objType="+type+"&objId="+id;
	UI.Popup(url, "userReport", "width=400, height=260, resizable=yes");
}

/* 평점주기 */
var giveGrade = function(type,target,id) {
	var url = "#"+ target;
	if(id){
		if(type == "AL")	
		url = "/album/album.do?albumId="+ id + url;
		else
		url = "/artist/artist.do?artistDetailId="+ id + url;
	}
	location.href = url;
};		

/* 내블로그로 리뷰보내기 */
var goTrackback = function(id, what) {
	if(what == "album") { var url = "http://user.csm.daum.net/album/trackbacks/new/" + id; }
	else { var url = "http://user.csm.daum.net/artist/trackbacks/new/" + id; }
	
	Music.newWin(url, "trackback", "width=400, height=260, resizable=no, scrollbars=yes");
};

/* MP3|배경음악 구매, 선물하기 레이어메뉴 컨트롤 */
var openLayerController = function( type, objBtn, id ){
	var objMenu = UI.$("daumLayerMenu");
	if( !objMenu ) {
	   objMenu = $C("div");
	   objMenu.id = "daumLayerMenu";
	   UI.$("Daum_doc").appendChild( objMenu )
	}

	if( type == "MP3"){
		var temp = '<ul class="layerMenuMP3">';
		if(document.location.href == 'http://music.daum.net/my/depository/mp3.do' || document.location.href == 'http://music.daum.net/my/depository/mp3.do?type=OWN') {
			temp += '<li class="gray">MP3 구매</li>';
		} else {
			temp += '<li><a href="javascript:;" onclick="openCartPop(['+id+'], \'mp3\');">MP3 구매</a></li>';
		}	   
		temp += '<li><a href="javascript:;" onclick="openCartPop(['+id+'], \'mp3\', \'gift\');">MP3 선물</a></li></ul>';
	} else if( type == "BGM") {
		var temp = '<ul class="layerMenuBGM">';
		if(document.location.href == 'http://music.daum.net/my/depository/bgm.do' || document.location.href == 'http://music.daum.net/my/depository/bgm.do?type=OWN' || document.location.href == 'http://music.daum.net/my/depository/bgm.do?type=TAKE') {
			temp += '<li class="gray">배경음악 구매</li>';
		} else {
			temp += '<li><a href="javascript:;" onclick="openCartPop(['+id+'], \'bgm\');"">배경음악 구매</a></li>';
		}
		temp += '<li><a href="javascript:;" onclick="openCartPop(['+id+'], \'bgm\', \'gift\');">배경음악 선물</a></li>';
		if(id.constructor != Array) { 	// item 일때만 미리듣기 보여줌
			temp += '<li><a href="javascript:;" onclick="Music.openPreview(\''+id+'\');">미리듣기</a></li>';
		}
		temp += '</ul>';
	}  else if( type == "relSong") {
		
		var temp = '<div class="layerRelSong" id="layerRelSong"><ul>';
		
		for( var i=0, cnt=id.length; i<cnt; i++ ){
			var item = id[i];
			temp += "<li><a href='/song/"+item.song.songId+"' title='"+item.song.songTitle.replace(/'/gi, "&quot;")+"' class='b'>"+item.song.songTitle+"</a>";
			temp += " <span class='bar'>|</span> ";
			temp += "아티스트:";
			for( var k=0,cntK=item.artist.length; k<cntK; k++ ){
                if( k>0) temp += ",";
                temp += "<a href='/artist/"+item.artist[k].artistDetailId+"' title='"+item.artist[k].artistName.replace(/'/gi, "&quot;")+"'>"+item.artist[k].artistName+"</a>";
			}
			temp += " <span class='bar'>|</span> ";
			var albumName = item.album.albumTitle;
			if( item.album.volumn != "" ) albumName = item.album.volumn+"집 "+ albumName;
			temp += "앨범:<a href='/album/"+item.album.albumId+"' title='"+albumName.replace(/'/gi, "&quot;")+"'>"+albumName+"</a>";
			temp += "</li>";
		}
		temp += '</ul><a href="javascript:;" onclick="UI.$(\'layerRelSong\').style.display = \'none\';" class="close">닫기</a></div>';
	}
	
	objMenu.innerHTML = temp;
	
    objParent = objBtn;
    var left = objBtn.offsetLeft;
    var top = objBtn.offsetTop;

    while( objParent = objParent.offsetParent ){
        if( objParent.id=="Daum_doc"){
            break;
        }
        left += objParent.offsetLeft;
        top += objParent.offsetTop;
    }
    
	var el_height = parseInt(UI.getStyle(objBtn, 'height').replace('px',''),10);
    objMenu.style.display = "block";
    objMenu.style.left = left+"px";
    objMenu.style.top = (id.constructor != Array) ? (top+el_height+2)+"px" : (top+el_height-2)+"px";
    objMenu.style.position = "absolute";
    objMenu.style.zIndex = "1000";
};


/*
var objOpenLayerMenu = null;
var checkLayerEvent = function( event, type ){
    var el = UI.getEl( event );
    try
    {
        if( el.id.indexOf("layerMenu") == 0 || el.offsetParent.id.indexOf("layerMenu") == 0 ){
            var thisEl = null;
            if( el.id.indexOf("layerMenu") == 0 ) thisEl = el;
            else thilEl = el.offsetParent;
            if( thilEl == null ) return false;

            if( type == "out" ){
                thilEl.style.display = "none";
            } else if( type == "over" ){
                thilEl.style.display = "block";
            }
        }
    }catch (e){}
};
var openLayerController = function( type, objBtn, id ){
    var obj = null;
    if( type == "MP3" ){
        obj = UI.$("layerMenuMP3_"+id);
    } else if ( type == "BGM" ){
        obj = UI.$("layerMenuBGM_"+id);
    }

    // 아래 alert은 개발용임., 실서비스에선 빼주3
    if( !obj ) {
        alert("해당 메뉴 레이어가 존재하지 않습니다. - 수정필요 -");
        return false;
    }
    if( objOpenLayerMenu ){
        objOpenLayerMenu.style.display = "none";
    }
    objOpenLayerMenu = obj;
    obj.style.display = "block";
    
};
function openLayerBGM( objBtn, id ){
    openLayerController("BGM", objBtn, id );
}
function openLayerMP3( objBtn, id ){
    openLayerController("MP3", objBtn, id );
}
function openLayerInit(){
    UI.addEvent( document, "mouseout", checkLayerEvent.bindAsEventListener( this, "out" ) );
    UI.addEvent( document, "mouseover", checkLayerEvent.bindAsEventListener( this, "over" ) );
}
UI.addEvent( document, "mouseout", checkLayerEvent.bindAsEventListener( this, "out" ) );
UI.addEvent( document, "mouseover", checkLayerEvent.bindAsEventListener( this, "over" ) );
* */
Music.onMouseDown = function( event ){
    var objLayerMenu = UI.$("daumLayerMenu");
    if( objLayerMenu && objLayerMenu.style.display == "block" ){
    	var el = UI.getEl( event );
    	var div = UI.findParent( el, "DIV", "daumLayerMenu");
    	if( !div ){
        	objLayerMenu.style.display = "none";    	
    	}
    }
}
/**
 * 마우스 우클릭, 드래그, 선택 금지
 */
var runProtectedContents = function(){    
    UI.addEvent( document, "contextmenu", function(){ return false } );
//    UI.addEvent( document, "selectstart", function(){ return false } );
    UI.addEvent( document, "dragstart", function(){ return false } );
}
// 1분 제한
var BGMInterval = function(){
    playInterval++;
    if( playInterval > 60 ){
       BGMStop();
    }
};
UI.addEvent(window, 'load', FTdebugEvent);
UI.addEvent(document, 'mousedown', Music.onMouseDown );

function updateChar(FieldName, mententname, textlimitname, message){
	var strCount = 0;
	var tempStr, tempStr2;
	for(i = 0;i < UI.$(mententname).value.length;i++) {
		tempStr = UI.$(mententname).value.charAt(i);
		if(escape(tempStr).length > 4) strCount += 2;
		else strCount += 1 ;
	}
	if (strCount > FieldName) {
		if(message) { alert(message); }
		else { alert("최대 " + FieldName + "byte이므로 초과된 글자수는 자동으로 삭제됩니다."); }
		strCount = 0;
		tempStr2 = "";
		for(i = 0; i < UI.$(mententname).value.length; i++) {
			tempStr = UI.$(mententname).value.charAt(i);
			if(escape(tempStr).length > 4) strCount += 2;
			else strCount += 1 ;
			if (strCount > FieldName) {
				if(escape(tempStr).length > 4) strCount -= 2;
				else strCount -= 1 ;
				break;
			} else tempStr2 += tempStr;
		}
		UI.$(mententname).value = tempStr2;
	}
	UI.$(textlimitname).innerHTML = strCount;
}

/* GNB 검색창 */
UI.$F=function(n) {
	var s=null;
	s = UI.$(n)||document.getElementsByName(n)[0];
	if(s!=undefined) {
		if(s.type=="checkbox")
		{
			var c=[];
			var r=document.getElementsByName(n);
			for(var i=0;i<r.length; i++) if(r[i].checked) c.push(r[i].value);
			return (c.length>0)?c:""; 
		}
		else if(s.type=="radio")
		{
			var r=document.getElementsByName(n);
			for(var i=0;i<r.length; i++) if(r[i].checked) return r[i].value;
			return "";
		}

		return s.value;
	} else {
		return ;
	}
};
function _jsSearchForm() {
	var SearchKeyword = document.getElementById("SearchKeyword");
	var chkKey = UI.trim(SearchKeyword.value);
	var chkUrl = "";
	if(chkKey == "") {
		alert("검색어를 입력해 주시기 바랍니다.");
		return false;
	} else {
		try {
    		gLink(null, 'SBCY', '1', '1'); // click log
    	} catch(e) {}
    	
		var Stype = document.search.type.value;
		if(Stype == "daumSearch") {
    		chkUrl = "http://search.daum.net/search?q=" + encodeURIComponent(chkKey);
    		
    		window.open(chkUrl, "_blank");
    	} else {
	    	if (Stype == "total" || Stype == "")
	    		chkUrl = "http://music.daum.net/search/search.do";
	    	else
	    		chkUrl = "http://music.daum.net/search/"+Stype+".do";
    		
    		document.location.href = chkUrl + "?query=" + encodeURIComponent(chkKey);
    	}
	}
}
function _jsSethFrameUrl(event) {
	
	var hFrameSrc = UI.$("hFrame").src;
	var cate = UI.$F("SearchCategory");	
	
	var gLinkP = null;

	switch(cate) {
		case "total" : {gLinkP = "1";break;}                    
		case "artist" : {gLinkP = "2";hFrameSrc = "http://suggest.music.daum.net/music_script_tot.html";break;}
		case "song" : {gLinkP = "3";break;}
		case "album" : {gLinkP = "4";hFrameSrc = "http://suggest.music.daum.net/music_script_tot.html";break;}
		case "video" : {gLinkP = "5";break;}
		case "lyric" : {gLinkP = "6";break;}
		case "board" : {gLinkP = "7";break;}
		case "news" : {break;}
		case "bgm" : {gLinkP = "8";break;}
		case "daumSearch" : {gLinkP = "9";break;}
		//case "genre" : {break;}
		default : {hFrameSrc = "http://suggest.music.daum.net/music_script_tot.html";break;}
	}	
	/* suggest_init */
	if(UI.$("hFrame")) {
		UI.$("hFrame").src = hFrameSrc;			
	}
	try{
		gLink(null, "SDCY", "1", gLinkP);	// click log
	} catch(e) {}
}

// 듣기가능, 배경음악 구매 가능 필터링
function filter(type, url) {
	var aod = (UI.$('filterAOD').className.indexOf('icoCheck_dis') > -1)? false : true;
	var bgm = (UI.$('filterBGM').className.indexOf('icoCheck_dis') > -1)? false : true;
	
	if(type == "AOD") { aod = (aod) ? false : true; } 
	else { bgm = (bgm) ? false : true; }
	
	if(aod) url += '&playYn=Y';
	if(bgm) url += '&bgmYn=Y';
	location.href = url;
}

// click log - for section search
function gClickLink(idx, cnt, area) {
	var code = null;
	var pathname = document.location.pathname;
	if(area == "songtop") {	// songTop10 - mot
		switch(pathname) {
			case "/search/search.do" : code = "R2TY"; break;
			case "/search/artist.do" : code = "R3AY"; break;
			case "/search/song.do" : code = "R5SY"; break;
			case "/search/album.do" : code = "R4VY"; break;		
			case "/search/video.do" : code = "R4MY"; break;	
			case "/search/lyric.do" : code = "R5LY"; break;	
			case "/search/board.do" : code = "R1BY"; break;
			case "/search/bgm.do" : code = "R5GY"; break;
			default : code = "R2TY"; break;
		}
	} else if(area == "artisttop") {	// artistTop10 - mot
		switch(pathname) {
			case "/search/search.do" : code = "R3TY"; break;
			case "/search/artist.do" : code = "R4AY"; break;
			case "/search/song.do" : code = "R6SY"; break;
			case "/search/album.do" : code = "R5VY"; break;		
			case "/search/video.do" : code = "R5MY"; break;	
			case "/search/lyric.do" : code = "R6LY"; break;	
			case "/search/board.do" : code = "R2BY"; break;
			case "/search/bgm.do" : code = "R6GY"; break;
			default : code = "R3TY"; break;
		}
	} else if(area == "genre") {	// 장르별
		switch(pathname) {
			case "/search/artist.do" : code = "R2AY"; break;
			case "/search/song.do" : code = "R3SY"; break;
			case "/search/album.do" : code = "R2VY"; break;		
			case "/search/video.do" : code = "R2MY"; break;	
			case "/search/lyric.do" : code = "R3LY"; break;	
			case "/search/bgm.do" : code = "R3GY"; break;
			default : code = "R3TY"; break;
		}
	} else if(area == "target") {	// 대상별
		switch(pathname) {
			case "/search/song.do" : code = "R1SY"; break;
			case "/search/album.do" : code = "R1VY"; break;		
			case "/search/video.do" : code = "R1MY"; break;	
			case "/search/lyric.do" : code = "R1LY"; break;	
			case "/search/bgm.do" : code = "R1GY"; break;
			default : code = "R1SY"; break;
		}
	} else if(area == "release") {	// 발매연도별
		switch(pathname) {
			case "/search/song.do" : code = "R4SY"; break;
			case "/search/album.do" : code = "R3VY"; break;		
			case "/search/video.do" : code = "R3MY"; break;	
			case "/search/lyric.do" : code = "R4LY"; break;	
			case "/search/bgm.do" : code = "R4GY"; break;
			default : code = "R4SY"; break;
		}
	} else if(area == "artist") {	// 아티스트별
		switch(pathname) {
			case "/search/search.do" : code = "R1TY"; break;
			case "/search/song.do" : code = "R2SY"; break;
			case "/search/lyric.do" : code = "R2LY"; break;	
			case "/search/bgm.do" : code = "R2GY"; break;
			default : code = "R1TY"; break;
		}
	} else if(area == "paging") {	// 페이징
		switch(pathname) {
			case "/search/artist.do" : code = "PGAY"; break;
			case "/search/song.do" : code = "PGSY"; break;
			case "/search/album.do" : code = "PGVY"; break;		
			case "/search/video.do" : code = "PGMY"; break;	
			case "/search/lyric.do" : code = "PGLY"; break;	
			case "/search/board.do" : code = "PGBY"; break;
			case "/search/bgm.do" : code = "PGGY"; break;
			default : code = "PGAY"; break;
		}
	}
	gLink(null, code, idx, cnt);
}