$(function(event) {
    $('html').addClass($('body').attr('class'));
    if ($('body#index').length) {
        $('div.menubox').click(function(event) {
            event.preventDefault();
            event.stopPropagation();
            window.open($(this).children('a').attr('href'), '_self');
        });
        $('div#saloninfo div.inbox p').each(function(idx, elem) {
            var clkbox = $('<a>');
            $(elem).addClass('iepngfix').parent().append(clkbox.css({
                position: 'absolute',
                top: $(elem).position().top,
                left: $(elem).position().left + 10,
                width: $(elem).width(),
                height: $(elem).height(),
                backgroundColor: '#fff',
                opacity: 0.0,
                cursor: 'pointer'
            }).attr('href', $(elem).prev('a').attr('href')));
        });
        var f = function() {
            $('a#calendarprev, a#calendarnext').click(function(event) {
                event.preventDefault();
                event.stopPropagation();
                $('#calendarread').load($(this).attr('href'),{}, f);
            });
        };
        $('#calendarread').load('http://www.pineapples.co.jp/calendar.php', {}, f);
    }
    
    if ($('body#topics.ho').length) {
        $.ajax({
            url: 'http://www.pineapples.co.jp/blog/topicho/index.html',
            cache: false,
            success: function(html){
                $("div#topicsbox").html(html);
                var id = document.location.toString().split('#')[1];
                window.scrollTo($('#'+id).offset().left, $('#'+id).offset().top);
            }
        });
    }
    
    if ($('body#topics.jo').length) {
        $.ajax({
            url: 'http://www.pineapples.co.jp/blog/topicjo/index.html',
            cache: false,
            success: function(html){
                $("div#topicsbox").html(html);
                var id = document.location.toString().split('#')[1];
                window.scrollTo($('#'+id).offset().left, $('#'+id).offset().top);
            }
        });
    }
    
    if ($('body#topics.in').length) {
        $.ajax({
            url: 'http://www.pineapples.co.jp/blog/topicin/index.html',
            cache: false,
            success: function(html){
                $("div#topicsbox").html(html);
                var id = document.location.toString().split('#')[1];
                window.scrollTo($('#'+id).offset().left, $('#'+id).offset().top);
            }
        });
    }
    
    if ($('body#index.ent').length) {
        $.ajax({
            url: 'blog/topics.html',
            cache: false,
            success: function(html){
                $("#topics").html(html);
            }
        });
    }
    
    if ($('body#index.ho').length) {
        $.ajax({
            url: 'http://www.pineapples.co.jp/blog/topicho.html',
            cache: false,
            success: function(html){
                $("#topics").html(html);
            }
        });
    }
    
    if ($('body#index.jo').length) {
        $.ajax({
            url: 'http://www.pineapples.co.jp/blog/topicjo.html',
            cache: false,
            success: function(html){
                $("#topics").html(html);
            }
        });
    }
    
    if ($('body#index.in').length) {
        $.ajax({
            url: 'http://www.pineapples.co.jp/blog/topicin.html',
            cache: false,
            success: function(html){
                $("#topics").html(html);
            }
        });
    }
    
    if ($('body#answer01').length || $('body#answer02').length) {
        var pageId = location.href.split('#')[1];
        pageId = $('#' + pageId);
        if (pageId.length) {
            var colors = [255, 255, 0];
            var color;
            setTimeout(function() {
                color = '#' + colors[0].toString(16) + colors[1].toString(16) + (colors[2].toString(16).length == 1? '0' + colors[2].toString(16) : colors[2].toString(16));
                pageId.css({backgroundColor: color});
                colors[2] += 5;
                if (colors[2] < 255) setTimeout(arguments.callee, 30);
            }, 30);
        }
    }
    if ($('body#style').length) {
        $('#styles a').click(function(event) {
            event.preventDefault();
            event.stopPropagation();
            /* $('#ajaxdata').load($(this).attr('href'),{}); */
            $.ajax({
                url: $(this).attr('href'),
                cache: false,
                success: function(html){
                    $("#ajaxdata").html(html);
                }
            });
        });
        $('#styles a').hover(oppOver,function(){});
    }
    
    if ($('body#staff').length) {
        $('.staffThumbBox a').click(function(event) {
            event.preventDefault();
            event.stopPropagation();
            /* $('#staffbox').load($(this).attr('href'),{}); */
            $.ajax({
                url: $(this).attr('href'),
                cache: false,
                success: function(html){
                    $("#staffbox").html(html);
                }
            });
        });
        $('.staffThumbBox a').hover(oppOver,function(){});
    }
    if ($('body#reservation').length) {
        var jo_in01 = $('#time01').children().eq(0).nextAll();
        var jo_in02 = $('#time02').children().eq(0).nextAll();
        var jo_in03 = $('#time03').children().eq(0).nextAll();
        
        var ho01 = $('#time01').children().eq(2).nextAll();
        var ho02 = $('#time02').children().eq(2).nextAll();
        var ho03 = $('#time03').children().eq(2).nextAll();
        
        var hostylist = $('#stylist').children().filter('.ho');
        var jostylist = $('#stylist').children().filter('.jo');
        var instylist = $('#stylist').children().filter('.in');
        
        $('#stylist option').each(function() {
            if ($('#store').attr('value') == $(this).attr('class')) $(this).attr('disabled', false);
        });

        $('#store').change(function(event) {
            $('#time01,#time02,#time03').each(function() {$(this).children().eq(0).nextAll().remove();});
            $('#stylist').children().eq(3).nextAll().remove();
            var kls = $(this).attr('value');            
            if (kls == 'ho') {
                ho01.each(function() {$(this).appendTo($('#time01'))});
                ho02.each(function() {$(this).appendTo($('#time02'))});
                ho03.each(function() {$(this).appendTo($('#time03'))});
                hostylist.each(function() {$(this).appendTo($('#stylist'))}).attr('disabled', false);
            } else {
                jo_in01.each(function() {$(this).appendTo($('#time01'))});
                jo_in02.each(function() {$(this).appendTo($('#time02'))});
                jo_in03.each(function() {$(this).appendTo($('#time03'))});
                if (kls == 'jo') {
                    jostylist.each(function() {$(this).appendTo($('#stylist'))}).attr('disabled', false);
                } else {
                    instylist.each(function() {$(this).appendTo($('#stylist'))}).attr('disabled', false);
                }
            }
        });
        if ($('body.ho').length) {
            $('#time01,#time02,#time03').each(function() {
                $(this).children().eq(1).attr('disabled', true);
                $(this).children().eq(2).attr('disabled', true);
            });
        }
    }
});

function oppOver(event) {
    var op = 50;
    var elem = $(event.target);
    var timeId = setInterval(function() {
        elem.css({opacity: op / 100});
        op += 10;
        if (op > 100) clearInterval(timeId);
    }, 15);
}



//スライドショー
 $(window).load(function() {
    $('#slider').nivoSlider({
    effect:'fade',
    slices:5,
    animSpeed:500, //画像が切り替わるスピード
    pauseTime:10000, //画像が切り替わるまでの時間
    startSlide:0, //最初に表示する画像
    directionNav:true, //矢印を表示する
    directionNavHide:true, //マウスを乗せたときに矢印を表示
    controlNav:true, //1,2,3...
    controlNavThumbs:false, //下にサムネイルを使う場合
    controlNavThumbsSearch: '.jpg',
    controlNavThumbsReplace: '_thumb.jpg',
    keyboardNav:true, //Use left & right arrows
    pauseOnHover:true, //オンマウスで画像が止まる
    manualAdvance:false, //Force manual transitions
    captionOpacity:0.8, //Universal caption opacity
    beforeChange: function(){},
    afterChange: function(){},
    slideshowEnd: function(){} 
    });
  });
