/* 配列処理関数 */
function arrayPush(arr,val){
    var num = arr.length;
    arr[num] = val;
    return arr;
}
/* onload処理オブジェクト */
function class_onloadlib(){
    this.onloadFunc = new Array();
    this.addFunc = addFunc;
    this.exec = exec;
    this.completed = false;
    
    function addFunc(fn){
        this.onloadFunc = arrayPush(this.onloadFunc, fn);
    }
    function exec(){
        for(var i = 0; i < this.onloadFunc.length; i++) {
            eval(this.onloadFunc[i]);
        }
        this.completed = true;
    }
}
var onload_obj = new class_onloadlib();
// onloadに関数を追加
function onload_add(fn){
    onload_obj.addFunc(fn);
}
function onload_exec(fn){
    onload_obj.exec();
}
window.onload = onload_exec;

// 外部URLを別のウィンドウやタブで開く
function externalLink(){
    var conf = {
        className:'externalLink'
    };
    var isMSIE = /*@cc_on!@*/false;
    var anchorList = document.getElementsByTagName('a');
    
    if(isMSIE)  {
        for (var i=0, len=anchorList.length; i<len; i++){
            var a = anchorList[i];
            if (
                a.getAttribute('href').match(/^http:/) &&
                !(a.getAttribute('href').match(/^http:\/\/archive-pro/)) && 
                !(a.getAttribute('href').match(/^javascript/)) 
                ){
                a.className = conf.className;
                a.onclick = function (){
                    window.open(this.getAttribute('href',2), '_blank');
                    return false;
                }
            } else if (a.getAttribute('href').match(/^(.)*\#(.)*/)) {
                var url = urlList(a.getAttribute('href'));
                if (url[9] == "intro") {
                    a.onclick = function (){
                        gotoTop();
                        return false;
                    }
                }
            }
        }
    } else {
        for (var i=0, len=anchorList.length; i<len; i++){
            var a = anchorList[i];
            if (
                a.getAttribute('href').match(/^http:/) && 
                !(a.getAttribute('href').match(/^http:\/\/archive-pro/)) 
            ){
                a.className = conf.className;
                a.onclick = function (){
                    window.open(this.getAttribute('href'), '_blank');
                    return false;
                }
            } else if (a.getAttribute('href').match(/^\#/)) {
                var url = urlList(a.getAttribute('href'));
                if (url[9] == "intro") {
                    a.onclick = function (){
                        gotoTop();
                        return false;
                    }
                }
            }
        }
    }
    function urlList(url) {
        var r = /^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;
        var a = r.exec (url);
    
        return a;
        // var url = 'http://example.com/path/to/file?query#fragment';
        // a[2]; 'http'
        // a[4]; 'example.com'
        // a[5]; '/path/to/file'
        // a[7]; 'query'
        // a[9]; 'fragment'
    }
    function gotoTop() {
        var c = {
            easing:100,
            step:30,
            fps:80
        };
        c.ms = Math.floor(1000/c.fps);
        var timerId;
        var param = {
            stepCount:0,
            startY:0,
            endY:0,
            lastY:0
        }
        function move() {
            if (param.stepCount == c.step) {
                // scroll_end
                window.scrollTo(getCurrentX(), param.endY);
            } else if (param.lastY == getCurrentY()) {
                // scroll
                param.stepCount++;
                window.scrollTo(getCurrentX(), getEasingY());
                param.lastY = getEasingY();
                timerId = setTimeout(move, c.ms);
            }
        }
        function getCurrentX() {
            return document.body.scrollLeft || document.documentElement.scrollLeft;
        }
        function getCurrentY() {
            return document.body.scrollTop || document.documentElement.scrollTop;
        }
        function getEasingY() {
            return Math.floor(getEasing(param.startY, param.endY, param.stepCount, c.step, c.easing));
        }
        function getEasing(start, end, stepCount, step, easing) {
            var s = stepCount / step;
            return (end - start) * (s + easing / (100 * Math.PI) * Math.sin(Math.PI * s)) + start;
        }
        clearTimeout(timerId);
        param.stepCount = 0;
        param.startY = param.lastY = getCurrentY();
        timerId = setTimeout(move, c.ms);
    }
}
onload_add('externalLink();');

function initRollOvers() {
    if (!document.getElementById){
        return;
    }
   
    var preLoads = new Array();
    var allImages = document.getElementsByTagName('img');
 
    for (var i = 0; i < allImages.length; i++) {       
        if (allImages[i].className == 'rollover') {
            var src = allImages[i].getAttribute('src');
            var ftype = src.substring(src.lastIndexOf('.'), src.length);
            var oSrc = src.replace(ftype, '_on'+ftype);
 
            //-- スワップ元、スワップ先画像の登録
            allImages[i].setAttribute('pSrc', src);
            allImages[i].setAttribute('oSrc', oSrc);
 
            //-- イメージのプリロード
            preLoads[i] = new Image();
            preLoads[i].src = oSrc;
 
            //-- イベントの設定
            allImages[i].onmouseover = function() {
                this.setAttribute('src', this.getAttribute('oSrc'));
            }
            allImages[i].onmouseout = function() {
                this.setAttribute('src', this.getAttribute('pSrc'));
            }
        }
    }
}
onload_add('initRollOvers();');

function containerSize() {
    var obj = window;
    if( window.opera ) {
        var w = obj.innerWidth;
        var h = obj.innerHeight;
    } else if( document.all ){              //ie4-
        if(typeof window.innerHeight != "undefined"){
            w = window.innerHeight;
            h = window.innerHeight;
        }else if(document.compatMode=='CSS1Compat'){
            w = document.documentElement.clientHeight;
            h = document.documentElement.clientHeight;
        }else{
            w = document.body.clientHeight;
            h = document.body.clientHeight;
        }
    } else if( document.getElementById ){   //n6-7, m1, s1
        var w = obj.innerWidth;
        var h = obj.innerHeight;
    }
    var intro = document.getElementById("intro");
    var container = document.getElementById("container");
    var content = document.getElementById("content");
    var footer = document.getElementById("footer");
    
    if(container.offsetHeight <= (h - intro.offsetHeight - footer.offsetHeight)) {
        //content.style.height = h - intro.offsetHeight - footer.offsetHeight - 16 + "px";
        content.style.height = h - intro.offsetHeight - footer.offsetHeight - 12 + "px";
    }
}
onload_add('containerSize();');

function dummy() {
    return false;
}


