// ロールオーバー
$(function () {
    $.rollover = {
        init: function () {
            $('a img,input[type="image"]').not('[src*="_on."]')
                .bind('mouseover', this.over)
                .bind('mouseout',  this.out)
                .each(this.preload);
        },

        over : function () {
            this.setAttribute('src', this.getAttribute('src').replace('_off.', '_on.'));
        },

        out : function () {
            this.setAttribute('src', this.getAttribute('src').replace('_on.', '_off.'));
        },

        preload : function () {
            new Image().src = this.getAttribute('src').replace('_off.', '_on.');
        }
    };

    $.rollover.init();
});

$(function(){
    //初期設定
    var $ul = $('div.senior_slide_window ul.senior_slider');
    var move = $ul.children('li').outerWidth({margin:true});
    
    if($ul.children().size() != 1){
        $ul.css("width", move * $ul.children('li').size()+"px");//li.height*数

        $ul.css("margin-left", -move +"px");//移動
        $ul.children('li:last').prependTo($ul);//最後のカラムを先頭へ移動
        

        if($ul.children().size() == 2){
            $ul.children().each(function(i, e){
                $(this).clone().appendTo($ul);
            });
            
            $ul.css("width", move * $ul.children('li').size()+"px");//li.height*数
        }
        
        $.slider = {
            init: function(){
            
            },
            moveNext: function(){

                $ul.animate({
                        marginLeft:parseInt($ul.css("margin-left")) -move + "px"
                    },"slow","swing",
                    function(){
                            $ul.css("margin-left", -move + "px");
                            $ul.children('li:first').appendTo($ul);
                    }
                );

            },
            movePrev: function(){
                $ul.animate({
                        marginLeft:parseInt($ul.css("margin-left")) + move + "px"
                    },"slow","swing",
                    function(){
                            $ul.css("margin-left", -move +"px");
                            $ul.children('li:last').prependTo($ul);
                });
            }
        };
        
        $('div.section.top div.senior p.left').click(function(){
            if(! $ul.is(':animated')){
                $.slider.movePrev();
            }
        });
        $('div.section.top div.senior p.right').click(function(){
            if(! $ul.is(':animated')){
                $.slider.moveNext();
            }
        });
        $('div.section.top div.senior p.left, div.section.top div.senior p.right').hover(function(){
            $(this).css('opacity', '0.7');
        },function(){
            $(this).css('opacity', '1');
        });
    }
});

//flatheight
$(window).bind('load',function(){
    var sets = [], temp = [];
    $('div.section div.navigation').each(function(i) {
        temp.push(this);
        if (i % 2 == 1) {
            sets.push(temp);
            temp = [];
        }
    });
    if (temp.length) sets.push(temp);
    $.each(sets, function() {
        $(this).flatHeights();
    });
});

$(function(){
    $("div.navigation:even").addClass("odd");
    $("div.navigation:odd").addClass("even");
});

