jQuery( document).ready( function( $){

    /**
     * INIT
     *
     */
    $('.font button').click( function(){
        var fontsize =  $( this).attr( 'id');
        //alert( fontsize);

        fontResize( fontsize);
    });
    function fontResize( fontsize){
        $( '.font button.active').removeClass( 'active');
        $( '#'+fontsize).addClass('active');

        switch( fontsize){
            case 'large':
                $( '.CONTENTS').css( 'font-size', '16px');
                break;
            default:
                $( '.CONTENTS').css( 'font-size', '14px');
                break;
        }

        //save cookie
        $.cookie( 'fontsize', fontsize, { expires:30, path: '/'});
    }
    //init fontsize
    var init_size = ( $.cookie( 'fontsize')) ? $.cookie( 'fontsize') : 'normal';
    fontResize( init_size);
    //topic path
    $( '.TOPIC-PATH>li[class!=current]').append( ' > ');


    $( '.tpl_table').each( function(){
        var head = $( this).children( '.head').html();
        var headClass = $( this).children( '.head').attr( 'class');
        var data = $( this).children( '.data').html();
        var thisClass = $( this).attr( 'class');
        var tpl  = '<table class="'+thisClass+'"><tr><td class="'+headClass+'">'+head+'</td><td class="data">'+data+'</td></tr></table>';

        $(this).replaceWith( tpl);
        $('.colorbox-frame').colorbox({
            iframe: true,
            width: "95%",
            height: "95%",
            opacity: 0.3,
            close: '閉じる'
        });
    });


    /**
     * ACCORDION
     *
     */
    $( '.accordion').accordion({
      header: '.header',
      autoHeight: false
    });



    /**
     * colorbox-frame
     *
     * COLORBOXのiframeモードを用いたサブウィンドウ表示
     */
    $('.colorbox-frame').colorbox({
        iframe: true,
        width: "95%",
        height: "95%",
        opacity: 0.3,
        close: '閉じる'
    });



    $( '.img_hover').hover(
        function(){
            before_img = $(this).attr( 'src');
            after_img  = before_img.replace( '_off', '_on');
            $(this).attr( 'src', after_img);
        },
        function(){
            before_img = $(this).attr( 'src');
            after_img  = before_img.replace( '_on', '_off');
            $(this).attr( 'src', after_img);
        }
    );


    $( '.HEADER .search .btn').click(
        function(){
            $(this).css( 'background', 'url(/lib/common/images/structure/btn_search_on.gif)');
        }
    );
});

