$(function() {
    var rotation = function(target) {
        $(target + ' .arrows').rotate({
            duration: 50000,
            angle: 0,
            animateTo: 360,
            callback: function() {
                rotation(target);
            },
            easing: function (x, t, b, c, d) {
                //console.debug(x, t, b, c, d);
                return (c / d) * t;
            }
        });
    }
    
    if ($('.cycle').size() > 0) {
        rotation('.cycle');
    }

    if ($('.cycle-small').size() > 0) {
        rotation('.cycle-small');
    }

    var dropdownFadeout = function() {
        var timeoutId = setTimeout(function() {
            $('#dropdown').fadeOut(200);
        }, 200);
        
        $('#dropdown').data('timeoutId', timeoutId);
    }

    $('.meny li.products').mouseenter(function() {
        clearTimeout($('#dropdown').data('timeoutId'));
        $('#dropdown').fadeIn(700);
    });

    $('.meny li.products').mouseleave(dropdownFadeout);
    $('#dropdown').hover(function() { clearTimeout($('#dropdown').data('timeoutId')); },
                         dropdownFadeout);

    // Make the whole buttons in the meny clickable
    $('#dropdown ul li').each(function() {
        $(this).click(function() {
            if ($(this).find('a').size() > 0)
                window.location.href = $(this).find('a').attr('href');
        });
    });

    // Footer column hover effect
    $('#footer .column').each(function() {
        $(this).hover(
            function() {
                $(this).find('.inner').addClass('hover');
            },
            function() {
                $(this).find('.inner').removeClass('hover');
            });
    });
});

