﻿//<![CDATA[
/// 2007. 05. 15 --- 1차 완료 버전 : Next 부분 완성. IE / FireFox Test 완료.
/// 2007. 05. 15 --- 2차 완료 버전 : Prev 부분 완성. IE / FireFox Test 완료.

/// 2007. 05. 16 --- 클래스화. TEST.
var MoveUp = Class.create();
MoveUp.prototype =
{ 				
	initialize: function(element, options) 
	{
		this.element        = element;
		this.options        = Object.extend({ScrollPixel : 2, Duration : 5, TimerDuration: 0.05, ViewCount: 1, BackGroundColor: "WHITE"}, options);
		this.clipLayer      = null;
		this.moveLayer      = null;
		this.moveLayerList  = new Array();
		this.elementList    = new Array();
		this.elementList    = this.element.getElementsByTagName('p');
		
		if(this.elementList.length > 1){
		    this.startPos       = null;
		    this.endNextPos     = null;
		    this.ScrollPixel    = this.options.ScrollPixel;
		    this.Duration       = this.options.Duration;
		    this.TimerDuration  = this.options.TimerDuration;
		    this.ViewCount      = this.options.ViewCount;
		    this.backgroundColor = this.options.BackGroundColor;
		    
		    this.moving_Timer           = new PeriodicalExecuter(this.up_scroll, this.Duration);
		    this.moving_Timer.component = this;
		    this.moving_Timer.id        = this.element.id + "MoveUp";
		    this.up_Timer               = new PeriodicalExecuter(this.up_movingAnimation, this.TimerDuration);
		    this.up_Timer.component     = this;
		    this.up_Timer.stop();
		    
		    this.objParent      = null;
		    this.cloneExist     = false;
		    this.init();}}, 
		    
	init: function(){
	        for(i=0 ;i < this.elementList.length; i++){
                if(i < this.ViewCount){this.elementList[i].style.display ="block";}
		        else{this.elementList[i].style.display ="none";}}
		    this.objParent	= this.element.parentNode;
		    this.clipLayer                  = document.createElement('div');
            this.moveLayer                  = document.createElement('div');
            this.objParent.appendChild(this.clipLayer);
            this.clipLayer.appendChild(this.moveLayer);
		    this.createclone();},
	
	get_layer : function (){
            for(i= 0 ;i < this.ViewCount;i++){
                var objParagraph	= this.elementList[i];
                var objClone		= objParagraph.cloneNode(true);
                this.moveLayer.appendChild(objClone);
                this.moveLayerList[i] = objClone;
                objClone.style.top	= objParagraph.offsetTop + "px";
                objClone.style.left	= objParagraph.offsetLeft + "px";} 
            var objParagraph	= this.elementList[this.ViewCount];
            var objClone		= objParagraph.cloneNode(true);
            this.moveLayer.appendChild(objClone);
            this.moveLayerList[this.moveLayerList.length] = objClone;
            this.moveLayerList[this.moveLayerList.length -1].style.display = "block";},
	
	pos : function(){
        if(navigator.appName.indexOf("Microsoft") != -1){
            this.startPos        = this.element.offsetTop + $("body").offsetTop;
            this.endNextPos      = this.element.offsetTop + $("body").offsetTop - this.elementList[0].offsetHeight;}
        else{
            this.startPos        = this.elementList[0].offsetTop;
            this.endNextPos      = this.elementList[0].offsetTop - this.elementList[0].offsetHeight;}},
	
	createclone : function(){
	    if(!this.cloneExist){this.get_layer();
    	    this.clipLayer.id	= "clipLayer_MoveUp";
    	    
    	    if(navigator.appName.indexOf("Microsoft") != -1){
    	        var base = navigator.appVersion.indexOf('MSIE');
		        var IEVer = navigator.appVersion.substring(base + 4, base + 8);	
		        if(IEVer >= 7.0){
		            this.clipLayer.style.top = this.element.offsetTop + $("body").offsetTop;
                    this.clipLayer.style.left= $("wrap").offsetLeft + $("bodywrap").offsetLeft;}
		        else{
                    this.clipLayer.style.top = this.element.offsetTop + $("body").offsetTop;
                    this.clipLayer.style.left = $("wrap").offsetLeft + $("body").offsetLeft;}}
    	    else{
    	        this.clipLayer.style.top	    = this.element.offsetTop + "px";
                this.clipLayer.style.left	    = this.element.offsetLeft + "px";}
    	    
    	    this.clipLayer.style.width	    = this.element.offsetWidth - 34 + "px";
            this.clipLayer.style.height		= this.element.offsetHeight + "px";
            this.clipLayer.style.zIndex	    = "1";
            this.clipLayer.style.position   = "absolute";
            this.clipLayer.style.overflow   = "hidden";
            this.clipLayer.style.background = this.backgroundColor;
            this.moveLayer.id				= "moveLayer_MoveUp";
            this.moveLayer.style.position	= "absolute";
		    this.moveLayer.style.display	= "block";
            this.moveLayer.style.zindex 	= "2";
            if(navigator.appName.indexOf("Microsoft") == -1){
			    this.moveLayer.style.top		= this.element.offsetTop - parseInt(this.clipLayer.style.top) -  this.elementList[0].offsetHeight + "px";}
			this.clipLayer.style.display    = "none";
	        this.cloneExist = true;
            this.pos();}
	    else{
	        var length = this.moveLayerList.length;
	        for(i=0 ; i< length; i++){this.moveLayer.removeChild(this.moveLayerList[i]);}
            this.moveLayerList = new Array();this.pos();this.get_layer();}},
	
	up_scroll: function(){if(this.id == this.component.moving_Timer.id){this.component.moving();}},
	
	up: function(){
		var temp;		
		var tempArr1 = new Array();		
		var tempArr2 = new Array();
			
	    for(i=0; i < this.elementList.length; i++){
			if(i == 0){temp = this.elementList[i].innerHTML;}
			if(i == this.elementList.length - 1){this.elementList[i].innerHTML = temp;}
			else{this.elementList[i].innerHTML = this.elementList[i+1].innerHTML;}}
		
		this.up_Timer.stop();},
	
	moving : function(direction){
	    this.clipLayer.style.display = "block";
		this.moveLayer.style.display = "block";
		
		this.up_Timer.stop();
		this.up_Timer.registerCallback();},
			
	up_movingAnimation : function(){   
	    if(this.component.startPos < this.component.endNextPos){   
            this.component.up();
            this.component.moveLayer.style.display = "none";
		    this.component.clipLayer.style.display = "none";
		    this.component.createclone();
		    if(navigator.appName.indexOf("Microsoft") == -1){this.component.moveLayer.style.top		= this.component.element.offsetTop - parseInt(this.component.clipLayer.style.top) -  this.component.elementList[0].offsetHeight + "px";}
			this.component.element.style.display = "block";
		    this.component.up_Timer.stop();}
		else{
            this.component.startPos = this.component.startPos - this.component.ScrollPixel;
            this.component.moveLayer.style.top = this.component.startPos - parseInt(this.component.clipLayer.style.top) + "px";}}
}

//]]>