$(function() {
    // large images
    $("div.vystup a[href$=.jpg], div.vystup a[href$=.png], div.vystup a[href$=.gif], div.vystup a[href$=.bmp]").fancybox({
        "titlePosition" : "outside",
        "transitionIn"	: "none",
        "transitionOut"	: "none"
    });

    // hr fix
    $('hr').each(function(i) {
        $(this).replaceWith('<div class="hr"><hr /></div>');
    });

    // cultures hover
//    $('div.cultures a').mouseover(function(i) {
//        $(this).find('img').attr('src', '/images/language_' + $(this).attr('rel') + '_active.gif');
//    }).mouseout(function(i) {
//        $(this).find('img').attr('src', '/images/language_' + $(this).attr('rel') + '.gif');
//    });

    // mainmenu traversing
    $('#mainmenu li:last').addClass('last');
    // menu hover with cufon
    $('#mainmenu>ul>li>a').each(function(i) {
        var span = $($(this).html());
        span.addClass('hover');
        span.hide();
        span.appendTo(this);
    }).mouseover(function() {
        $(this).find('span').hide();
        $(this).find('span.hover').show();
    }).mouseout(function() {
        $(this).find('span').show();
        $(this).find('span.hover').hide();
    });
    // mainmenu submenu open
    $('#mainmenu>ul>li').mouseenter(function() {
        $('#mainmenu>ul>li>ul').hide().css('z-index: 1;');
        $(this).find('ul').show().css('z-index: 100');
    });

    // cufon
    Cufon.replace('#mainmenu>ul>li>a>span');
    Cufon.replace('h1');
    Cufon.replace('#homepage_right h2');

    // homepage rorator
    $('#rotator').cycle({
        fx:      'fade',
        speed:   1000,
        timeout: 10000,
        next:    '#rotator_next',
        prev:    '#rotator_prev'
    });

    // content height fix
    if ($('#content').length > 0) {
        var height = $(window).height() - 400;
        if ($('#content').height() < height) {
            $('#content').css('height', ($(window).height() - 400) + 'px');
        }
    }

    // gemeotry table
    if ($('table.geometry').length > 0) {
        $('table.geometry').each(function(i) {
            $(this).find('tr').each(function(tr) {
                $(this).find('th').each(function(th) {
                    if (th > 0 && th % 2 == 0) {
                        $(this).addClass('even');
                    }
                    $(this).parent().addClass('head');
                });
            });
            $(this).parents('div.content').addClass('geometry_content');
        });
    }
});
