function termin_over(){
    if($(this).hasClass('open')){
        
    }else{
        $(this).parent().find('.open').each(function(){
            $(this).removeClass('open');
            $(this).find('.termin-content').slideUp(500);
        });
        $(this).find('.termin-content').slideDown(500);
        $(this).addClass('open');
        clearInterval(runthrough);
    }
}

function slide_termine($speed){
    if($i > $total+1){
        $i = 1;
    }   
    $("#sidebar_widget_calendar .termin:nth-child("+ $i +")").each(function(){
        $(this).parent().find('.open').each(function(){
            $(this).removeClass('open');
            $(this).find('.termin-content').slideUp($speed);
        });
        $(this).parent().find('.termin:nth-child('+ $i +')').find('.termin-content').slideDown($speed);
        $(this).parent().find('.termin:nth-child('+ $i +')').addClass('open');        
    });    
    $i++;
}

function termin_out(){}

function bind(){
     $("#sidebar_widget_calendar .termin").each(function(){
        $(this).hoverIntent(termin_over, termin_out);
     });    
}

$(document).ready(function(){

     $speed = 500;
     $interval = 50000000;    
     $i = 1;
     $total = $("#sidebar_widget_calendar .termin").length;
     
     slide_termine(500);
     
     $i = 1;
     bind();

      runthrough = setInterval( "slide_termine(" + $speed + ")", $interval);
 
     $(".head").click(function(){
         if($(this).parent().find('.content').hasClass('opened')){
             $("#calendar_contents .content").removeClass('opened').fadeOut(0);
             $(this).parent().find('.content').stop(true, true).fadeOut(0);
             $(this).parent().find('.content').removeClass('opened');    
             $("#calendar_contents .subhead_termin").fadeIn(100);
         }else{
             $("#calendar_contents .subhead_termin").fadeIn(100);
             $("#calendar_contents .content").removeClass('opened').fadeOut(0);
             $(this).parent().find('.content').stop(true, true).fadeIn(1200);
             $(this).parent().find('.content').addClass('opened');
             $(this).parent().find('.subhead_termin').fadeOut(0);
         }
     });
});
