//상단으로 움직으로 스크롤
function eScroll() {
	var thisObj = this;
	this.timeObj = null;

	/*** 설정변수 ***/
	this.mode = "left";						// 스크롤 방향 (top|left)
	this.width		=	null;						// 라인당 가로값 (pixel -ex)50)
	this.height	=	null;						// 라인당 높이값 (pixel -ex)70)
	this.line		=	1;							// 출력 라인수 -ex)1
	this.delay		=	60;							// 스크롤후 딜레이 시간
	this.speed	=	1;							// 스크롤 속도 (작을수록 빠름)
	this.id			=	null;						// 객체 id (클래스 다중 사용시 id 다르게 지정 요망)
	this.contents	=	new Array();		// 출력 내용 (배열로 내용 지정 요망)
	this.align			=	"center";				// 내용 aligne
	this.classname	=	null;					// 스타일 클래스명

	/*** 내장변수 ***/
	this.gap = 0;
	this.direction = 1;
	this.add = add;
	this.exec = exec;
	this.start = start;
	this.stop = stop;
	this.scroll = scroll;
	this.go = go;

	function add(str)
	{
		this.contents[this.contents.length] = str;
	}

	function exec()
	{
		this.basis = (this.mode == "left" || this.mode == "right") ? this.width : this.height;
		var outWidth = this.width * ((this.mode == "left"|| this.mode == "right") ? this.line : 1);
		var outHeight = this.height * ((this.mode == "top") ? this.line : 1);

		var outline = "<div id=" + this.id + " style='overflow:hidden; width:" + outWidth + "px; height:" + outHeight + "px;'><table></table></div>";
		document.write(outline);
		this.obj = document.getElementById(this.id);

		var tb = this.obj.appendChild(document.createElement("table"));
		var tbody = tb.appendChild(document.createElement("tbody"));
		tb.cellPadding = 0 ;
		tb.cellSpacing = 0 ;
		tb.onmouseover = function(){thisObj.stop()};
		tb.onmouseout = function(){thisObj.start()};

		if (this.mode=="left"|| this.mode == "right") var tr = tbody.appendChild(document.createElement("tr"));
		for (k in this.contents) {
			if (this.mode=="top") var tr = tbody.appendChild(document.createElement("tr"));
			var td = tr.appendChild(document.createElement("td"));
			td.noWrap = true;
			td.style.width = this.width;
			td.style.height = this.height;
			td.style.textAlign = this.align;
			td.innerHTML = this.contents[k];
		}

		var len = (this.contents.length>this.line) ? this.contents.length : this.line;
		var j		= 0;
		for (i=0;i<len;i++) {
			if (this.mode=="top") var tr = tbody.appendChild(document.createElement("tr"));
			td = tr.appendChild(document.createElement("td"));
			td.noWrap = true;
			td.style.width = this.width;
			td.style.height = this.height;
			td.style.textAlign = this.align;
			td.innerHTML = this.contents[j];

			if ((this.contents.length - 1) <= i)		j	= 0;
			else													j++;
		}

		this.obj.parent = this;
		this.tpoint = this.basis * this.contents.length;
		this.start();
	}

	function scroll()
	{
		var out = (this.mode=="left"|| this.mode == "right") ? this.obj.scrollLeft : this.obj.scrollTop;
		if (out%this.basis==0){
			this.gap++;
			if (this.gap>=this.delay) this.gap = 0;
		}
		if (!this.gap) {
			if( this.mode == "right" )
				var ret = (out==this.tpoint) ? this.direction : out - this.direction;
			else
				var ret = (out==this.tpoint) ? this.direction : out + this.direction;
			if (ret<0) ret = this.tpoint + ret;
			if (this.mode=="left" || this.mode == "right" ) this.obj.scrollLeft = ret;
			else this.obj.scrollTop = ret;
		}
	}

	function start()
	{
		this.timeObj = window.setInterval("(document.getElementById('" + this.id + "')).parent.scroll()",this.speed);
	}

	function stop()
	{
		clearTimeout(this.timeObj);
	}

	function go()
	{
		this.stop();
		var out = (this.mode=="left" || this.mode == "right" ) ? this.obj.scrollLeft : this.obj.scrollTop;
		var ret = (parseInt(out / this.basis) + this.direction) * this.basis;
		if (ret<0) ret = this.tpoint + ret;
		if (ret>this.tpoint) ret = this.basis;
		if (this.mode=="left" || this.mode == "right" ) this.obj.scrollLeft = ret;
		this.obj.scrollTop = ret;
	}
}/*

function scrollMode( mode ) {
	scrollDealing.mode = mode;
	scrollDealing.speed	=	1;
}
function scrollMode2() {
	scrollDealing.speed	=	10;
}
*/
function rotatecontents(objectid){
 
    // 컨텐츠 로테이션
    // http://www.psyonline.kr
    
    this.titleobject=null;
    this.titlesetbyrule=null;
    this.pagingobject=null;
    this.pagingstart='';
    this.pagingdelimiter='/';
    this.pagingend='';
    this.rotatemethod=null;
    this.maxzindex=1;
    this.speed=3;
    this.autoplay=true;
    this.autoplaytime=3;
 
    this.buttonobject=null;
    this.buttontype='text';
    this.buttononclassname='on';
    this.buttononimagename='';
 
    this.addtitle=function(title){
        titles.push(title);
    }
    
    var object=document.getElementById(objectid);
    var items=new Array(),itemsnum,titles=new Array();
    var btns=new Array(),btnsmover=new Array(),btnsmout=new Array();
    var speed,timer,nowno=0,canimove=true;
    var isie=(navigator.userAgent.toLowerCase().indexOf('msie')!=-1)? true : false;
 
    this.initialize=function(){
        var isfirst=true,removeobjs=new Array(),childs=object.childNodes;
        for(var i=0,j=-1,max=childs.length; i<max; i++){
            if(childs[i].nodeType==1){
                j++;
                if(this.titleobject){
                    if(this.titlesetbyrule=='alt'){
                        titles.push((childs[i].nodeName.toLowerCase()=='img')? childs[i].alt : childs[i].getElementsByTagName('img')[0].alt);
                    }else if(this.titlesetbyrule=='nextobject' && j%2){
                        titles.push(childs[i].innerHTML);
                        removeobjs.push(childs[i]);
                        continue;
                    }else if(this.titlesetbyrule=='prevobject' && j%2==0){
                        titles.push(childs[i].innerHTML);
                        removeobjs.push(childs[i]);
                        continue;
                    }
                }
                if(!isfirst) childs[i].style.display='none';
                items.push(childs[i]);
                if(this.rotatemethod=='overlap' || this.rotatemethod=='slide' || this.rotatemethod=='fadein'){
                    speed=this.speed;
                    object.style.position='relative';
                    with(childs[i].style){
                        position='absolute';
                        left='0px';
                        top='0px';
                        width=object.offsetWidth+'px';
                    }
                    if(this.rotatemethod=='fadein'){
                        setopacity(childs[i],(isfirst)? 100 : 0);
                    }
                }
                if(isfirst) isfirst=false;
            }
        }
        itemsnum=items.length;
        if(removeobjs[0]){
            for(var i=0,max=removeobjs.length; i<max; i++) object.removeChild(removeobjs[i]);
        }
        if(this.titleobject) this.titleobject=(titles[0])? document.getElementById(this.titleobject) : null;
        if(this.pagingobject) this.pagingobject=document.getElementById(this.pagingobject);
        this.settitlenpaging(nowno);
        object.style.width=object.offsetWidth+'px';
        object.style.height=object.offsetHeight+'px';
        object.style.overflow='hidden';
        object.onmouseover=function(){
            clearTimeout(eval(objectid).autoplaytimer);
        }
        object.onmouseout=function(){
            eval(objectid).autoplayaction();
        }
        if(this.buttonobject){
            this.buttonobject=document.getElementById(this.buttonobject);
            var childs=this.buttonobject.childNodes;
            for(var i=0,j=0,max=childs.length; i<max; i++){
                if(childs[i].nodeType==1){
                    childs[i].myno=j;
                    if(childs[i].onmouseover) btnsmover.push(childs[i].onmouseover);
                    if(childs[i].onmouseout) btnsmout.push(childs[i].onmouseout);
                    btns.push(childs[i]);
                    j++;
                }
            }
            if(items.length!=btns.length) this.buttonobject=null;
            else this.setbtns();
        }
        this.autoplayaction();
    }
 
    this.settitlenpaging=function(no){
        if(this.titleobject) this.titleobject.innerHTML=titles[no];
        if(this.pagingobject) this.pagingobject.innerHTML=this.pagingstart+(no+1)+this.pagingdelimiter+itemsnum+this.pagingend;
    }
 
    this.setzindex=function(no){
        for(var i=0; i<itemsnum; i++){
            if(i==no){
                items[i].style.zIndex=this.maxzindex+3;
                items[i].style.display='';
            }else if(i==nowno){
                items[i].style.zIndex=this.maxzindex+2;
            }else{
                items[i].style.zIndex=this.maxzindex+1;
                items[i].style.display='none';
            }
        }
    }
 
    this.setbtns=function(no){
        if(!no && no!==0) no=nowno;
        for(var i=0; i<itemsnum; i++){
            if(i==no){
                this.setbtnon(btns[i]);
                btns[i].onmouseover=null;
                btns[i].onmouseout=null;
            }else{
                this.setbtnoff(btns[i]);
                btns[i].onmouseover=function(){
                    eval(objectid).setbtnon(this);
                    if(btnsmover[this.myno]) btnsmover[this.myno]();
                }
                btns[i].onmouseout=function(){
                    eval(objectid).setbtnoff(this);
                    if(btnsmout[this.myno]) btnsmout[this.myno]();
                }
            }
        }
    }
 
    this.setbtnon=function(target){
        var classes,exist=false;
        if(this.buttontype=='image'){
            var btnimg=target.getElementsByTagName('img')[0];
            var btnimgexp=btnimg.src.substring(btnimg.src.lastIndexOf('.'));
            if(btnimg.src.indexOf(this.buttononimagename+btnimgexp)==-1) btnimg.src=btnimg.src.replace(btnimgexp,this.buttononimagename+btnimgexp);
        }
        classes=target.className.split(' ');
        for(var i=0; i<classes.length; i++) if(classes[i]==this.buttononclassname) exist=true;
        if(!exist) target.className=target.className+' '+this.buttononclassname;
    }
 
    this.setbtnoff=function(target){
        var classes;
        if(this.buttontype=='image'){
            var btnimg=target.getElementsByTagName('img')[0];
            var btnimgexp=btnimg.src.substring(btnimg.src.lastIndexOf('.'));
            if(btnimg.src.indexOf(this.buttononimagename+btnimgexp)!=-1) btnimg.src=btnimg.src.replace(this.buttononimagename+btnimgexp,btnimgexp);
        }
        if(target.className.indexOf(this.buttononclassname)!=-1){
            if(target.className.indexOf(' ')==-1) target.className=target.className.replace(this.buttononclassname,'');
            else{
                classes=target.className.split(' ');
                for(var i=0; i<classes.length; i++) if(classes[i]==this.buttononclassname) classes[i]='';
                target.className=classes.join(' ');
            }
        }
    }
 
    this.change=function(no){
        no=no-1;
        if(no!=nowno){
            if(this.rotatemethod=='overlap') this.moveaction('overlap',no,(no<nowno)? 'prev' : 'next');
            else if(this.rotatemethod=='slide') this.moveaction('slide',no,(no<nowno)? 'prev' : 'next');
            else if(this.rotatemethod=='fadein') this.fadeinaction(no);
            else this.hideitem(no);
            this.settitlenpaging(no);
            if(this.buttonobject) this.setbtns(no);
        }
    }
 
    this.prev=function(){
        var prevno=(nowno==0)? itemsnum-1 : nowno-1;
        if(this.rotatemethod=='overlap') this.moveaction('overlap',prevno,'prev');
        else if(this.rotatemethod=='slide') this.moveaction('slide',prevno,'prev');
        else if(this.rotatemethod=='fadein') this.fadeinaction(prevno);
        else this.hideitem(prevno);
        this.settitlenpaging(prevno);
    }
 
    this.next=function(){
        var nextno=(nowno==(itemsnum-1))? 0 : nowno+1;
        if(this.rotatemethod=='overlap') this.moveaction('overlap',nextno,'next');
        else if(this.rotatemethod=='slide') this.moveaction('slide',nextno,'next');
        else if(this.rotatemethod=='fadein') this.fadeinaction(nextno);
        else this.hideitem(nextno);
        this.settitlenpaging(nextno);
        if(this.buttonobject) this.setbtns(nextno);
    }
 
    this.autoplaytimer=null;
    this.autoplayaction=function(){
        if(!this.autoplay) return;
        this.autoplaytimer=setTimeout(objectid+'.next()',this.autoplaytime*1000);
    }
 
    this.hideitem=function(no){
        clearTimeout(this.autoplaytimer);
        for(var i=0; i<itemsnum; i++) items[i].style.display=(i==no)? '' : 'none';
        this.autoplayaction();
        nowno=no;
    }
 
    var getleft=function(no){
        return parseInt(items[no].style.left);
    }
 
    var setleft=function(no,value){
        items[no].style.left=value+'px';
    }
 
    this.moveaction=function(method,no,direction){
        clearTimeout(this.autoplaytimer);
        if(canimove){
            canimove=false;
            setleft(no,(direction=='prev')? -(object.offsetWidth) : object.offsetWidth);
            this.setzindex(no);
            var now,snow,to=0,mv=0;
            var action=function(){
                clearTimeout(timer);
                now=getleft(no);
                if(method=='slide') snow=getleft(nowno);
                if(now!=to){
                    mv=(now-to)/speed;
                    setleft(no,(direction=='prev')? Math.ceil(now-mv) : Math.floor(now-mv));
                    if(method=='slide') setleft(nowno,(direction=='prev')? Math.ceil(snow-mv) : Math.floor(snow-mv));
                    setTimeout(action,10);
                }else{
                    eval(objectid+'.autoplayaction()');
                    clearTimeout(timer);
                    canimove=true;
                    nowno=no;
                }
            }
            action();
        }
    }
 
    var getopacity=function(target){
        return (isie)? parseInt(target.style.filter.match(/alpha\(opacity=([0-9]+)\)/)[1]) : target.style.opacity*100;
    }
 
    var setopacity=function(target,value){
        if(isie) target.style.filter='alpha(opacity='+value+')';
        else target.style.opacity=value/100;
    }
 
    this.fadeinaction=function(no){
        clearTimeout(this.autoplaytimer);
        if(canimove){
            canimove=false;
            setopacity(items[no],0);
            this.setzindex(no);
            var nowo,to=0;
            var action=function(){
                clearTimeout(timer);
                nowo=getopacity(items[no]);
                if(nowo!=100){
                    setopacity(items[no],Math.ceil(nowo+(100-nowo)/speed));
                    setTimeout(action,10);
                }else{
                    eval(objectid+'.autoplayaction()');
                    clearTimeout(timer);
                    canimove=true;
                    nowno=no;
                }
            }
            action();
        }
    }
 
}


/* 메인 탭 */
function onTab(cid,chk) {
	var hList = document.getElementById(cid).getElementsByTagName("h3");
	var cList = document.getElementById(cid).getElementsByTagName("div");
	for (i=0; i<hList.length; i++)	{

		if (i == chk){		
			cList[i].style.display="block";
		} else {
			cList[i].style.display="none";
		}
		
		hList[i].className = (i==chk) ? hList[i].className + " on" : hList[i].className.replace(" on","");
		if(hList[i].className.indexOf(" on on") > -1)
		{
			hList[i].className = hList[i].className.replace(" on on"," on");
		}
	}
	
}
