﻿
var scrollerheight=12 // 스크롤러의 높이
var scrollertop=20 // 스크롤러의 위쪽위치
var scrollerleft=20 // 스크롤러의 좌측 위치
var scrollerborder=0 // 스크롤러 테두리 두께

var standstill=4000		
var cliptop=0
var clipbottom=0
var clipleft=0
var clipright=600
var i_message=0
var contenttext=""
var contentbg=""
var step=1
var pause=20			
var start=true
var PauseTimer
var StillTimer
var message = new Array()

function initiate() {
	var cloumn=document.getElementById("scrollerbg"); 
	var top = GetObjectTop(cloumn)+5;
	var left =  GetObjectLeft(cloumn);
    scrollertop=top;
	scrollerleft=left;
	
	message = document.getElementsByName("wrap_msg")[0].innerHTML.split("|")
	
    if (navigator.appName=="Microsoft Internet Explorer") { // IE 용 코드
		contenttext = "<div style='width=100%; height="+scrollerheight+"px;cursor:pointer;text-align:left;' onmouseover='fStopScroll()' onmouseout='fStartScroll()' onclick='fMedia("+message[0]+")'>"+message[1]+"</div>";
		contentbg="<div style='width=100%; height="+scrollerheight+"px;'></div>"
				
        document.getElementById("scrollertext").innerHTML=contenttext
        document.getElementById("scrollerbg").innerHTML=contentbg
        
        document.getElementById("scrollertext").style.posTop=scrollertop+scrollerheight
        document.getElementById("scrollertext").style.posLeft=scrollerleft
        document.getElementById("scrollerbg").style.posTop=scrollertop-scrollerborder
        document.getElementById("scrollerbg").style.posLeft=scrollerleft-scrollerborder
        document.getElementById("scrollertext").style.clip="rect("+cliptop+"px, "+clipright+"px, "+clipbottom+"px, "+clipleft+"px)"
 		scrollin();
	}
    else { // 네츠케이프용 코드
		//scrolltext의 innerHTML 구문
		contenttext = message[1];
		var objScrollText = document.createElement("div");
		objScrollText.style.width="100%"
		objScrollText.style.height=scrollerheight+'px'
		objScrollText.style.cursor = "pointer"
		objScrollText.setAttribute("id","dvScroll")
		objScrollText.onmouseover = function() { fStopScroll(); }
		objScrollText.onmouseout = function() { fStartScroll(); }
		objScrollText.onclick = function () { fMedia(message[0]); }
		objScrollText.appendChild(document.createTextNode(contenttext));
		document.getElementById("scrollertext").appendChild(objScrollText);
		//scrollbg의 innerHTML 구문
		var objScrollBg = document.createElement("div");
		objScrollBg.style.width="100%"
		objScrollBg.style.height=scrollerheight+'px'
		document.getElementById("scrollerbg").appendChild(objScrollBg);
		
        document.getElementById("scrollertext").style.top=scrollertop+scrollerheight+'px'
        document.getElementById("scrollertext").style.left=scrollerleft+'px'
        document.getElementById("scrollerbg").style.top=scrollertop-scrollerborder+'px'
        document.getElementById("scrollerbg").style.left=scrollerleft-scrollerborder+'px'
        
        // 현재 적용 안됨 ㅜㅜ 
		document.getElementById("scrollertext").style.clip.left=clipleft+'px'
		document.getElementById("scrollertext").style.clip.right=clipright+'px'
		document.getElementById("scrollertext").style.clip.top=cliptop+'px'
		document.getElementById("scrollertext").style.clip.bottom=clipbottom+'px'
        scrollin();	
    }
}

function scrollin(){		//스크롤 작동
	if (navigator.appName=="Microsoft Internet Explorer"){		//익스플로러 일 때 
		if (document.all.scrollertext.style.posTop > scrollertop) {
			clipbottom+=step
			document.all.scrollertext.style.clip="rect("+cliptop+"px, "+clipright+"px, "+clipbottom+"px, "+clipleft+"px)"
			document.all.scrollertext.style.posTop-=step
			PauseTimer = setTimeout("scrollin()",pause)
		}
		else {
			clearTimeout(PauseTimer)
			if (start) {StillTimer = setTimeout("scrollout()",standstill)} //4초후 scrollout 실행
		}
	}
    else {	//넷스케이프일 때
		var cloumn = document.getElementById("scrollertext")
        var top = GetObjectTop(cloumn)
        if (top > scrollertop) {
            clipbottom+=step
            
            // 현재 적용 안됨 ㅜㅜ
			document.getElementById("scrollertext").style.clip.left=clipleft+'px'
			document.getElementById("scrollertext").style.clip.right=clipright+'px'
			document.getElementById("scrollertext").style.clip.top=cliptop+'px'
			document.getElementById("scrollertext").style.clip.bottom=clipbottom+'px'
			top-=step
			document.getElementById("scrollertext").style.top = top+'px'
            PauseTimer = setTimeout("scrollin()",pause)
        }
        else {
            clearTimeout(PauseTimer)
            if (start) {StillTimer = setTimeout("scrollout()",standstill)} //4초후 scrollout 실행
        }
    }
}

function scrollout(){	//스크롤 사라짐
    if (navigator.appName=="Microsoft Internet Explorer"){	//익스플로러일 때
		if (start) {
			clearTimeout(StillTimer);	// 타이머 해제
			if (document.all.scrollertext.style.posTop>(scrollertop-scrollerheight)) {
				cliptop+=step
				document.all.scrollertext.style.clip="rect("+cliptop+"px, "+clipright+"px, "+clipbottom+"px, "+clipleft+"px)"
				document.all.scrollertext.style.posTop-=step
				PauseTimer = setTimeout("scrollout()",pause)
			}
			else {
				clearTimeout(PauseTimer)	//타이머 해제
				changemessage()				//메세지 변경
			}
		}
		else {
			clearTimeout(PauseTimer)
		}
    }
    else {	//넷스케이프 일 때
		if (start) {
			clearTimeout(StillTimer);	// 타이머 해제
			var cloumn = document.getElementById("scrollertext")
			var top = GetObjectTop(cloumn)
	        
			if (top > (scrollertop-scrollerheight)) {
				cliptop+=step 
				
				// 현재 적용 안됨 ㅜㅜ
				document.getElementById("scrollertext").style.clip.left=clipleft+'px'
				document.getElementById("scrollertext").style.clip.right=clipright+'px'
				document.getElementById("scrollertext").style.clip.top=cliptop+'px'
				document.getElementById("scrollertext").style.clip.bottom=clipbottom+'px'
				top-=step
				document.getElementById("scrollertext").style.top = top+'px'
				var timer=setTimeout("scrollout()",pause)
			}
			else {
				clearTimeout(timer);
				changemessage();
			}
		}
		else {
			clearTimeout(PauseTimer);
		}
    }
}

function changemessage(){
	var count  = document.getElementsByName("wrap_msg").length;
	i_message++
	if (i_message>count-1) {i_message=0}
	
	cliptop=0
	clipbottom=0
	
	message = document.getElementsByName("wrap_msg")[i_message].innerHTML.split("|")
	
    if (navigator.appName=="Microsoft Internet Explorer"){
		contenttext = "<div style='width=100%; height="+scrollerheight+"px;cursor:pointer;text-align:left;' onmouseover='fStopScroll()' onmouseout='fStartScroll()' onclick='fMedia("+message[0]+")'>"+message[1]+"</div>";
        scrollertext.innerHTML=contenttext
        document.all.scrollertext.style.posTop=scrollertop+scrollerheight
        document.all.scrollertext.style.posLeft=scrollerleft
        document.all.scrollertext.style.clip="rect("+cliptop+"px, "+clipright+"px, "+clipbottom+"px, "+clipleft+"px)"
        scrollin()
    }
    else {
		contenttext = message[1];
		document.getElementById("scrollertext").removeChild(document.getElementById("dvScroll"));
	
		var objScrollText = document.createElement("div");
		objScrollText.style.width="100%"
		objScrollText.style.height=scrollerheight+'px'
		objScrollText.style.cursor = "pointer"
		objScrollText.setAttribute("id","dvScroll")
		objScrollText.onmouseover = function () { fStopScroll(); }
		objScrollText.onmouseout = function () { fStartScroll(); }
		objScrollText.onclick = function () { fMedia(message[0]); }
		objScrollText.appendChild(document.createTextNode(contenttext));
		document.getElementById("scrollertext").appendChild(objScrollText);
		
        document.getElementById("scrollertext").style.top=scrollertop+scrollerheight+'px'
        document.getElementById("scrollertext").style.left=scrollerleft+'px'
		
		// 현재 적용 안됨 ㅜㅜ
		document.getElementById("scrollertext").style.clip.left=clipleft+'px'
		document.getElementById("scrollertext").style.clip.right=clipright+'px'
		document.getElementById("scrollertext").style.clip.top=cliptop+'px'
		document.getElementById("scrollertext").style.clip.bottom=clipbottom+'px'	
		scrollin()
    }
}

function fStopScroll() {
	start = false;
	clearTimeout(StillTimer); 
}

function fStartScroll() {
	start = true;
	scrollout();
}
