﻿$(document).ready(function () {
    $('#footer-pobyty ul').easyListSplitter({ colNumber: 2, direction: 'horizontal' });

    $(".trigger").tooltip({ offset: [9, 0], effect: 'slide' });
    $(".trigger-lode").tooltip({ offset: [9, 0], effect: 'slide', tipClass: 'tooltip-lode', relative: true });

    $("a.print").click(function () { window.print(); return false; });

    if (jQuery.browser.msie && jQuery.browser.version.substr(0, 1) < 7) {
    }
    else {
        // If no JS CSS menu will still work
        $("#mainmenu").removeClass("cssonly");
        // Find subnav menus and slide them down
        $("#mainmenu li a").mouseover(
            function () {
                $(this).parent().find("div.content-menu-box").animate({ opacity: 'toggle', height: "toggle" }, 200);
                $(this).parent().hover(function () {
                }, function () {
                    // On hovering out slide subnav menus back up
                    $(this).parent().find("div.content-menu-box").slideUp(100);
                })
            });
    }

    var triggers = $(".form-input").overlay({
        mask: {
            color: '#fff',
            loadSpeed: 200,
            opacity: 0.8
        },
        fixed: false
    });

    $.tools.dateinput.localize("sk", {
        months: 'Január,Február,Marec,Apríl,Máj,Jún,Júl,August,' +
                   	                    'September,Október,November,December',
        shortMonths: 'jan,feb,mar,apr,máj,jún,júl,aug,sep,okt,nov,dec',
        days: 'nedeľa,pondelok,utorok,streda,štvrtok,piatok,sobota',
        shortDays: 'ned,pon,ut,str,štv,pia,sob'
    });

    $(":date").dateinput({ trigger: true, format: 'dd.mm.yyyy', min: -1, lang: 'sk', firstDay: 1 });

    // when first date input is changed
    $(":date:first").data("dateinput").change(function () {

        // we use it's value for the seconds input min option
        $(":date:last").data("dateinput").setMin(this.getValue(), true);
    });

    $('input[title!=""]').hint();

    $('#search-zajazd').change(function () {
        checkResults();
    });


    function checkResults() {
        var str = $("form").serializeArray();
        $.ajax({
            type: "POST",
            url: "/webservices/data.asmx/GetKrajiny",
            cache: false,
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify({ data: str }),
            dataType: "json",
            beforeSend: function () {
                $('#search-krajina').html('<div><img src=\"/imgs/ajax-loader.gif\" alt="Nahrávam..."></div>');
            },
            success: handleHtml,
            error: ajaxFailed
        });
    }

    function handleHtml(msg) {
        $("#search-krajina").empty();
        $("#search-krajina").html(msg.d);
    }

    function ajaxFailed(xmlRequest) {
        alert(xmlRequest);
    }

});
