//Event Action

onload=onloadAction;
onresize=onresizeAction;

//2004.07.06 sasaki アットサーチからの連携用
mypath = window.location.pathname;
mypathflug = mypath.indexOf("from=atsearch");   //URLのパスをチェック
if(mypathflug == -1){
    atsearchFlg = true;
}
//-----------


function onloadAction(){
    doRectangleControl();
    initFrameHeight();
}

function onresizeAction(){
    resizeFrameHeight();
}

//Browser Check
var browserType=new checkBrowserType();
var osType=new checkOsType();
function checkBrowserType(){
    this.IE=(navigator.userAgent.indexOf("MSIE")!=-1);
    this.Gecko=(navigator.userAgent.indexOf("Gecko")!=-1);
    this.IE6=(navigator.userAgent.indexOf("MSIE 6.")!=-1);
    this.IE5=(navigator.userAgent.indexOf("MSIE 5.")!=-1);
    this.NC71=(navigator.userAgent.indexOf("Netscape/7.1")!=-1);
    this.NC70=(navigator.userAgent.indexOf("Netscape/7.0")!=-1);
    this.NC6=(navigator.userAgent.indexOf("Netscape/6.")!=-1);
    this.NC7=(navigator.userAgent.indexOf("Netscape/7.")!=-1);
    this.NC4=(navigator.userAgent.indexOf("Netscape/4.")!=-1);
}
function checkOsType(){
    this.Win=(navigator.appVersion.indexOf("Win")!=-1);
    this.Mac=(navigator.appVersion.indexOf("Mac")!=-1);
    this.Unix=(navigator.appVersion.indexOf("X11")!=-1);
}

//CSS Setting
if(!browserType.IE){
    document.write('<style type="text/css">body,td,th{font-size:small;color:#000000;}</style>');
}

//PreloadImages
function preloadImages(){
    var imgDir="/img/";
    var imgFileName=new Array();
    var imgArray=new Array();
    for(i=0;i<imgFileName.length;i++){
        imgArray[i]=new Image();
        imgArray[i].src=imgDir+imgFileName[i];
    }
}

//ChangeImages
function changeImages(){
    if (document.images){
        for(i=0;i<changeImages.arguments.length;i+=2){
            document[changeImages.arguments[i]].src=changeImages.arguments[i+1];
        }
    }
}

function changeThisImage(){
    if (document.images){
        changeThisImage.arguments[0].src=changeThisImage.arguments[1];
    }
}

//RectangleControl
rectangleFlg=0;

function rectangleControl(){
    rectangleFlg=1;
}

function doRectangleControl(){
    if(rectangleFlg){
        if(browserType.IE){
            if(document.all["rectangle"].scrollHeight<10){
                document.all["rectangle"].style.display="none";
            }
        }
        else{
            if(document.getElementById("rectangle").scrollHeight<10){
                document.getElementById("rectangle").style.display="none";
            }
        }
    }
}

//FrameSizeControl
frameFlg=false;

function initFrameHeight(){

    //2004.07.06 sasaki アットサーチからの連携用
    if(atsearchFlg){
        frameFlg = false;
    }

    if(frameFlg){
        var frameHeight=getFrameHeight("mainFrame");
        var documentHeight=getDocumentHeight();
        frameDif=documentHeight-frameHeight;
        resizeFrameHeight();
    }
}

function resizeFrameHeight(){
    if(frameFlg){
        var windowHeight=getWindowHeight();
        if(browserType.IE){
            document.all["mainFrame"].style.height=windowHeight-frameDif;
        }
        else{
            document.getElementById("mainFrame").style.height=windowHeight-frameDif;
        }
    }
}

function getFrameHeight(id){

    if(browserType.IE){
        var frameHeight=document.all[id].offsetHeight;
    }
    else{
        var frameHeight=document.getElementById(id).offsetHeight;
    }
    return frameHeight;
}

function getDocumentHeight(){
    if(browserType.IE && osType.Mac){
        var documentHeight=document.body.offsetHeight;
    }
    else{
        var documentHeight=document.body.scrollHeight;
    }
    return documentHeight;
}

function getWindowHeight(){
    if(browserType.IE){
        var windowHeight=document.body.clientHeight;
    }
    else{
        var windowHeight=window.innerHeight;
    }
    return windowHeight;
}

//SearchForm
function checkPrefGroup(groupid){
    if (document.forms["searchOption"].elements[groupid+"top"].checked==true){
        for(i=0;i<document.forms["searchOption"].elements.length;i++){
            if(document.forms["searchOption"].elements[i].id.indexOf(groupid+"_")!=-1){
                document.forms["searchOption"].elements[i].checked = true;
            }
        }
    }
    if (document.forms["searchOption"].elements[groupid+"top"].checked==false){
        for (i = 0; i <document.forms["searchOption"].elements.length; i++){
            if(document.forms["searchOption"].elements[i].id.indexOf(groupid+"_")!=-1){
                document.forms["searchOption"].elements[i].checked = false;
            }
        }
    }
}


//WriteCopy
function writeCopy(){
    var copyNum=Math.floor(Math.random()*copyArray.length);
    var str="";
    str+='';
    str+='<div class="topTitle" style="background-image:url(\''+copyArray[copyNum][0]+'\'); background-position:right;"><div style="background-image:url(\''+copyArray[copyNum][4]+'\'); background-repeat:no-repeat;"><a href="'+copyArray[copyNum][3]+'" onmouseover="startOpenAnimation();" onmouseout="startCloseAnimation();"><img src="/img/s.gif" width="100%" height="70" border="0" alt="'+copyArray[copyNum][1]+'"></a></div><div id="copyPalette" class="lh125" onmouseover="startOpenAnimation();" onmouseout="startCloseAnimation();">'+copyArray[copyNum][2]+'</div></div>';
    document.write(str);
}

//CopyPalette
var copyPaletteOffsetX=-600;
var copyPaletteOffsetY=200;
var fadeTimer=0;
var fadeCounter=0;

function startOpenAnimation(){
    showCopyPalette();
    clearTimeout(fadeTimer);
    if(browserType.IE && osType.Win){
        document.all["copyPalette"].filters.alpha.opacity=0;
        fadeinCopyPalette();
    }
}

function startCloseAnimation(){
    clearTimeout(fadeTimer);
    if(browserType.IE && osType.Win){
        fadeoutCopyPalette();
    }
    else{
        hideCopyPalette();
    }
}

function fadeinCopyPalette(){
    fadeCounter+=1;
    document.all["copyPalette"].filters.alpha.opacity=fadeCounter*10;
    document.all["copyPalette"].style.left=copyPaletteX-Math.round(Math.pow(10-fadeCounter,2)*0.2);
    if(fadeCounter<10){
        fadeTimer=setTimeout("fadeinCopyPalette()",10);
    }
}

function fadeoutCopyPalette(){
    fadeCounter-=1;
    document.all["copyPalette"].filters.alpha.opacity=fadeCounter*10;
    document.all["copyPalette"].style.left=copyPaletteX-Math.round(Math.pow(10-fadeCounter,2)*0.2);
    if(fadeCounter>0){
        fadeTimer=setTimeout("fadeoutCopyPalette()",10);
    }
}

function showCopyPalette(){
    //PalettePositionSet
    var WindowWidth=document.body.clientWidth;
    if(WindowWidth<980 && WindowWidth>780){
        copyPaletteX=WindowWidth+copyPaletteOffsetX;
    }
    else if(WindowWidth<780){
        copyPaletteX=780+copyPaletteOffsetX;
    }
    else{
        copyPaletteX=Math.floor((WindowWidth+980)/2)+copyPaletteOffsetX;
    }
    copyPaletteY=copyPaletteOffsetY;

    if(browserType.IE){
        document.all["copyPalette"].style.visibility="visible";
        document.all["copyPalette"].style.left=copyPaletteX;
        document.all["copyPalette"].style.top=copyPaletteY;
    }
    else{
        document.getElementById("copyPalette").style.visibility="visible";
        document.getElementById("copyPalette").style.left=copyPaletteX;
        document.getElementById("copyPalette").style.top=copyPaletteY;
    }
}

function hideCopyPalette(){
    if(browserType.IE){
        document.all["copyPalette"].style.visibility="hidden";
        document.all["copyPalette"].style.left=0;
    }
    else{
        document.getElementById("copyPalette").style.visibility="hidden";
        document.getElementById("copyPalette").style.left=0;
    }
}



function search(){

    if(document.forms["hallsrh"].elements["searchMode"][0].checked){

        document.forms["nmsrh"].elements["nmsrh"].value = document.forms["hallsrh"].elements["srhkey"].value;
        document.forms["nmsrh"].submit();

    }else if(document.forms["hallsrh"].elements["searchMode"][1].checked){

        document.forms["adsrh"].elements["adsrh"].value = document.forms["hallsrh"].elements["srhkey"].value;
        document.forms["adsrh"].submit();

    }else{

        document.forms["stsrh"].elements["stsrh"].value = document.forms["hallsrh"].elements["srhkey"].value;
        document.forms["stsrh"].submit();
    }


}

// -*- coding:utf-8 -*-
(function(){
    var targets = [];
    if(document.querySelectorAll){
        targets = document.querySelectorAll('div.socialplugins');
    }else if(document.getElementsByClassName){
        targets = document.getElementsByClassName('.socialplugins');
    }else{
        var divs = document.getElementsByTagName('div');
        for(var i = 0, l = divs.length; i < l; i++){
            if(divs[i] && divs[i].className && divs[i].className.match(/socialplugins/)){
                targets.push(divs[i]);
            }
        }
    }

    var useMixiCheck = false;
    var createHTML = function(tu, ap, opt){
        ap = ap.split(',');
        var definition = {
            twitter : '<iframe allowtransparency="true" frameborder="0" scrolling="no" src="http://platform.twitter.com/widgets/tweet_button.html?url='+tu+'" style="width:130px; height:21px;"></iframe>',
            mixi : '<a href="http://mixi.jp/share.pl" class="mixi-check-button" data-url="'+tu+'" '+(opt && opt.mixi && opt.mixi.apikey ? 'data-key="'+opt.mixi.apikey+'"' : '')+'>mixiチェック</a>',
            gree : '<iframe src="http://share.gree.jp/share?url='+tu+'&type=0&height=20" scrolling="no" frameborder="0" marginwidth="0" marginheight="0" style="border:none; overflow:hidden; width:70px; height:20px;" allowTransparency="true"></iframe>',
            facebook : '<iframe src="http://www.facebook.com/plugins/like.php?href='+tu+'&amp;layout=button_count&amp;show_faces=true&amp;width=50&amp;action=like&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:90px; height:21px;" allowTransparency="true"></iframe>'
        };
        var htmlText = '';
        for(var i = 0, l = ap.length; i < l; i++){
            htmlText += '<li>'+definition[ap[i].toLocaleLowerCase()]+'</li>';
        }
        return '<ul>'+htmlText+'</ul>';
    };

    for(var i = 0, l = targets.length; i < l; i++){
        var mixiPluginAPIKEY = targets[i].getAttribute('data-nifty-socialplugins-mixi-apikey');
        if(!mixiPluginAPIKEY){
             continue;
        }
        var targetUrl = targets[i].getAttribute('data-nifty-socialplugins-url') || location.protocol+'//'+location.hostname+location.pathname+(location.search ? location.search : '');
        var applySocialPlugins = targets[i].getAttribute('data-nifty-socialplugins-apply') || 'mixi,gree,facebook';
        if(/mixi/.test(applySocialPlugins)){
            useMixiCheck = true;
        }
        targets[i].innerHTML = createHTML(targetUrl, applySocialPlugins, {mixi:{apikey: mixiPluginAPIKEY}});
    }

    //
    if(useMixiCheck){
        var mixiCheckScript = document.createElement('script');
        mixiCheckScript.setAttribute('type', 'text/javascript');
        mixiCheckScript.setAttribute('src', 'http://static.mixi.jp/js/share.js');
        document.body.insertBefore(mixiCheckScript, null);
    }
})();


