document.observe('dom:loaded', function() {

    Cufon.replace('#mainarticles .box h2 a, #mainarticles .box h1 a, #mainarticles .box h1 strong, .maincontent h1, .nummer, #radio h1, .contest li .position, .contest .voting .total strong', {
        fontFamily: 'primary',
        hover: true
    });

    Cufon.replace('#mainarticles h2 a, .header h3, h3.header, .articles h2 a, .bookmarks li a em, #footer h3, #menu>li>a, #mainarticles h3, .textfield h4, .author h4, .column h3, .comments h3, .discussion h3, .form h3 strong, .maincontent h2, .getdata label em, .addaction .getdata h3, .login div h3, .subjects li strong, .actions a, .actionssearch dt, .impbutton-big, .cat-choice h3, #tag_form h3, .infotext p.date strong', {
        fontFamily: 'second',
        hover: true
    });

    /* .stats h3 strong */
    //setTimeout("Effect.Fade('message')",3000);

    /*
    //$$('.header h3').update($(this).down('.cufon-alt'));

    $$('.bookmarks').each(function(tab_group){
      new Control.Tabs(tab_group);
    });

    makeItCount('excerpt', 500);
    makeItCount('actual', 150);
*/

    // Hover on image
    $$('.item-rating a img').each(function(el){
        $(el).observe('mouseover',function(){

            var src = $(this).src;
            src = src.replace(".gif","-hover.gif");
            $(this).src=src;

        });

        $(el).observe('mouseout',function(){

            var src = $(this).src;
            src = src.replace("-hover.gif",".gif");
            $(this).src=src;

        });

    });

});

/*
* systemMessage() - skryje zprávu
* systemMessage('a') - zobrazí zprávu 'a'
* systemMessage('a',10000) - zobrazí 'a' na 10s
* 
* skrytí zprávy (dokud nenajdem lepší řešení) volat těsně před koncem body:
  <script type="text/javascript">setTimeout('systemMessage()', 3000);</script>
* 
*/

function systemMessage(message, time) {
    
    // Pokud nemáme žádné argumenty, skryjeme hlášku
    if(arguments.length == 0) {
        
        //$('message-wrap').hide(); - bez animace
        Effect.Fade('message-wrap');
        
    } else { // Argumenty máme, zobrazíme
    
        //alert($('message-wrap').getElementsBySelector('p').length);
        $('message-wrap').getElementsBySelector('p')[0].update(message);        
        $('message-wrap').show();
        
        var setTime = time || 3000;
        
        // Automatické skrytí po zadaném (nebo 3) počtu sekund
        setTimeout('systemMessage()', setTime);
        
        // Skrytí při kliknutí na cokoli - funkce nesmí být předávána přímo, jinak se předá jako první argument objekt události
        
    }
    
}
Event.observe(document, 'click', function(){ systemMessage(); });

function kontrola_testu(formular,pocet,preklad)
{
    ret = false;
    if (formular) {
        celkem = 0;
        for (var i = 0; i < (formular.length); i++) {
            if (formular[i].tagName!='INPUT') continue;
            if (formular[i].type!='radio') continue;

            if (formular[i].checked) celkem++;
        }

        if (pocet==celkem)
        {
            if (celkem > 0) ret = true;
        }
    }

    if (ret)
    {
        return true;
    }
    else
    {
        alert(preklad);
        return false;
    }
}




// Strict doesn't know _blank, so we have to use rel="external" in anchors ;-)
function externalLinks() {
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i=0; i<anchors.length; i++) {
        var anchor = anchors[i];
        if (anchor.getAttribute("href") &&
            anchor.getAttribute("rel")) {
            if(anchor.getAttribute("rel").search(/external/)+1) {
                anchor.target = "_blank";
                if(anchor.getAttribute("title")==null||anchor.getAttribute("title")=="")
                    anchor.title = "Odkaz vede do nového okna";
            }
        }
    }
}
window.onload = externalLinks;

function sortable (id){
    hiddens =  document.getElementById(id).getElementsByTagName ('input');
    for (i = 0; i < (hiddens.length-1); i++) {
        hiddens[i].value = i+1;
    }
}

function fbs_click() {
    u=location.href;
    t=document.title;
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width= 626,height=436');
    return false;
}



function rate_com_bef(id)
{
    
    Element.insert('id_link_rate_'+id+'', { 
        before: '<img id="id_spinner_'+id+'" title="Načítám ..." src="/images/spinner-white.gif" alt="Načítám ..."/>'
    });
    Element.hide('id_link_rate_'+id+'');

    Element.replace('id_link_down_'+id+'', $('id_link_down_'+id+'').innerHTML);
    Element.replace('id_link_up_'+id+'', $('id_link_up_'+id+'').innerHTML);
    
}

function rate_com_aft(id)
{
    // Element.replace('id_link_down_'+id+'', $('id_link_down_'+id+'').innerHTML);
    // Element.replace('id_link_up_'+id+'', $('id_link_up_'+id+'').innerHTML);
    // Element.insert('id_link_rate_'+id+'', { before: '<img id="id_spinner" title="Načítám ..." src="/images/spinner-white.gif" alt="Načítám ..."/>' });
    Element.remove('id_spinner_'+id+'');
    Element.show('id_link_rate_'+id+'');
}
