﻿
/*
* Author: Inexes s.r.o. - www.inexes.cz
* Created on: 9.11.2010
* Modified on: 4.1.2011
* SVN revision: 1844
*
* Name: inCMS page initialization functions
* Summary:
*
* Dependences: jQuery 1.4.4, jQuery.History 1.5.0
*
*/

// Inbox flash variables settings
var InboxFlashVariables = "controlColor=16777215&backgroundColor=0&controlBackground=0&controlsHideTimeout=3&controlsResizeType=smart&hideTotalTime=false&showTime=true&controlsPadding=5,5,5,5&autoPlay=true";

// 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();


$(document).ready(function () {

    globalInitialization();

});

function showIfChecked(item, target) {
	if (item.checked) inCMS.getObj(target).style.display = "block";
	else inCMS.getObj(target).style.display = "none";
}

function globalInitialization() {
    // Radio buttons border fix
    $('input[type=radio]').css('border', 'none');
    $('input[type=checkbox]').css('border', 'none');

    if ($('h1:first').html() == "") {$('h1:first').remove();}
    $('table tr:even').addClass('even');

    markMenuParents('#menuList-h1');
}

function markMenuParents(parentSelector){
    $(parentSelector).children('li').each(function(){
        var uls = $(this).children('ul');
        if(uls.size() >= 1){
            $(this).addClass('isParent');
            markMenuParents(uls);
        }
    });
}

function replaceSpacesWith(selector, replaceString){
    $(selector).each(function(){
        var text = $(this).html();
        $(this).html(text.replace(/ /g, replaceString));
    });
}

function setEqualHeightInRow(parentSelector, childSelector, itemsPerRow){
    $(parentSelector).each(function(){
        var items = $(this).find(childSelector);
        var itemCount = $(items).size();

        // Set equeal height for items in row
        for (var i = 0; i < itemCount; i += itemsPerRow) {
            // Get max height in row
            var actualMaxHeight = 0;
            for (var j = 0; j < itemsPerRow; j++) {
                var height = $(items).eq(i+j).height();
                if(height > actualMaxHeight) actualMaxHeight = height;
            }
            // Set height in row
            for (var j = 0; j < itemsPerRow; j++) {
                $(items).eq(i+j).height(actualMaxHeight);
            }
        }

    });
}

function replaceDiacriticsWithEquivalents(originalString){
    var charsWith =     "áäčďéěíĺľňóôöŕšťúůüýřžÁÄČĎÉĚÍĹĽŇÓÔÖŔŠŤÚŮÜÝŘŽ";
    var charsWithout =  "aacdeeillnooorstuuuyrzAACDEEILLNOOORSTUUUYRZ";
    var convertedString = "";

    for(i=0;i<originalString.length;i++) {
        if (charsWith.indexOf(originalString.charAt(i))!=-1)
            convertedString+=charsWithout.charAt(charsWith.indexOf(originalString.charAt(i)));
        else
            convertedString+=originalString.charAt(i);
    }

    return convertedString;
}
