function newImage(arg) {
    if (document.images) {
        rslt = new Image();
        rslt.src = arg;
        return rslt;
    }
}

function changeImages() {
    if (document.images && (preloadFlag == true)) {
        for (var i=0; i<changeImages.arguments.length; i+=2) {
            document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
        }
    }
}

var preloadFlag = false;
function preloadImages() {
    if (document.images) {
        img_03_over = newImage("img/img_03-over.gif");
        img_04_over = newImage("img/img_04-over.gif");
        img_05_over = newImage("img/img_05-over.gif");
        img_06_over = newImage("img/img_06-over.gif");
        img_07_over = newImage("img/img_07-over.gif");
        img_08_over = newImage("img/img_08-over.gif");
        preloadFlag = true;
    }
}

$(document).ready(function () {
    $('.fancy_popup').each(function(){
       $(this).fancybox();
    });
    
    $('#catalogueForm #locationSelect, #catalogueForm #townSelect, #catalogueForm #branchSelect').change(function(){
        $(this).parents('form').submit(); 
    });
    
    $('#clearSearchButton').click(function(){
        window.location = 'http://www.powiat.nowy-sacz.pl/content.php?component=com_catalogue&category=' + $('#categoryIdHiddenInput').val();
    });
    
    $('#mainMenu > li').mouseenter(function(){
        //$(this).addClass('hovered').find('> span').addClass('hovered').parent().find('> ul').show().css('visibility', 'visible');
        $('#mainMenu ul').hide();
        $(this).find('> ul').show();
    }).mouseleave(function(){
        //$(this).removeClass('hovered').find('> span').removeClass('hovered').parent().find('> ul').fadeOut('fast');
        $(this).find('> ul').fadeOut('fast');
    }).each(function(){
        //moving submenu to its designed position...
        $('> ul', this).each(function(){
            //var left = parseInt($(this).parent().position().left) * 1;
            //var width = parseInt($(this).parent().width());
            //if ($(this).parent().hasClass('last')) {width = width - 10;}
            //$(this).css({'left': left, 'width': 'auto'});
        });
    });
    $('#mainMenu > li > ul > li').mouseenter(function(){
        $(this).addClass('hovered').find('> ul').show();
    }).mouseleave(function(){
        $(this).removeClass('hovered').find('> ul').fadeOut('fast');
    });
    
    
    /*
    $('#mainMenu > li > ul > li > ul').each(function(){
        var width = $(this).parent().width() * 1;
        $(this).css({'left': width});
    });
    */
    
});
