$(function(){  

//フォントサイズ設定  
    var FontSize = [];  
    FontSize["S"] = 100;  
    FontSize["M"] = 116;  
    FontSize["L"] = 131;  

//フォントサイズ変更ボタン設定  
    var ChangeBtn = "#fontSize img";  
    var SearchImg = ["#fontS img","#fontM img","#fontL img"];  

//フォントサイズ変更関数  
    function FontSizeSet(fs){  
        $("#changeArea").css("font-size",fs+"%");  
    };

//画像置換関数  
    function OnFont(){  
        $(this).attr("src",$(this).attr("src"));  
    };  
    function OvFont(io){  
        $(io).attr("src",$(io).attr("src").replace(/^(.+)(\.[a-z]+)$/,"$1_ov$2"));  
    };  
    function OffFont(io){  
        $(io).attr("src",$(io).attr("src").replace(/^(.+)_ov(\.[a-z]+)$/,"$1$2"));  
    };  

//クッキー設定関数  
    function FontCookie(ck){  
        $.cookie("fontsize",ck,{path:'/',expires:7});  
    };  

//クッキー確認関数  
    function CookieChack(fs){  
        return $.cookie("fontsize")==fs;  
    };  

//ロード時表示設定  
    function LoadFont(fs,si){  
        FontSizeSet(FontSize[fs]);  
        OvFont(SearchImg[si]);  
    };  

    if(CookieChack("fontS")){  
        LoadFont("S",0);  
    }  
    else if(CookieChack("fontM")){  
        LoadFont("M",1);  
    }  
    else if(CookieChack("fontL")){  
        LoadFont("L",2);  
    }  
    else {  
        FontCookie("fontS");  
        LoadFont("S",0);  
    };  

//画像プリロード設定  
    function ImgPreload(io){  
        $(ChangeBtn).not(SearchImg[io]).each(function(){  
            $("<img>").attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/,"$1_ov$2"));  
        });  
    };  

    if(CookieChack("fontS")){  
        ImgPreload(0);  
    }  
    else if(CookieChack("fontM")){  
        ImgPreload(1);  
    }  
    else if(CookieChack("fontL")){  
        ImgPreload(2);  
    };  

//ホバーイベント  
    $(ChangeBtn)  
    .hover(  
    function(){  
        if(!$(this).attr("src").match("_ov")){  
            OvFont(this);  
        };  
    },  

    function(){  
        if($(this).attr("src").match("_ov")){  
            if(CookieChack("fontS")){  
                OffFont(SearchImg[1]),OffFont(SearchImg[2]);  
            }  
            else if(CookieChack("fontM")){  
                OffFont(SearchImg[0]),OffFont(SearchImg[2]);  
            }  
            else if(CookieChack("fontL")){  
                OffFont(SearchImg[0]),OffFont(SearchImg[1]);  
            };  
        };  
    });  

//クリックイベント  
    function ClickFont(ck,fs,io1,io2){  
        FontCookie(ck);  
        FontSizeSet(FontSize[fs]);  
        OffFont(SearchImg[io1]),OffFont(SearchImg[io2]);  
        OnFont();  
    };  

    $(SearchImg[0]).click(function(){  
        ClickFont("fontS","S",1,2);  
    });  
    $(SearchImg[1]).click(function(){  
        ClickFont("fontM","M",0,2);  
    });  
    $(SearchImg[2]).click(function(){  
        ClickFont("fontL","L",0,1);  
    });  

}); 



function printFontChange(){
  var str = "";

  str  = '<div id="FontChange">' ;
//  str += '<div id="FontChangeLineL"><img src="/common/img/spacing.gif" width="1" height="1" /></div>' ;
  str += '<div id="FontChangeCore">' ;
  str += '<ul id="fontSize">' ;
  str += '<li id="fontS"><img width="23" height="23" src="/common/img/btn_fontchange_s.gif" alt="小"></li>' ;
  str += '<li id="fontM"><img width="23" height="23" src="/common/img/btn_fontchange_m.gif" alt="中"></li>' ;
  str += '<li id="fontL"><img width="23" height="23" src="/common/img/btn_fontchange_l.gif" alt="大"></li>' ;
  str += '</ul>' ;
  str += '</div>' ;
//  str += '<div id="FontChangeLineR"><img src="/common/img/spacing.gif" width="1" height="1" /></div>' ;
  str += '<div class="clear"><img src="/common/img/spacing.gif" width="1" height="1" /></div>' ;
  str += '</div>' ;

  document.write(str);
}


