/* funkce najde div pomoci nazvu class */
function getElementsByClass(searchClass,node,tag) {
    var classElements = new Array();
    if ( node == null )
        node = document;
    if ( tag == null )
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
    for (i = 0, j = 0; i < elsLen; i++) {
        if ( pattern.test(els[i].className) ) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}

/* funkce, ktera posouva aktuality doleva a doprava */
function change_news(where)
{
    //najdeme element se tridou body
    var id = getElementsByClass('body');
    //vytahmene si z tohoto elementu hodnotu tagu id
    id = id[0].id;
    //vypreparujeme cislo aktuality
    id = id.split('_');
    id = id[1];
    
    //zjistime kolik novinek je celkem
    var hiddens = getElementsByClass('hidden');
    var max_id = hiddens.length;
    max_id = max_id - 1;
    
    //zjistime cislo aktuality na ktere se chceme posunout
    if(where == 'prev') new_id = parseInt(id) - 1;
    if(where == 'next') new_id = parseInt(id) + 1;
    
    //osetrime posun na neexistujici aktuality
    if(new_id < 0) new_id = max_id;
    if(new_id > max_id) new_id = 0;
    
    //nyni skryjeme puvodni aktualitu   
    document.getElementById('news_'+id).className = 'hidden'
    
    //a zobrazime novou
    document.getElementById('news_'+new_id).className = 'body'
    
    //a vratime false kvuli posunum na strance
    return false;
    
    //alert('visible id:'+id+', number of news: '+max_id+', move id:'+new_id);
}

/* funkce pro automaticke posouvani aktualit */
function autoswitch_news(time, stop)
{
    if(time == '') time = 10000;
    
    if(stop)
    {
        timer = clearTimeout(timer);
    }
    else
    {
        timer = setTimeout('change_news("next");autoswitch_news('+time+');', time);
    }
}
