var PreviousQl = 1;       // ciselne oznaceni elementu, na kterem byla mys v predchozim kroku 
var t_var;

$(document).ready(function() {


        // osetreni najeti mysi nad prvky horniho menu
        $('.top-menu-a').bind('mouseover', function(event){
                // pokusim se zamezit uvedeni quicklinks do klidoveho stavu
                if (t_var != 'undefined') {clearTimeout(t_var)};
                event.stopPropagation();
                
                // ziskam id webu z id prvku, na kterem byla vyvolana udalost
                var id = $(this).attr("id").substring(3,5);
                quickLinks(id);
        });
        
        // osetreni opusteni horniho menu mysi
        //$('#topmenu').bind('mouseout', function(event){
        $('#topmenu').bind('mouseout', function(event){
                event.stopPropagation();  // je to tu k necemu?
                //console.log('mouseout');
                t_var = setTimeout('quickLinks(webid)', 400);
                
        }); 
        
 /*        $('div #main-rect-home').bind('mouseover', function(){
                if (t_var != 'undefined') {clearTimeout(t_var)};
        });
  */       
        
 
});


function quickLinks(id)
{
    // tmp debug
    //if (!$("#top"+id).length){console.log('#top+'+id+' empty');}
    //console.log(id);
    
    
    if (PreviousQl == webid)
        $("#top"+PreviousQl).css("background-position", "0 87px");
    else
        $("#top"+PreviousQl).css("background-position", "0 0px")
    
    $("#top"+id).css("background-position", "0 174px");
    
    var duration = 400;
    
    if (PreviousQl != id)  // pouze pokud se zmenilo id
    {                        
        $("#main-rect-home").css("background-image", "url('/design/homepage/prod"+PreviousQl+".jpg')");
        
        var prevImg = $("#prod"+PreviousQl); 
        var newImg = $("#prod"+id);
        prevQl = $("#ql"+PreviousQl);
        var newQl = $("#ql"+id);             
        
        if (newImg.is(':animated')) {
            newImg.stop().animate({opacity:1}, duration/4, 'linear');            
        } else {            
            newImg.animate({opacity:1}, duration, 'linear');                        
        }            
        prevImg.animate({opacity:0}, duration, 'linear');
        //$("#prod"+PreviousQl).animate({opacity:0}, duration, 'linear');            
        
        
        //             newQl.css('display', 'block');
        //             if (newQl.is(':animated')) {
        //                 newQl.stop().animate({opacity:1}, duration/4, 'linear');            
        //             } else {            
        //                 newQl.animate({opacity:1}, duration, 'linear');                        
        //             }            
        //                         
        //             prevQl.animate({opacity:0}, duration, 'linear', function(){prevQl.css('display','none')});
        PreviousQl = id;
    }       
}



