﻿$(document).ready(function () {

    //---------------------------------------------------
    //  ie6 alpha bug
    //---------------------------------------------------
    $('.menu-0').supersleight();
    $('#menu-top').supersleight();
    $('#logo').supersleight();
    $('#apple-right').supersleight();
    $('#leaf-right').supersleight();
    $('#leaf-bottom').supersleight();

    //---------------------------------------------------
    //  medias tabs
    //---------------------------------------------------
    $('#medias .menu .ca-tab').click(function () {
        var target = ca_getModuleArg($(this), 'ca-tab');
        if (target != null) {

            $('#medias .menu .ca-tab').removeClass('active');
            $(this).addClass('active');
            var tabs = $('#medias .impression:visible');
            if (!tabs.hasClass(target)) {
                $('#medias .impression:visible').slideUp('slow', function () {
                    $('#medias .' + target).slideDown('slow');
                });
            }
            if ($('#medias .impression:visible').length == 0) {
                $('#medias .' + target).slideDown('slow');
            }
        }
    });

    //---------------------------------------------------
    //  contact - children-adults
    //---------------------------------------------------
    var activechildren = parseInt($(":input.showchildren option:selected").text());
    var children;
    if (activechildren > 0)
        children = $(":input.showchild:gt(" + (activechildren - 1) + ")");
    else {
        $(".children-ages").hide();
        children = $(":input.showchild");
    }
    children.hide();
    $(":input.showchildren").change(function () {
        var showchildren = parseInt($(this).find("option:selected").text());

        $(".children-ages").hide();
        children = $(":input.showchild");
        children.hide();
        if (showchildren > 0) {
            $(".children-ages").show();
            $(":input.showchild:lt(" + showchildren + ")").show();
        }
    });

    // -------------------------------------------------
    // contact - calendar -min/max date
    // -------------------------------------------------
    $('.ca-calendar').each(function () {
        var args = ca_getModuleArgs($(this), "ca-calendar");
        if (args.length > 1) {
            var minDate = getDate(args[0]);
            var maxDate = getDate(args[1]);
            $(this).datepicker({
                showOn: 'button',
                buttonImage: '/media/calendar.gif',
                buttonImageOnly: true,
                minDate: minDate,
                maxDate: maxDate
            });
        }
    });

    //---------------------------------------------------
    // offers Slider
    //---------------------------------------------------
    $("#offers-slider").easySlider({
        auto: false,
        continuous: true,
        prevText: "<img src='/media/arrow-left.png' >",
        nextText: "<img src='/media/arrow-red.png' >",
        columns: 1
    });

    //---------------------------------------------------
    //  frame-choose tabs
    //---------------------------------------------------
    $('#frame-choose .menu .ca-tab').mouseenter(function () {
        var target = ca_getModuleArg($(this), 'ca-tab');
        if (target != null) {
            $('#frame-choose .menu .ca-tab').removeClass('active');
            $(this).addClass('active');
            $('#frame-choose .impression').hide();
            $('#frame-choose .' + target).show();
        }
    });

});

function getDate(rawdate) {
    if (rawdate != null) {
        var parts = rawdate.split("-");
        if (parts.length == 3)
            return new Date(parseInt(parts[0], 10), (parseInt(parts[1], 10) - 1), parseInt(parts[2], 10));
    }
}

//---------------------------------------------------
// fotogallery
//---------------------------------------------------
function cu_customGallery(id, lang) {
    var width = $(document).width() - 200;
    var height = $(window).height() - 100;
    cu_CustomPopup("popup-gallery", "/pages/gallery.aspx?lang:" + lang + "|id:" + id, width, height);
    return false;
}

// -------------------------------------------------
// print
// -------------------------------------------------
function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function CL_printWindow() {
    window.print();
}

