/*--------------------------------------------------
 *
 * 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
        });
    }
};



/**
 * fixed（IE6対応）
 */
$.auto.fixed =
{
    init:function()
    {
        var iefixed = function()
        {
            if ($.browser.msie)
            {
                var version = navigator.userAgent.match(/MSIE ([\d.]+)/)[1];
                if (!$.boxModel || version < 7.0)
                {
                    $(".pageTop").attr("style","position:absolute;right:0px;left:auto;bottom:0px;top:auto;");
                }
            }
        };
        $(window).scroll(function (){iefixed();});
        iefixed();
    }
};


/**
 * マウスonで画像を変更
 */
$.auto.imgover =
{
    init: function()
    {
        var hoge = "";
        $("img,input").each(function()
        {
            if ($(this).attr('class') != "imgover") return true;

            var src =  $(this).attr('src');
            var ftype = src.substring(src.lastIndexOf('.'), src.length);
            var hsrc = src.replace(ftype, '_on'+ftype);
            $(this).attr('hsrc', hsrc);

            $(this).mouseover(function()
            {
                hoge = $(this).attr("src");
                $(this).attr("src", $(this).attr("hsrc"));
            });

            $(this).mouseout(function()
            {
                $(this).attr("src", hoge);
            });
        });
    }
};


/**
 * 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;
        };

        $("#content").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');
            }
        })
    }
};


/**
 * タグクラウド
 */
$.auto.tagcloud =
{
    init: function()
    {
        $.ajax({
            type: "POST",
            url: "http://www.implant21.com/ajax/tag_cloud.text.php",
            dataType: "text",
            success: function(obj)
            {
                $("#tagcloud").html(obj);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                $("#tagcloud").html("読込失敗");
            }
        });
    }
};


