/*--------------------------------------------------
 *
 * Version 1.0.0
 * jquery.init.js
 *--------------------------------------------------*/
$.auto = {
    init: function() {
        for (module in $.auto) {
            if ($.auto[module].init)
                $.auto[module].init();
        }
    }
};
$(document).ready($.auto.init);


/**
 * スムーズスクロール
 */
$.auto.scroll =
{
    init: function()
    {
        $("a[href*='#']").easingScroll({
            easing: "swing",
            duration: 400
        });
    }
};


/**
 * マウスonで画像を変更
 */
$.auto.imgover =
{
    init: function()
    {
        if (!document.getElementById) return;
        var aPreLoad = new Array();
        var sTempSrc;
        var setup = function(aImages) {
            for (var i = 0; i < aImages.length; i++) {
                if (aImages[i].className == 'imgover') {
                    var src = aImages[i].getAttribute('src');
                    var ftype = src.substring(src.lastIndexOf('.'), src.length);
                    var hsrc = src.replace(ftype, '_on'+ftype);
                    aImages[i].setAttribute('hsrc', hsrc);
                    aPreLoad[i] = new Image();
                    aPreLoad[i].src = hsrc;
                    aImages[i].onmouseover = function() {
                        sTempSrc = this.getAttribute('src');
                        this.setAttribute('src', this.getAttribute('hsrc'));
                    }
                    aImages[i].onmouseout = function() {
                        if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_on'+ftype, ftype);
                        this.setAttribute('src', sTempSrc);
                    }
                }
            }
        };
        var aImages = document.getElementsByTagName('img');
        setup(aImages);
        var aInputs = document.getElementsByTagName('input');
        setup(aInputs);
    }
};


/**
 * text,textareaのフォーカス取得時に背景色を変更
 */
$.auto.highlight =
{
    init: function()
    {
        var hoge = "";
        $(":text,textarea").each(function()
        {
            if($(this).attr('class') == "doNotHighlightThisInput")
            {
                return true;
            }
            $(this).focus(function ()
            {
                hoge = $(this).attr("class");
                $(this).addClass("inputHighlighted");
            });
            $(this).blur(function ()
            {
                $(this).removeClass($(this).attr("class"));
                $(this).addClass(hoge);
            });
        });
    }
};


/**
 * 現在のURLと同じLink先の状態を変更
 */
$.auto.currentlink =
{
    init: function()
    {
        var getAbsolutePath = function(path){
            var img = new Image();
            img.src = path;
            path = img.src;
            img.src = '#';
            return path;
        };

        $("#treatment_menu_list").find("a").each(function(){
            var href = $(this).attr("href");
            var absolutePath = getAbsolutePath(href);
            var isCurrentLisk = (absolutePath == location.href);
            var fragment = false;
            var a = absolutePath.split('://');
            var schema = a[0];
            if (a[1] !=null)
            {
                var d = a[1].split('/');
                var host = d.shift();
                var f = d.pop();
                var dirs = d;
                var file = f.split('?')[0].split('#')[0];
                var fn = file.split('.');
                var fileExtension = (fn.length == 1) ? '' : fn.pop();
                var fileName = fn.join('.');
                var fq = f.split('?');
                var query = (fq[1]) ? fq[1].split('#')[0] : '';
                var ff = f.split('#');
                fragment = (ff[1]) ? ff[1].split('?')[0] : '';
            }
            if (isCurrentLisk && !fragment)
            {
                $(this).addClass('current');
            }
        })
    }
};

