$(document).ready(function() {
    
    $('.content').hide();
    //$('#najnovsiehry_content').show();
    $("#najlepsiehry_content").show();

    $('.menu').click(function() {
        
        if ($(this).attr('id')=="mojeoblubene") {
            $(".prev").show();
            $(".next").show();   
        } else {
            $(".prev").show();
            $(".next").show();            
        }
        
        $('.menu').removeClass("active");
        $(this).addClass('active');
        
        $('.content').hide();
        $('#'+$(this).attr('id')+'_content').show();        
    });    
});



function init(name) {
    
    //alert(name);
    
    var boxWidth = $('.zoznam_hra').width() + 10;
    var boxTotal = $('#'+name+'_content .zoznam_hra').length;
    var totalBoxWidth = boxWidth * boxTotal;
    $('#'+name+'_content.content').css('width', totalBoxWidth+'px' ); 
    
    return totalBoxWidth;
}


function goPrev() {
    
    
    
    init($('.active').attr('id'))
    
    boxLeft = parseFloat($('#'+$('.active').attr('id')+'_content').css('left').replace("px",""));
    
    if (boxLeft<0) {
        $('.prev').hide();
        $('#'+$('.active').attr('id')+'_content').animate({
            "left": "+=850px"
        }, "fast",'linear',function() {
            // alert('done...');
            $('.prev').show();
        });
    }
    
    
}
    
function goNext() {
    
   totalBoxWidth = init($('.active').attr('id'));
   
   
   $('#'+$('.active').attr('id')+'_content.content').css('width', totalBoxWidth+'px' );    
   boxLeft = parseFloat($('#'+$('.active').attr('id')+'_content').css('left').replace("px",""));
   
   // alert( $('#'+$('.active').attr('id')+'_content').css('left')  );
   
   if (boxLeft.toString()=="NaN") {
       boxLeft = 0;
   }
   
   //alert(boxLeft);
   
   xxx = 850 - totalBoxWidth;
   
  
    if (boxLeft> xxx) {
        $('.next').hide();
        $('#'+$('.active').attr('id')+'_content').animate({
            "left": "-=850px"
        }, "fast",'linear',function() {
            // alert('done...');
            $('.next').show();
        });
    }
    
}
