﻿// Funkce spouštěné při načítání stránky


// Fce pro vytvoreni bezpecneho odkazu
inCMS.initLinks = function() {
    var mailList = $('span.link');
    mailList.each(function() {
        var mail = $(this).html().replace('(zavinac)', '@');
        mail = mail.replace(/\(tecka\)/g, '.');
        $(this).html('<a href="mailto:' + mail + '" title="' + mail + '">' + mail + '</a>');
    });
}
inCMS.initLinks();

// Prvni a posledni polozka v menu
$('#menuList-h1 > li:first-child').addClass('first');
$('#menuList-h1 > li:last-child').addClass('last');
$('#subMenuBox ul.switch ul a').before('- ');

// Remove last item from breadcrumb in category view
$('#rptCategories.categoryView a:last-child').remove();
if ($('#rptCategories.categoryView').find('a').get(0) != null) {
    $('#rptCategories.categoryView').append('&nbsp;');
}

function setSamePairWidth(firstPairSelector, secondPairSelector) {
    var firsPairWidth = 0;
    $(firstPairSelector).each(function() {
        var currentWidth = $(this).width();
        if (currentWidth > firsPairWidth) firsPairWidth = currentWidth;
    });
    
    var secondPairWidth = 0;
    $(secondPairSelector).each(function() {
        var currentWidth = $(this).width();
        if (currentWidth > secondPairWidth) secondPairWidth = currentWidth;
    });
    
    if (firsPairWidth > secondPairWidth) {
        $(secondPairSelector).css({ width: firsPairWidth + "px" });
    } else {
        $(firstPairSelector).css({ width: secondPairWidth + "px" });
    }
}
//setSamePairWidth(".detailInfo table.styled.info .col1", ".detailInfo .detailDesc table.styled.info.properties .col1");


$(document).ready(function() {
    // Roztazeni stranky
    var browserHeight = $(window).height();
    var headerBoxHeight = $('#headerBox').height();
    var mainBoxHeight = $('#mainBox').height();
    var mainBoxHeightSpaces = 31;
    var computedMainBoxHeight = browserHeight - headerBoxHeight - mainBoxHeightSpaces;
    if (computedMainBoxHeight > mainBoxHeight) {
        $('#mainBox').css('height', computedMainBoxHeight + 'px');
    }
    // Set same height for content
    //$("#mainContentBox").height($("#mainBox").height());

    // Set min-width for submenu
    $('ul#menuList-h1 > li > ul').each(function() {
        var parentWidth = $(this).parent('li').width();
        if ($.browser.msie && $.browser.version <= 6) {
            $(this).css({ width: parentWidth + 'px' });
        } else {
            $(this).css({ minWidth: parentWidth + 'px' });
        }

    });

    // Menu fake round corners for IE
    if ($.browser.msie && $.browser.version <= 8) {
        $('#menuList-h1 > li > ul').css({ "left": "4px" });
        $('#menuList-h1 > li > ul').append('<li class="leftCorner">&nbsp;</li><li class="rightCorner">&nbsp;</li><li class="rightCornerTop">&nbsp;</li>');
        $('#menuList-h1 > li > ul > .leftCorner').each(function() {
            var parentHeight = $(this).parent().height();
            $(this).css({ height: parentHeight + "px" });
        });
        $('#menuList-h1 > li > ul > .rightCorner').each(function() {
            var parentHeight = $(this).parent().height();
            $(this).css({ height: (parentHeight - 4) + "px" });
        });
    }
})
