$(document).ready(
    function()
    {
        // this is for the products popup fadeout
        var productsPopupTimer = {};
        var currHoveredMenuItemId = "";
        
        $("#meniu>li").hover(
            function()
            {
                currHoveredMenuItemId = $(this).attr("id");
                if ($(this).attr("id") == "li_products") 
                    productsPopupTimer = $.oneTimer(500, function() 
                        {
                            $.clearTimer(productsPopupTimer);
                            if (currHoveredMenuItemId == "li_products") 
                            {
                                // if the tracker is on something different than 'products', hide it
                                // Sublogic: if li_products is active, the tracker cannot be on it
                                if ($('#li_products').children('a').children('img').hasClass('activ')) $('#tracker').hide();
                                //alert($('#li_products').attr("id"));
                                $('#table_products_popup').show(); //$('#table_products_popup').fadeIn(1000);
                            }
                        }
                    );
                else
                    $('#table_products_popup').fadeOut(100);
                    
                if ($(this).children('a').children('img').hasClass('activ'))
                {
                    // the active element, set the cursor
                    $(this).children('a').children('img').css('cursor','default');
                }
                else // not the active element, activate tracking
                {
                    var ie7_fix = 0;
                    if (BrowserDetect.browser == 'Explorer')
                    {
                        if ((BrowserDetect.version == '7') || (BrowserDetect.version == '6')) ie7_fix = $('.header').width() - 10;
                    }
                    
                    var l = $(this).position().left - ie7_fix;
                    if ($('#tracker').is(':visible'))
                    {
                        $("#tracker").show().animate({"marginLeft": l+39}, 120);
                    }
                    else
                    {
                        $("#tracker").css({"marginLeft": l+39}).show();
                    }
                }
            },
            function()
            {
                currHoveredMenuItemId = "";
                if ($(this).attr("id") == "li_products") $('#table_products_popup').hide();
            }
        );
        $("#meniu").hover(
            function()
            {
            },
            function()
            {
                $("#tracker").hide();
            }
        );
        
        var switcher = 1;
        $(document).everyTime(7000, 
            function()
            {
                switch(switcher)
                {
                    case 1:
                        switcher = 2;
                        $('#cust_row1').fadeOut(1000);
                        $('#cust_row2').fadeIn(2000);
                        break;
                    case 2:
                        switcher = 3;
                        $('#cust_row2').fadeOut(1000);
                        $('#cust_row3').fadeIn(2000);
                        break;
                    case 3:
                        switcher = 1;
                        $('#cust_row3').fadeOut(1000);
                        $('#cust_row1').fadeIn(2000);
                }
            }
        );
    }
);
