var voteOldValue;
var spanId;
function makeVote(unid, id, value) {
    spanId = '#'+unid.replace(/\./, "\\.")+'-'+id;
    voteOldValue = $(spanId).html();
    tvfvoter.makeVote(unid, id, value,"tvfreak", {callback:handleVote});
}
function handleVote(result){
    $(spanId).fadeOut('slow', function(){
            if(result[1]!='e'){$(spanId).empty().html(result[1]).fadeIn('slow');}else{ $(spanId).html(voteOldValue).fadeIn('slow');}
            $(spanId+'info').html(result[0]);
    });
}
var oldDiscAns;
function rollDiscAns(pageNumber, pageSize,size,showall,allowRemove,UNID){
    oldDiscAns = $('#discussion-ansv').html();
    tvfvoter.renderDiscusionAnsversAjax(pageNumber,pageSize,size,showall,allowRemove,'tvfreak',UNID,{callback:setDiscAns, errorHandler:setOldDiscAns})
}

function setDiscAns(result){
    $('#discussion-ansv').html(result);
    $('#discussion-ansv').scroll(0,0);
}

function setOldDiscAns(){
    $('#discussion-ansv').html(oldDiscAns);
}
var oldThemebox;
function getAnotherMonth(year, month){
    oldThemebox = $('#monththeme').html();
    monththemetvf.renderAjaxLeftbox(year, month, 'tvfreak', {callback:setNewMonthTheme, errorHandler:setOldMonthTheme});
}

function setNewMonthTheme(result){
    $('#monththeme').html(result);
}

function setOldMonthTheme(){
    $('#monththeme').html(oldThemebox);
}

var oldDateSelect;
function changeDate(day, month, year){
    oldDateSelect = $('#date-select').html();
    kalendartvf.renderAjaxNavigation(day,month,year, 'tvfreak', {callback:setDate, errorHandler:setOldDate});
}

function setDate(result){
    $('#date-select').html(result);
}

function setOldDate(){
    $('#date-select').html(oldDateSelect);
}
var startPosition =0;
function getNextNewArticleInit(){
    hideAllNewArticles();
    getNextNewArticle(0);
}
function getNextNewArticle(position){
    hideAllNewArticles();
    var newI = "#art" + position;
    $(newI).show();
    startPosition = position + 1;
    if(startPosition == 4){
        startPosition = 0;
   }
}
function hideAllNewArticles(){
    for(i=0; i < 4; i++)
    {
        var id;
        id = "#art" + i;
        $(id).hide();
    }
}
function newestArticlesUpdate(){
   setTimeout("newestArticlesUpdate()",6000);
   getNextNewArticle(startPosition)
}
var prboxvisible = false;
var zajeti = false;

function initPressReleaseBox(){

    var config = {
        over:function (){
            clearTimeout(zajeti);
            $('#prboxik').slideDown('slow');
        },
        timeout:500,
        out:function(){
            zajeti = setTimeout( function (){$('#prboxik').slideUp('slow');}, 1500);}
    };
    var config2 = {
        over:function (){
            clearTimeout(zajeti);
            $('#prboxik').slideDown('slow');
        },
        timeout:500,
        out: function(){
            zajeti = setTimeout(function (){$('#prboxik').slideUp('slow');}, 1500);}
    };
    $('#prboxik').hoverIntent(config);
    $('#pressrelbar').hoverIntent(config2);
}

function initNewestArticlesBox(){
    function hideAll(){
        $('#nejnovejsiContent-1').hide();
        $('#nejnovejsiContent-2').hide();
        $('#nejnovejsiContent-3').hide();
        $('#nejnovejsiContent-4').hide();
        $('#nejnovejsiContent-5').hide();
        $('#new1_active').hide();
        $('#new2_active').hide();
        $('#new3_active').hide();
        $('#new4_active').hide();
        $('#new5_active').hide();
    };
    function showAll(){
        $('#new1').show();
        $('#new2').show();
        $('#new3').show();
        $('#new4').show();
        $('#new5').show();
    }
    function deactiveAll(){
         $('#nejnovejsi-1').removeClass("selected");
         $('#nejnovejsi-2').removeClass("selected");
         $('#nejnovejsi-3').removeClass("selected");
         $('#nejnovejsi-4').removeClass("selected");
         $('#nejnovejsi-5').removeClass("selected");
    }
    hideAll();
    $('#nejnovejsiContent-1').show();
    $('#nejnovejsi-1').addClass("selected");
    $('#new1_active').show();
    $('#new1').hide();

    $('#nejnovejsi-1').click(function(){
        hideAll();deactiveAll();showAll();
        $('#nejnovejsi-1').addClass("selected");
        $('#nejnovejsiContent-1').show();
        $('#new1').hide();
        $('#new1_active').show();
    });
    $('#nejnovejsi-2').click(function(){
        hideAll();deactiveAll();showAll();
        $('#nejnovejsi-2').addClass("selected");
        $('#nejnovejsiContent-2').show();
        $('#new2').hide();
        $('#new2_active').show();
    });
    $('#nejnovejsi-3').click(function(){
        hideAll();deactiveAll();showAll();
        $('#nejnovejsi-3').addClass("selected");
        $('#nejnovejsiContent-3').show();
        $('#new3').hide();
        $('#new3_active').show();
    });
    $('#nejnovejsi-4').click(function(){
        hideAll();deactiveAll();showAll();
        $('#nejnovejsi-4').addClass("selected");
        $('#nejnovejsiContent-4').show();
        $('#new4').hide();
        $('#new4_active').show();
    });
    $('#nejnovejsi-5').click(function(){
        hideAll();deactiveAll();showAll();
        $('#nejnovejsi-5').addClass("selected");
        $('#nejnovejsiContent-5').show();
        $('#new5').hide();
        $('#new5_active').show();
    });
}
function initExpertiadyPodleLet(){

    var rok =new Date().getUTCFullYear();

    function hideAll(){
        for(i=rok; i>2005;i--){
            $('#'+i).hide();
        }
    };

    function showAll(){}

    hideAll();
    $('#'+(rok)).show();
    $('#menu2006').click(function(){
            hideAll();
            $('#2006').show();
        });
    $('#menu2007').click(function(){
            hideAll();
            $('#2007').show();
        });
    $('#menu2008').click(function(){
            hideAll();
            $('#2008').show();
        });
    $('#menu2009').click(function(){
            hideAll();
            $('#2009').show();
        });
         $('#menu2010').click(function(){
            hideAll();
            $('#2010').show();
        });
    $('#menu2011').click(function(){
            hideAll();
            $('#2011').show();
        });
    $('#menu2012').click(function(){
            hideAll();
            $('#2012').show();
        });
}

function initRboxNejctenejsi(){
    function hideContents(){
        $('#nejctenejsiContent').hide();
        $('#nejdiskutovanejsiContent').hide()
    };
    function deactivateHeadline(){
        $('#nejctenejsi').removeClass("selected");
        $('#nejdiskutovanejsi').removeClass("selected");
    };
    function hideNejctenejsiContent(){
        $('#prvni').hide();
        $('#druha').hide();
    };
    function hideNejdiskutovanejsiContent(){
        $('#prvni2').hide();
        $('#druha2').hide();
    };
    hideContents();
    hideNejctenejsiContent();
     $('#nejctenejsiContent').show();
     $('#nejctenejsi').addClass("selected");
     $('#prvni').show();   

    $('#nejctenejsi').click(function(){
        hideNejctenejsiContent();
        hideContents();deactivateHeadline();
        $('#nejctenejsiContent').show();
        $('#nejctenejsi').addClass("selected");
        $('#prvni').show();
    });
    $('#nejdiskutovanejsi').click(function(){
        hideNejdiskutovanejsiContent();
        hideContents();deactivateHeadline();
        $('#nejdiskutovanejsiContent').show();
        $('#nejdiskutovanejsi').addClass("selected");
        $('#prvni2').show();
    });
}

function initRecsVyrobci(){
    function hideContents(){
        $('#recs-vyrobci-30').hide();
        $('#recs-vyrobci-all').hide()
    };

    hideContents();
     $('#recs-vyrobci-30').show();

    $('#recs-odkaz1').click(function(){
        hideContents();
        $('#recs-vyrobci-all').show();

    });
    $('#recs-odkaz2').click(function(){
        hideContents();
        $('#recs-vyrobci-30').show();

    });
}
function changeRecommendedArticles(oldId, newId){
    var newI = "#" + newId;
    var oldI = "#" + oldId;
    $(oldI).hide();
    $(newI).show();
}

function recommendedArticlesInit(){
     for(i=0; i < 5; i++)
    {
        var id;
        id = "#" + i;
        $(id).hide();
    }
    $("#0").show();
}
