$(document).ready(function ()
{
    // Main menu clickable li items

    $('ul#menu > li > a').each(function ()
    {
        var src = $(this).attr('href');
        var parent = $(this).parent();
    
        $(parent).click(function ()
        {
            location.href = src;
            return false;
        });
    });

    // Dashoboard sveze

    $(document).ready(function ()
    {
        var currentNews = 0;

        function sveze ()
        {
            var items = $('.dashboard > .item.sveze > .news-list > li');
            if (! items[currentNews]) { currentNews = 0; }
            var item = items[currentNews];

            $('.dashboard > .item.sveze > .date > .content').html($('.date', item).html());
            $('.dashboard > .item.sveze > .title > .content').fadeOut(200, function () {
                $(this).html($('.title', item).html()).fadeIn(400);
            });

            currentNews += 1;
        }
        
        sveze();
        var timer = setInterval(sveze, 5000);

        $('.dashboard > .item.sveze > ul.news-list');
    });

    // Dashboard koledar
    
    $(document).ready(function ()
    {
        function set_active_days ()
        {
            $('.dashboard > .item.koledar > .days > .days > li').unbind('click').removeClass('active');

            $('.dashboard > .item.koledar > .days > .days > li > .content > a').each(function (i, el)
            {
                var element = $(el);
                var parents = $(el).parents('li');

                $(parents).each(function (i, el) {
                    $(el).addClass('active');

                    $(el).click(function () {
                        location.href = element.attr('href');
                    });
                });
            });
        }

        set_active_days();
        
        $('.dashboard > .item.koledar > .month > .change').live('click', function ()
        {
            var url = $(this).attr('href');
            var days = $('.dashboard > .item.koledar > .days > .days > li > .content');
        
            $('.dashboard > .item.koledar > .days > .days > li').addClass('sliding');
        
            days.animate({marginLeft: "-40px", opacity: 0}, 300);
        
            $('.dashboard > .item.koledar > .month > a.month > .content').fadeOut(300, function () {
        
                $(this).html('');
            
                $.get(url, function (data) {
            
                    data = $(data);
                
                    $('.days > .days > li > .content', data).each(function (i, el) {
                        $(days[i]).html($(el).html());
                    });                
                    
                    set_active_days();
                    
                    days.animate({marginLeft: "0px", opacity: 1}, 300, function () {
                        $('.dashboard > .item.koledar > .days > .days > li').removeClass('sliding');
                    });
                    $('.dashboard > .item.koledar > .month').html($('.month', data).html());
                });
            });
        
            return false;
        });   
    });
});

