$(document).ready(function() {

    // tlacitko Kontakty
    $('#contacts img').hover( function() { this.src = this.src.replace(/.png/,"h.png"); },
                              function() { this.src = this.src.replace(/h.png/,".png"); });

    // scrollbar
    fleXenv.fleXcrollMain('content');

    // menu
    $('#menu').hover(
        function() { $('#content_mcontentwrapper').css( { 'z-index' : 0 } ); },
        function() { $('#content_mcontentwrapper').css( { 'z-index' : 2 } ); }
    );
    $('#menu-item12, #menu-item13').hover(
        function() { $('#children').css( { 'z-index' : 0   } ); },
        function() { $('#children').css( { 'z-index' : 200 } ); }
    );

    // kulaty rohy (krome IE <=8)
    if (!$.browser.msie || $.browser.version.substr(0,1) > 8) {
        $('#menu a.top, #menu ul, #contacts-content').corner('10px');
        $('#menu li.first > a').corner('top 10px');
        $('#menu li.last > a').corner('bottom 10px');
    }

    // zobrazeni kontaktu
    $('#contacts, #contacts-close a').click( function() {
        var interval = 500;
        if ( $('#contacts-content').is(':hidden') ) {
            $('#contacts-content').fadeIn(interval);
            $('#menu').fadeOut(interval);
        } else {
            $('#contacts-content').fadeOut(interval);
            $('#menu').fadeIn(interval);
        }
    });

    if ($.browser.msie && $.browser.version.substr(0,1) == 6) {
        $("#menu li").hover(
            function() { $(this).addClass("iehover"); },
            function() { $(this).removeClass("iehover"); }
        );
    } else {
        setValidImageTitles();
        $().piroBox({
            my_speed: 300,
            bg_alpha: 0.5,
            slideShow : true,
            slideSpeed : 3,
            close_all : '.piro_close,.piro_overlay'
        });
    }


    // seznamy odkazu
    $("#tree li").each( function() {
        var ul = $("ul", this).first();
        if ( !ul.size() )  return;
        var span = $('<span></span>');
        $(span).click( function() { ul.toggle(); $(this).toggleClass("expanded"); });
        $(this).append(span);
    });

});


function setValidImageTitles() {
  $('div.gallery').each( function() {
    var text = $(this).prevAll('h1:first').text();
    var prev = $(this).prev();
    if ( prev.get(0).tagName.toLowerCase() == 'h2' )
      text = text + ": " + prev.text();

    $('a', this).attr('title', text);
  });
}

