﻿$(document).ready(function () {
    localizeRadWindow();
    Quotes();
    InitQtip();
    SetActiveAnchors();
    SetupNavigatorObj();
    initPiro();

    window.onresize = function (event) {
        SetHeight();
    }
    window.onload = function (event) {
        SetHeight();
    }

    $('hr:not(.clear)').wrap('<div class="horizontal-line" />');

    var txts = $('.NormalTextBox').each(function (key, value) {
        var val = $(this).val();
        if (val == 'předmět zprávy' || val == 'jméno a příjmení' || val == 'e-mail' || val == 'telefon') {
            $(this).click(function (event) {
                $(this).val('');
            });
        }
    });

    var udtTextArea = $('.UDT_Input  textarea');
    if (udtTextArea.val() == 'text zprávy' || 'doplňující informace') {
        udtTextArea.click(function (event) {
            udtTextArea.val('');
        });
    }

    var txtSearch = $('#dnn_dnnSEARCH_ClassicSearch .NormalTextBox');
    txtSearch.val('hledat');
    txtSearch.click(function (event) {
        txtSearch.val('');
    });
});

function initPiro() {
    $().piroBox({
        my_speed: 600, //animation speed
        bg_alpha: 0.7, //background opacity
        radius: 4, //caption rounded corner
        scrollImage: false, // true == image follows the page _|_ false == image remains in the same open position
        // in some cases of very large images or long description could be useful.
        slideShow: 'true', // true == slideshow on, false == slideshow off
        slideSpeed: 3, //slideshow
        pirobox_next: 'piro_next', // Nav buttons -> piro_next == inside piroBox , piro_next_out == outside piroBox
        pirobox_prev: 'piro_prev', // Nav buttons -> piro_prev == inside piroBox , piro_prev_out == outside piroBox
        close_all: '.piro_close' // add class .piro_overlay(with comma)if you want overlay click close piroBox
    });
}

function SetupNavigatorObj() {
    $('.ecc-navigator').before('<a href="/" title="Úvod"><img src="/portals/e-creative/skins/default/css/images/navigace-domecek.png" alt="Grafika Navigace" class="nav-img" /></a>');

    var content = $('.ecc-navigator').html();

    if (content != null) {
        content = content.replace(/&gt;/gi, '<img src="/portals/e-creative/skins/default/css/images/nav-sep.png" alt="Grafika Navigace" class="nav-sep" />');
        $('.ecc-navigator').html(content);
    }

    $('.ecc-navigator').css('display', 'block');
}


function OnClientMouseOver(sender, eventArgs) {
//    //activemenu
//    var tab = eventArgs.get_tab();
//    tab.select();
}

function SetActiveAnchors() {
    var index = 0;
    $('a').each(function (key, value) {
        if ($(this).attr('href') != null && $(this).attr('href').indexOf(location.pathname) > -1) {

            var curClass = "";

            if ($(this).attr("class") != null) {
                curClass = $(this).attr("class");
                curClass = curClass + " ActiveLink";
            }

            $(this).attr("class", curClass);

            //alert(curClass);
        }
    });
} 

function InitQtip() {
    var elements = $('.tooltip');

    $.each(elements, function (key, value) {

        var text = $(this).attr('title');
        $(this).qtip({
            content: text,
            style: {
                width: 178,
                textAlign: 'left',
                border: {
                    color: 'transparent'
                },
                tip: {
                    corner: 'bottomMiddle',
                    size: {
                        x: 18,
                        y: 20
                    }
                }
            },
            position: {
                corner: {
                    target: 'topMiddle',
                    tooltip: 'bottomMiddle'
                }
            },
            show: 'mouseover',
            hide: 'mouseout',
            name: 'light'
        });
    });
}

function Quotes() {
    $('.uvozovky').each(function () {
        var el = $(this);

        var wrapElStart = '<span class="uvozovky-start"></span>';
        var wrapElEnd = '<span class="uvozovky-end"></span>';

        $(wrapElStart).insertBefore('.uvozovky');
        $(wrapElEnd).insertAfter('.uvozovky');
    });
}

function SetHeight() {
    var headerH = $('#head-wrap').height() + $('.ControlPanel').height();
    var footerH = $('#foot-panel').height() + $('#bottom').height();
    var middleH = $('#middle-panel').height();

    var bodyH = $('body').height();
    var H = headerH + middleH + footerH;

    if (bodyH > H) {
        var tmpH = bodyH - headerH - footerH - middleH - 45;
        $('#middle-panel').css('min-height', middleH + tmpH + 'px');
    }
}

function localizeRadWindow() {
    try {
        Telerik.Web.UI.RadWindowUtils.Localization =
            {
                "Close": "Zavřít",
                "Minimize": "Minimalizovat",
                "Maximize": "Maximalizovat",
                "Reload": "Aktualizovat",
                "PinOn": "Zakotvit na tomto místě",
                "PinOff": "Odkotvit",
                "Restore": "Obnovit",
                "OK": "OK",
                "Cancel": "Zrušit"
            };
    }
    catch (e) { }
}
