function collapseAll(speed) {
    $('#categories ul li ul').slideUp(speed);
    $('.expand').removeClass('expand');
}
$(document).ready(function(){

    $('.head, .head1, .head2, .head3, .head4').click(function() {
        var nextEl = $(this).parent().children('ul');
        if (nextEl.is(':visible')) {
            $(this).removeClass('expand');
            nextEl.find('a.expand').removeClass('expand');
            nextEl.slideUp('slow');
            nextEl.find('ul:visible').slideUp('slow');
            return false;
        }
        if (nextEl.is(':hidden')) {
            if ( nextEl.parent().parent().prev('a.expand').length == 0 ) {
                collapseAll('slow');
            }
            $(this).addClass('expand');
            nextEl.slideDown('slow');
            return false;
        }

    });
    var vl = window.location.toString();
    var wz2 = /produkt/;
    if ( wz2.test(vl) ) {
        windLoc = $('#breadcrumb a').eq( parseInt( $('#breadcrumb a').length -1 ) ).attr('href');
    } else {
        var wzorzec = /\/page\/\d\.html/;
        var windLoc = vl.replace(wzorzec, '.html');
    }
    var elMenu = $("#categories ul li a[href='"+ windLoc +"']");
    elMenu.addClass('subnav-active');
    if ( elMenu.parent().parent().is(':hidden') ) {
        elMenu.parent().parent().slideDown('fast');
        elMenu.parent().parent().prev('a').addClass('expand');
    }
    if ( elMenu.parent().parent().parent().parent().is(':hidden') ) {
        elMenu.parent().parent().parent().parent().slideDown('fast');
        elMenu.parent().parent().parent().parent().prev('a').addClass('expand');
    }

    // prettyPhoto
    $("a[rel^='prettyPhoto']").prettyPhoto({
        showTitle: true,
        showTitle:false,
        theme:'light_square'
    });

    // flash
    $('#flash').flash({
        swf: 'telnix_top.swf',
        width: 493,
        height: 262,
        params: {wmode: 'opaque'}
    });
    $('#slider_inner').flash({
        swf: 'http://telnix.pl/public/slider/slideshow.swf',
        width: 130,
        height: 60,
        params: {wmode: 'opaque'}
    });

});
