var b;

$(function(){

    b = $("body");

    // 画像切替
    $(".over",b).imgchange({
        name: "-o"
    });

    // 半透明マウスオーバー
    $(".hover",b).hover(function() {
        $(this).animate({opacity: 0.8},{duration: 150, easing: "swing"});
    }, function () {
        $(this).animate({opacity: 1},{duration: 150, easing: "swing"});
    });


    // ウィンドウサイズ変更時の背景ズレ
    $(window).resize(function() {
        widthMax();
    });
    function widthMax(){
        var wrapMax = $(window).width();
        if(wrapMax <= 1000) {
            $("#header,#global-navi",b).css("width", "1020px");
        } else {
            $("#header,#global-navi",b).css("width", "100%");
        }
    }
    widthMax();

    //テーブルソート
    if( b.is(".mypage") ){
        sortableTable("#newlecture");
    }

    function sortableTable( $val ){
        var $this = $( $val );
        var $table = new Array();
        //console.log( $this.attr('rows').length-1 ); //trの数

        //console.log( $($this[0].rows) );
        /*
        for( var i=0; i < $this.attr('rows').length; i++ ){
            $table.push( [ $this[0]rows.,])
        }*/

    }
});


new function(){
    if(window.opera || navigator.userAgent.indexOf("Firefox") != -1){
        var wordBreak = function() {
            var wordBreakClass = "wordBreak";
            var table = document.getElementsByTagName("table");
            for(var i=0,len=table.length ; i<len ; i++){
                var tbClass = table[i].className.split(/\s+/);
                for (var j = 0; j < tbClass.length; j++) {
                    if (tbClass[j] == wordBreakClass) {
                        recursiveParse(table[i])
                    }
                }
            }
        }
        var recursiveParse = function(pNode) {
            var childs = pNode.childNodes;
            for (var i = 0; i < childs.length; i++) {
                var cNode = childs[i];
                if (childs[i].nodeType == 1) {
                    recursiveParse(childs[i]);
                }else if(cNode.nodeType == 3) {
                    if(cNode.nodeValue.match("[^\n ]")){
                        var plTxt = cNode.nodeValue.replace(/\t/g,"")
                        var spTxt = plTxt.split("");
                        spTxt = spTxt.join(String.fromCharCode(8203));
                        var chNode = document.createTextNode(spTxt);
                        cNode.parentNode.replaceChild(chNode,cNode)
                    }
                }
            }
        }

    }else{
        var wordBreak = function() {
            if( document.styleSheets[0].addRule ){
                document.styleSheets[0].addRule(".wordBreak","word-break:break-all");
            }else if( document.styleSheets[0].insertRule ){
                document.styleSheets[0].insertRule(".wordBreak{word-break:break-all}", document.styleSheets[0].cssRules.length );
            }else{
                return false;
            }
        }
    }
    var addEvent = function(elm,listener,fn){
        try{
            elm.addEventListener(listener,fn,false);
        }catch(e){
            elm.attachEvent("on"+listener,fn);
        }
    }
    addEvent(window,"load",wordBreak);
}

