var head = document.getElementsByTagName('head')[0];
var scripts = head.getElementsByTagName('script');
for(var s = 0,num = scripts.length; s < num; s++){
    if(scripts[s].src.indexOf('common.js')){
        var dirPath = scripts[s].src.split('js/common.js')[0];
    }
}
var util = {
    setEvent: function(obj,eventType,func){
        if(this.isIE) {
            obj.setAttribute(eventType,new Function(func));
        } else {
            obj.setAttribute(eventType,func);
        }
    },
    isIE: (document.documentElement.getAttribute("style") == document.documentElement.style)
}
var changeImage ={
    attach: function(){
        var preloadImg = new Object();
        var preNum = 0;
        var images = document.getElementsByTagName('img');
        for(var i = 0,num = images.length;i < num; i++){
            var img = images[i];
            var imgSrc = img.src;
            if(imgSrc.indexOf('_f.') > -1 && img.parentNode.href){
                var newImgSrc = imgSrc.split('_f.')[0] + '_h.' + imgSrc.split('_f.')[1];
                preloadImg[preNum] = new Image();
                preloadImg[preNum].src = newImgSrc;
                var funcOnImg = 'changeImage.action(this,\'' + newImgSrc + '\')\;return false\;';
                var funcOutImg = 'changeImage.action(this,\'' + imgSrc + '\')\;return false\;';
                util.setEvent(img.parentNode,'onmouseover',funcOnImg);
                util.setEvent(img.parentNode,'onmouseout',funcOutImg);
                preNum++;
            }
        }
    },
    action: function(eventAnchor,imgSrc){
        eventAnchor.getElementsByTagName('img')[0].src = imgSrc;
    }
}
var pullDown = {
    setting: {
        showPosition: '31px',
        hidePosition: '-9999px',
        targetElementID: 'GLOBALNAV'
    },
    show: function(LI){
        LI.className = 'onFocus';
        if(LI.getElementsByTagName('ul')[0]){
            LI.getElementsByTagName('ul')[0].style.top = this.setting.showPosition;
        }
    },
    hide: function(LI){
        LI.className = 'onBlur';
        if(LI.getElementsByTagName('ul')[0]){
            LI.getElementsByTagName('ul')[0].style.top = this.setting.hidePosition;
        }
    },
    setEvent: function(){
        var targetEle = document.getElementById(this.setting.targetElementID);
        var lists = targetEle.getElementsByTagName('li');
        var anchors = targetEle.getElementsByTagName('a');
        var liOverFunc = 'pullDown.show(this)';
        var liOutFunc = 'pullDown.hide(this)';
        var aFocusFunc = 'pullDown.show(this.parentNode)';
        var aBlurFunc = 'pullDown.hide(this.parentNode)';
        var aFocusFuncSub = 'pullDown.show(this.parentNode.parentNode.parentNode)';
        var aBlurFuncSub = 'pullDown.hide(this.parentNode.parentNode.parentNode)';
        for(var i = 0; i < lists.length; i++){
            if(lists[i].parentNode.className != 'sub'){
                util.setEvent(lists[i],'onmouseover',liOverFunc);
                util.setEvent(lists[i],'onmouseout',liOutFunc);
            }
        }
        for(var i = 0; i < anchors.length; i++){
            if(anchors[i].parentNode.parentNode.className != 'sub'){
                util.setEvent(anchors[i],'onfocus',aFocusFunc);
                util.setEvent(anchors[i],'onblur',aBlurFunc);
            }else{
                util.setEvent(anchors[i],'onfocus',aFocusFuncSub);
                util.setEvent(anchors[i],'onblur',aBlurFuncSub);
            }
        }
    }
}
var sizeSet = {
    medium: '100%',
    larger: '125%',
    largest: '150%'
}
var fontChangeScript = {
    buttonSet: {
        label: {
            ja: '<img src="' + dirPath + 'images/text_fontsize.gif" width="74" height="18" alt="&#25991;&#23383;&#12469;&#12452;&#12474;&#65306;" />',
            en: '<img src="' + dirPath + 'images/english/text_fontsize.gif" width="74" height="18" alt="Font size: " />'
        },
        medium: {
            negative: {
                ja: '<a href="#" onclick="fontChangeScript.buttonAction(\'' + sizeSet.medium + '\',this);return false;"><img src="' + dirPath + 'images/button_fontsize_medium_n.gif" width="38" height="18" alt="&#65339;&#27161;&#28310;&#65341;" /></a>',
                en: '<a href="#" onclick="fontChangeScript.buttonAction(\'' + sizeSet.medium + '\',this);return false;"><img src="' + dirPath + 'images/english/button_fontsize_medium_n.gif" width="35" height="18" alt="[Medium]" /></a>'
            },
            active: {
                ja: '<a href="#" onclick="fontChangeScript.buttonAction(\'' + sizeSet.medium + '\',this);return false;"><img src="' + dirPath + 'images/button_fontsize_medium_a.gif" width="38" height="18" alt="&#65339;&#27161;&#28310;&#65341;" /></a>',
                en: '<a href="#" onclick="fontChangeScript.buttonAction(\'' + sizeSet.medium + '\',this);return false;"><img src="' + dirPath + 'images/english/button_fontsize_medium_a.gif" width="35" height="18" alt="[Medium]" /></a>'
            }
        },
        larger: {
            negative: {
                ja: '<a href="#" onclick="fontChangeScript.buttonAction(\'' + sizeSet.larger + '\',this);return false;"><img src="' + dirPath + 'images/button_fontsize_larger_n.gif" width="28" height="18" alt="&#65339;&#22823;&#65341;" /></a>',
                en: '<a href="#" onclick="fontChangeScript.buttonAction(\'' + sizeSet.larger + '\',this);return false;"><img src="' + dirPath + 'images/english/button_fontsize_larger_n.gif" width="34" height="18" alt="[Larger]" /></a>'
            },
            active: {
                ja: '<a href="#" onclick="fontChangeScript.buttonAction(\'' + sizeSet.larger + '\',this);return false;"><img src="' + dirPath + 'images/button_fontsize_larger_a.gif" width="28" height="18" alt="&#65339;&#22823;&#65341;" /></a>',
                en: '<a href="#" onclick="fontChangeScript.buttonAction(\'' + sizeSet.larger + '\',this);return false;"><img src="' + dirPath + 'images/english/button_fontsize_larger_a.gif" width="34" height="18" alt="[Larger]" /></a>'
            }
        },
        largest: {
            negative: {
                ja: '<a href="#" onclick="fontChangeScript.buttonAction(\'' + sizeSet.largest + '\',this);return false;"><img src="' + dirPath + 'images/button_fontsize_largest_n.gif" width="39" height="18" alt="&#65339;&#29305;&#22823;&#65341;" /></a>',
                en: '<a href="#" onclick="fontChangeScript.buttonAction(\'' + sizeSet.largest + '\',this);return false;"><img src="' + dirPath + 'images/english/button_fontsize_largest_n.gif" width="36" height="18" alt="[Largest]" /></a>'
            },
            active: {
                ja: '<a href="#" onclick="fontChangeScript.buttonAction(\'' + sizeSet.largest + '\',this);return false;"><img src="' + dirPath + 'images/button_fontsize_largest_a.gif" width="39" height="18" alt="&#65339;&#29305;&#22823;&#65341;" /></a>',
                en: '<a href="#" onclick="fontChangeScript.buttonAction(\'' + sizeSet.largest + '\',this);return false;"><img src="' + dirPath + 'images/english/button_fontsize_largest_a.gif" width="36" height="18" alt="[Largest]" /></a>'
            }
        }
    },
    makeButton: function(lang /* = ja */){    //write button
        if(lang == undefined){
            lang = 'ja';
        }
        if(this.setSize){
            if(this.setSize == sizeSet.medium){
                this.button1 = this.buttonSet.medium.active[lang];
            }else{
                this.button1 = this.buttonSet.medium.negative[lang];
            }
            if(this.setSize == sizeSet.larger){
                this.button2 = this.buttonSet.larger.active[lang];
            }else{
                this.button2 = this.buttonSet.larger.negative[lang];
            }
            if(this.setSize == sizeSet.largest){
                this.button3 = this.buttonSet.largest.active[lang];
            }else{
                this.button3 = this.buttonSet.largest.negative[lang];
            }
        }else{
            this.button1 = this.buttonSet.medium.active[lang];
            this.button2 = this.buttonSet.larger.negative[lang];
            this.button3 = this.buttonSet.largest.negative[lang];
        }
        this.changeItem =
            '<p id="FONTSIZE_CHANGER">' +
            this.buttonSet.label[lang] +
            this.button1 +
            this.button2 +
            this.button3 +
            '</p>';
        document.write(this.changeItem);
    },
    buttonAction: function(size,bAnchor){    //onclick
        this.body = document.getElementsByTagName('body')[0];
        if(this.body){
            this.body.style.fontSize = size;
        }
        this.buttons = bAnchor.parentNode.parentNode.getElementsByTagName('img');
        for(var i = 0, num = this.buttons.length; i < num; i++){
            this.buttons[i].src = this.buttons[i].src.replace('_a.gif','_n.gif');
        }
        bAnchor.getElementsByTagName('img')[0].src = bAnchor.getElementsByTagName('img')[0].src.replace('_n.gif','_a.gif');
        this.fontDate = new Date();
        this.fontDate.setTime(this.fontDate.getTime() + (7*24*60*60*1000));
        document.cookie = 'font-size=' + size + '; path=/; expires=' + this.fontDate.toGMTString();
    },
    checkCookie: function(){    //read cookie & set font size
        if(document.cookie.indexOf('font-size=') >= 0){
            this.cookieAll = document.cookie + ';'
            this.cookieF = this.cookieAll.indexOf('font-size=');
            this.cookieE = this.cookieAll.indexOf(';',this.cookieF);
            this.fontSizeData = this.cookieAll.substring(this.cookieF,this.cookieE);
            this.setSize = this.fontSizeData.split('=')[1];
            document.write('<style type="text/css">body {font-size: ' + this.setSize + ';}</style>');
        }
    }
}
fontChangeScript.checkCookie();
window.onload = function(){
    changeImage.attach();
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}