// funkcia na ziskanie URL routera
var Router = function (route,params) {
    //parametre
    if (typeof(params) == 'object') {
        var p = '';
        $.each(params,function (name,value) {
            if (p != '') {
                p += '&';
            }
            p += escape(name)+'='+escape(value);
        });
        return Router(route)+'?'+p;
    }
    else {
        return LANGROOT + '/' + route;
    }
};
Router.route = function (route,params) {
    Router.gotoUrl(Router(route,params));
    return false;
}
Router.gotoUrl = function (url) {
    window.location.href = url;
    return false;
}

$(function () {
    //makeMainAnimation();
    
    if ($('body').is('.printOnLoad')) {
        window.print();
    }
    
    $('#nwac .newestarticles').each(function (idx, el) {
        if (idx != 0) {
            $(el).hide();
        }
    });
    
    $('#nwac_control a').click(function () {
        $('#nwac_control .active').removeClass('active');
        $(this).parent().addClass('active');
        var ot = $(this).attr('rel');
        
        $('#nwac .newestarticles').each(function (idx, el) {
            if ($(el).attr('class') == 'newestarticles ' + ot) {
                $(el).show();
            } else {
                $(el).hide();
            }
        });
    });
    
    $('#flac .newestarticles').each(function (idx, el) {
        if (idx != 0) {
            $(el).hide();
        }
    });
    
    $('#flac_control a').click(function () {
        $('#flac_control .active').removeClass('active');
        $(this).parent().addClass('active');
        var ot = $(this).attr('rel');
        
        $('#flac .newestarticles').each(function (idx, el) {
            if ($(el).attr('class') == 'newestarticles ' + ot) {
                $(el).show();
            } else {
                $(el).hide();
            }
        });
    });
    
    $('ul.pl-h-submenu').each(function (idx, el) {
        if ($(el).attr('rel') == 'collapsed') {
            $(el).hide();
        }
    });
    
    $('.pl-h-p').click(function () {
        var mid = $(this).attr('rel');
        var submenu = $('#' + mid);
        if ($(submenu).css('display') == 'none') {
            $(submenu).show();
        }
        else {
            $(submenu).hide();
        }
    });
    
    $('#il_cats_btn').toggle(function () {
        $('#il_cats').show();
    }, function () {
        $('#il_cats').hide();
    });
    
    if ($('#links_rss_preview').length > 0) {
        $('#links_rss_preview').load(Router('links/rss-load-new/'));
    }
});

function makeMainAnimation() {
    var animationImages = $('#mainAnimationSrc').val();
    if (animationImages) {
        eval('animationImages = ' + animationImages + ';');
        var ul = $('<ul></ul>').attr('id','mainAnimationImages');
        $.each(animationImages,function (idx,imgsrc) {
            ul.append('<li><img src="' + imgsrc + '" alt="[' + window.document.title + ']"></img></li>');
        });
        $('#mainAnimationSrc').after(ul);
        ul.innerfade({
            animationtype: 'fade',
            speed: 500,
            timeout: 5000
        });
    }
}