// mouseover script
// @param なし
// @return なし
$(function imgOver() {
    $('img, form input:image').each(function() {
        var node = this;
        if(node.src.match("_off.")) {
            node.originalSrc = node.src;
            node.temporarySrc = node.originalSrc.replace(/_off/,'');
            node.rolloverSrc = node.temporarySrc.replace(/(\.gif|\.jpg|\.png)/,'_on'+"$1");
            node.activeSrc = node.temporarySrc.replace(/(\.gif|\.jpg|\.png)/,'_active'+"$1");
            //画像のプリロード処理開始
            preloadImage(node.rolloverSrc);
            //Mouseover
            node.onmouseover = function() {
                if(this.className!='active') {
                    this.src = this.rolloverSrc;
                }
            }
            //Mouseout
            node.onmouseout = function() {
                if(this.className!='active') {
                    this.src = this.originalSrc;
                }
            }
        }
    });
});

// 画像のプリロードを行う関数
// @param string 画像のパス
// @return なし
preloadImages = [];
preloadImage = function(path) {
    var pre = preloadImages;
    var len = pre.length;
    pre[len] = new Image();
    pre[len].src = path;
}


//データ表示テーブルの最後のthとtdにクラスを追加
$(function addTrClass() {
    $("table.data tr:last-child th").addClass('bot');
    $("table.data tr:last-child td").addClass('bot');
    $('#SERBOX .resultbox table td.databox dl:first-child').addClass('top');
    $('#SERBOX .resultbox .photobox li:first-child').addClass('top');
    $('#MYBOX .mycolum .infobox .listbox .inner table tr:last-child').addClass('bot');
});

//外部リンクにクラス名「external」、target="_blank"を追加
$(function addBlankExtLink() {
    var selfDomain = document.domain;
    $('a').each(function() {
        if((this.href.indexOf(selfDomain)==-1) && (this.href.indexOf('mailto')==-1) && (this.href.indexOf('http://www.adobe.com/')==-1)) {
            $(this).addClass('external');
            $(this).attr('target','_blank');
        }
    });
});

//マイページ応募情報削除
function deleteApply(url) {
    if(confirm("この応募履歴を削除します。\nこの操作は取り消せません。よろしいですか")) {
        location.href = url;
        return true;
    } else {
        return false;
    }
}

//マイページ応募情報削除
function deleteMailMessage(url) {
 if(confirm("このメールを削除します。\nこの操作は取り消せません。よろしいですか")) {
  location.href = url;
 }
} 

//backToTop
function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }

    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }

    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;

    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));

    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 25);
    }
}
