var menuLastOpened = 0;

$(document).ready(function(){
    
    
    // Horizontal Menu
    $('li.menuItem').hover(
        // Show
        function() { 
            // Show Dropdown
            if(menuLastOpened < (new Date().getTime() - 200)) {
                $(this).find("ul").slideDown('fast');
                menuLastOpened = new Date().getTime();
            }
            
            // Replace Image on hover
            var mImage = $(this).find("a img");
            mImage.attr('src', mImage.attr('src').replace('.gif', '_over.gif')); 
            

        },
        // Hide
        function() { 
            // Hide dropdown
            $(this).find('ul').slideUp(100);
            // Replace image on hover-out
            var mImage = $(this).find("a img");
            mImage.attr('src', mImage.attr('src').replace('_over', ''));
        }
    );
    
    // Vertical Menu image replacements
    $('.overMe').hover(
        // Change to _over
        function() {
            $(this).attr('src', $(this).attr('src').replace('.', '_over.'));
        },
        // Change back
        function() {
            $(this).attr('src', $(this).attr('src').replace('_over', ''));
        }   
    );
    
    // Directory Basic Results
    $('.directory-result-basic-open .classified_table').hide();
    $('.directory-result-basic-open a').click(function(){
        $(this).parent().find(".classified_table").slideToggle(200);
    });
    
    
    // Rounded corners
    $('#col2 img').each(function() {
        // If the img has the class nocorners, don't apply corners to it
        if(!$(this).hasClass('nocorners')) {
        
            var colorArray = {
                0: 'F18020',
                1: 'C00075',
                2: '00A25D',
                3: '2E318E',
                4: '0091D3',
                5: 'FEC707',
                6: 'B5118C'
            };
            
            var randomNumber = Math.floor(Math.random()*7);
            
            $(this).addClass('corners');
            $(this).addClass('iborder5');
            $(this).addClass('icolor' + colorArray[randomNumber]);
            
        }
    });
        
});


// Scroll images
function scrollClassifiedImage(to)
{
    $('#classifiedImages').scrollTo($(to), 600);
}


function bookmarkUs(url, title) 
{
    if (window.sidebar) // firefox
        window.sidebar.addPanel(title, url, "");
    else if(window.opera && window.print){ // opera
        var elem = document.createElement('a');
        elem.setAttribute('href',url);
        elem.setAttribute('title',title);
        elem.setAttribute('rel','sidebar');
        elem.click();
    }
    else if(document.all)// ie
        window.external.AddFavorite(url, title);
}



