function getUTF(url, parameters, callback) {
  $.ajax({
    url: url,
    scriptCharset: 'utf8',
    data: parameters,
    success: callback,
    dataType: 'html'
  }).overrideMimeType('text/html; charset=UTF-8');
}

function loadSeminare() {
    getUTF('/seminare_portlet', {}, function(data) {
        $('#t_content').html(data);
        $('#seminare_tab').removeClass('nonactive_tab').addClass('active_tab');
        $('#news_tab').removeClass('active_tab').addClass('nonactive_tab');
        $('#n_all').fadeOut('slow', function() {
            $('#s_all').fadeIn();
        });
    });
}

function loadNews() {
    getUTF('/news_portlet', {}, function(data) {
        $('#t_content').html(data);
        $('#news_tab').removeClass('nonactive_tab').addClass('active_tab');
        $('#seminare_tab').removeClass('active_tab').addClass('nonactive_tab');
        $('#s_all').fadeOut('slow', function() {
            $('#n_all').fadeIn();
        });
    });
}

var rotated = [];
var position = 0;
var stopped = 0;

function doClick(elm) {
    $('.rot_item').hide();
    $('.active_slide').removeClass('active_slide');
    $(elm).addClass('active_slide');
    $('#'+elm.attr('rotid')).fadeIn();
}

function next() {
    if (stopped == 0) {
        doClick($('#'+rotated[position]));
    
        if (position==rotated.length-1)
            position = 0
        else position += 1;
    }
}

function stopRotator() {
    stopped = 1;
}

$(document).ready(function() {
    $('.rotated').each(function() {
        elm = $(this);
        rotated.push(elm.attr('id'));
    });
    position = 1;
    
    setInterval('next()', 5000);

    // cert rotator
    $('#portlet_cert').cycle({ 
        fx:     'fade', 
        timeout: 5000,
        height: 96,
        speed: 100,
    });
    
});

