﻿// custom_page
// 2006.12.11
// require event.js

var CustomPage_list = [];

function GetCustomPage(index) {
    return CustomPage_list[index];
}

function CustomPage_scrollEvent(index) {
    var customPage = GetCustomPage(index);
    document.body.scrollTop = customPage.maintainScrollTop;
    event.returnValue = false;
    event.cancelBubble = true;

    return false;
}

function CustomPage(coverImage) {
    this.index = CustomPage_list.length;
    CustomPage_list[CustomPage_list.length] = this;
    this.customEventScroll;
    this.maintainScrollTop;
    if(coverImage) this.coverImage = coverImage;
}

CustomPage.prototype.enable = function(value) {
    var divCover = this.getCover();
    if(value) {
        //if(this.customEventScroll) removeScrollEvent('custom_page_scroll_event' + this.index);
        divCover.style.visibility = 'hidden';
    }else {
        //if(!this.customEventScroll) this.customEventScroll = new CustomEvent('custom_page_scroll_event' + this.index, CustomPage_scrollEvent, 11, this.index);
        //addScrollEvent(this.customEventScroll);
        divCover.style.visibility = 'visible';
        this.maintainScrollTop = document.body.scrollTop;
    }
}

CustomPage.prototype.getCover = function() {
    var divCover = document.getElementById('div_custom_page_cover');
    if(!divCover) {
        divCover = document.createElement('DIV');
        divCover.id = 'div_custom_page_cover';
        divCover.align = 'center';
        divCover.style.position = 'absolute';
        divCover.style.width = document.body.clientWidth;
        divCover.style.height = document.body.clientHeight;
        divCover.style.backgroundImage = 'url(' + this.coverImage + ')';
        divCover.style.zIndex = 1000;
        
        document.body.appendChild(divCover);
    }
    divCover.style.top = document.body.scrollTop;
    divCover.style.left = document.body.scrollLeft;
    
    return divCover;
}
