function tools() {};
tools.prototype = {
    body_id: $('body').attr('id'),
    body_class: $('body').attr('class'),
    sec: {
        scroll_to_pagetop: 500,
        slide_gnavi_child: 200,
        overlay_rollover : 250
    },
    
    // Image rollover
    imageRollover: function(obj) {
        obj.hover(function() {
            $(this).attr('src', $(this).attr('src').replace(/^(.+)(\.[a-z]+)$/, '$1_on$2'));
        }, function() {
            $(this).attr('src', $(this).attr('src').replace(/^(.+)_on(\.[a-z]+)$/, '$1$2'));
        }).each(function() {
            $(this).click(function() {
                $(this).attr('src', $(this).attr('src').replace(/^(.+)_on(\.[a-z]+)$/, '$1$2'));
            });
            $('<img>').attr('src', $(this).attr('src').replace(/^(.+)(\.[a-z]+)$/, '$1_on$2'));
        });
    },
    
    //Overlay rollover
    overlayRollover: function(obj) {
        var sec = this.sec.overlay_rollover;
        obj.hover(function() {
            $(this).append('<div class="overlay_rollover"></div>');
            $('> div.overlay_rollover', this)
                .fadeTo(0, 0)
                .fadeTo(sec, 0.75);
        }, function() {
            $('> div.overlay_rollover', this).remove();
        });
    },
    
    // Scroll to pagetop
    scrollToPagetop: function(obj) {
        var sec = this.sec.scroll_to_pagetop;
        obj.click(function() {
            $(window).scrollTo($(this).attr('href'), sec);
            return false;
        });
    },
    
    // Blank window
    blankWindow: function(obj) {
        obj.attr('target', '_blank');
    },
    
    // Global navigation
    globalNavigation: function(obj) {
        var body_id  = this.body_id;
        var current_class  = 'current';
        //$('ul', obj).hide();
        if (body_id != 'index') {
            var down_sec    = this.sec.slide_gnavi_child;
            var up_sec      = this.sec.slide_gnavi_child * 0.6;
            var def_padding = '1px 2px 2px';
            obj.each(function() {
                var toggle_elem = $('ul', this);
                var def_height  = toggle_elem.height();
                if ($(this).hasClass(body_id)) {
                    $(this).addClass(current_class);
                    var current_img = $('> a > img', this);
                    current_img.attr('src', current_img.attr('src').replace(/^(.+)(\.[a-z]+)$/, '$1_cu$2'));
                }
                $(this).hover(function() {
                    toggle_elem
                        .stop()
                        .slideDown(down_sec, setDefaultStyle);
                }, function() {
                    toggle_elem
                        .stop()
                        .slideUp(up_sec, setDefaultStyle);
                });
                function setDefaultStyle() {
                    toggle_elem
                        .height(def_height)
                        .css('padding', def_padding);
                }
            });
            this.imageRollover($('li > a > img', obj));
        }
        this.imageRollover($('> a > img', obj.not('.' + current_class)));
    }
}


var t = new tools();
/* Initialize */
$(function() {
    t.globalNavigation($('#gnavi > ul > li'));
    t.imageRollover($('img.rollover'));
    t.scrollToPagetop($('a[href^=#]'));
    t.blankWindow($('a.blank'));
});

