function menuHover3(){
    $(this).find("ul.level3_animate").show('slide', {direction: 'left'}, 300);
}

function menuHoverOut3(){
    $(this).find("ul.level3_animate").hide('slide', {direction: 'left'}, 300);
}

function menuHover2(){
    $(this).find("ul.level2_animate").show('slide', {direction: 'up'}, 300);
}

function menuHoverOut2(){
    $(this).find("ul.level2_animate").hide('slide', {direction: 'up'}, 300);
}

$(document).ready(function(){
    $("a[rel='colorbox']").colorbox();
    
    var heightLi = 24;    
    
    // Klassen ersetzen
    $("#menu_top ul.level3").each(function(){
        $(this).removeClass("level3");
        $(this).addClass("level3_animate"); 
        // Höhe berechnen
        var lengthLevel3 = $(this).find("li").length;
        var heightLevel3 = (lengthLevel3 * heightLi) + 1;
        
        // Höhe anpassen
        $(this).css({'height' : heightLevel3});
        
        $("#menu_top ul.level1 li").hoverIntent(menuHover2, menuHoverOut2);        
    });
    
    $("#menu_top ul.level2").each(function(){
        $(this).removeClass("level2");
        $(this).addClass("level2_animate");
        
        var lengthLevel2 = $(this).find("li.level2").length;
        var heightLevel2 = lengthLevel2 * heightLi;
        $(this).css({'height' : heightLevel2});   
        $("#menu_top ul.level2_animate li").hoverIntent(menuHover3, menuHoverOut3);         
    });    
    
    // Scrolling werbung
	var $scrollingDiv = $("#scroll_ads");

	$(window).scroll(function(){			
        if($(window).scrollTop() >= 490 ){
		  $scrollingDiv.stop().animate({"marginTop": ($(window).scrollTop()) + "px"}, "slow" );
        }else{
          $scrollingDiv.stop().animate({"marginTop": "490px"}, "slow" );  
        }
	});

    // Voting Modul
    count = 0;
    counter_overall = 0;
    
    $(".vote_done").each(function(){
        $(this).find("li").each(function(){
            // Reset on new Poll
            if(counter_overall == 1){
                count = 0;
                counter_overall = 0;
            }
            count++;
            
            // Getting % of votes
            var height = 22;
            var original = $(this).html();
            var pp = $(this).html().split(': ');
            pp = pp[1].split(' %');
            
            // Setting 0% / 100% visual styles
            if(pp[0] == 0){pp[0] = 1}; 
            if(pp[0] == 100){pp[0] = 97.5};
            
            // Setting the Top-Pos of the text-elements
            if(count == 1){top_pos = 8}else{top_pos = 8+( (count - 1) * height);}
            
            // Initiating animation
            $(this).html('<div class="voted" style="width: 0px;"></div><div class="text_abso" style="top:'+top_pos+'px;">'+ original +'</div>');
            $(this).find('div.voted').animate({'width' : +pp[0]+"%"}, 1500, function(){
                $(this).parent().find('.text_abso').fadeIn(500);
            });                
        });
        counter_overall++;
    });
    
    $("#sidebar_widget_poll input[type=radio]").checkBox(); 
});
