$(function() {

    $(".date:not(.important)").hover(function() {

        $(this).stop().animate({
            backgroundColor: "#f26b1c"
        }, 300);
        $('.line', this).stop().animate({
            borderBottomColor: "#ffffff"
        }, 300);

    }, function() {

        $(this).stop().animate({
            backgroundColor: "#1d64cc"
        }, 300);
        $('.line', this).stop().animate({
            borderBottomColor: "#4881d6"
        }, 300);

    });

    /*open-animation*/
    $(".main-navi").each(function() {
        var navi = $(this);
        var items = navi.children('div');

        setTimeout(function() {
            navi.fadeIn(500);
        }, 500);

        setTimeout(function() {
            var index = 0;
            var interval = setInterval(function() {
                items.eq(index++).fadeIn(100);
                if (index >= items.length) {
                    clearInterval(interval);
                }
            }, 100);

            /*main-navi*/
            setTimeout(function() {
                items.each(function() {

                    var list = $('.list', this);
                    var listheight = list.height();
                    var section = $('.section a, .section', this);

                    $(this).hover(function() {
                        if (!$(this).hasClass('selected')) {
                            section.stop().animate({color: "#f26b1c"}, 300);
                        }
                        list.show().css({height: '0'}).stop().animate({height: listheight}, 300);

                    }, function() {
                        if (!$(this).hasClass('selected')) {
                            section.stop().animate({color: "#ffffff"}, 300);
                        }
                        list.stop().animate({height: 0}, 300, function() {
                            $(this).hide();
                        });

                    });
                });
            }, (items.length+1)*100);

        }, 600);

        $('.section', navi).click(function() {
            window.location = $('a', this).attr('href');
            return false;
        });
    });

    $(".main-navi .navi-ul span, .sec-navi .navi-ul span").hover(function() {
        if (!$(this).parent().hasClass('li-selected')) {
            $(this).parent().addClass('li-active');
        }
    }, function() {
        if (!$(this).parent().hasClass('li-selected')) {
            $(this).parent().removeClass('li-active');
        }
    });

    $(".feed-spacer").css({height: $('#footer .feedback').height() + 32});

    /*btt*/
    $(".feedback .btt, .service .btt").hover(function() {
        $(this).addClass('btt-hover');
    }, function() {
        $(this).removeClass('btt-hover');
    });

    /*.feedback*/




    var delay = 3000;
    $('.gallery-cell').each(function() {

        var cell = $(this);
        var index = 0;
        var elements = cell.children('div');
        var count = elements.length;

        var max = 0;
        elements.each(function() {
            if ($('img', this).height() > max) {
                max = $('img', this).height();
            }
        });
        cell.css('height', max+1);
        elements.css({position: 'absolute'});

        if (count > 1) {

            elements.eq(0).show();

            setInterval(function() {

                elements.eq(index % count).fadeOut(300);
                elements.eq((index+1) % count).fadeIn(300);

                index++;

            }, delay);
        } else {

            elements.show();

        }

        delay += 1000;
    });


});
