var nv = new Object();

nv.RollPanel = function(div_name,data){
    this.div = document.getElementById(div_name);
    this.data = data;
	this.div_name = div_name;
}

nv.RollPanel.prototype = {
    rotate : function(direction){
        switch(direction){
            case 'FWD' :
                this.panel_index++;
                if(this.panel_index >= this.data["data"].length) this.panel_index = 0;
                break;
            case 'BWD' :
                this.panel_index--;
                if(this.panel_index < 0) this.panel_index = this.data["data"].length - 1;
                break;
        }
        this.show(this.panel_index);
		if(this.div_name == 'pr_contents') pr_contents.innerHTML = this.data["data"][this.panel_index];
    },
    show : function(panel_index){
        if(this.div == null){
            return;
        }
        this.div.innerHTML = this.data["data"][panel_index];
    },
    move : function(index){
        if(index > this.data["data"].length - 1){
            return;
        }
        this.panel_index = index;
    },
    get_status : function(){
        return this.div != null ? true : false;
    }
}

nv.ElementCache = function(){
    this.items = new Array();
    this.item_count = 0;
    this.item_index = 0;
}

nv.ElementCache.prototype = {
    size : function(){
        return this.items.length;
    },
    add : function(key,value){
        if(!this.is_exists(key)){
            var child_panel = document.createElement("DIV");
            child_panel.style.display     = 'none';
            child_panel.innerHTML         = value;
            var hashval         = new Array();
            hashval['key']      = key;
            hashval['value']    = child_panel;
            this.items[this.item_count++] = hashval;
            this.items[key] = hashval;
        }
    },
    get : function(key){
        var div = this.items[key] ? this.items[key]['value'] : null;
        if(div == null){
        }
        return div;
    },
    set : function(key,value){
        var element = null;
        if((element = this.get(key)) != null){
            element[value] = value;
        }
    },
    current : function(){
        if(this.is_empty()) return;
        return this.items[this.item_index]['value'];
    },
    get_by_index : function(index){
        return (index < 0 || index >= this.items.length) ? null : this.items[index]['value'];
    },
    is_exists : function(key){
        for(i = 0 ; i < this.items.length ; i++){
            if(this.items[i]['key'] == key){ return true; }
        }
        return false;
    },
    is_empty : function(){
        return (this.items.length <= 0) ? true : false;
    }
}

nv.NewsPanel = function(div_name){
    this.appname= div_name;
    this.div    = document.getElementById(div_name);
    this.nvroll    = new Array();
    this.init_area= "";
    this.stop = true;
    this.speed = 5000;
    panel = this;
    this.panel = this;
}

nv.NewsPanel.prototype = {
    init : function(){
        var uri = new String(document.location);
        this.init_area = "NVMAIN";

        if(this.init_area == "NVMAIN"){
            this.init_rolling('NVMAIN');
            this.stop = false;
        }
    },
    init_rolling : function(area) {
        if(this.nvroll[0]){
            if(this.nvroll[0].get_status()) return;
        }

        this.nvroll[0] = new nv.RollPanel("main_contents",main_data[0]);
        this.nvroll[1] = new nv.RollPanel("pr_contents",pr_data[0]);

        if(this.init_area == 'NVMAIN'){
            this.nvroll[0].move(NVNEWS_INIT_ROLL_IDX);
            this.nvroll[1].move(NVNEWS_INIT_ROLL_IDX);
        }
        setTimeout("panel.rolling();",this.speed);
    },

    rotate : function(direction){
        for(var i = 0 ; i < this.nvroll.length ; i++){
            this.nvroll[i].rotate(direction);
        }
    },
    rolling : function(){
        if(this.stop == false){
            eval(this.appname + ".rotate('FWD')");
        }
        window.setTimeout(this.appname + ".rolling('FWD');",this.speed);
    },

    start : function(){this.stop = false;},
    pause : function(){this.stop = true;}
}