$(document).ready(function() {
    $("#calendar").ready(function() {
        loadCalendar();
    });
    
    $("#calendar .calendar2").live("click", function() {
        loadCalendar(this.rel);
    });

    $("#program").change(function() {
        $.get($("#root").val()+"scripts/ajax-program.php", {"program":this.value, "lang":$("#lang").val()}, function(data) {
            $("#termin").html(data);
        });
        if(this.value == 3) {
            $("#toggler").show("slow");
        } else {
            $("#toggler").hide("slow");
        }
    });

    $("#add_room").click(function() {
        var rooms = $(".room").length;
        rooms++;

        var html = '';
        html+= '<tr class="room">';
        html+= '<td><label for="room'+rooms+'">Pokoj '+rooms+'</label></td>';
        html+= '<td colspan="3" class="sleft">';
        html+= '<select name="room[]" id="room'+rooms+'">';
        html+= '<option value="0">Vyberte...</option>';
        html+= '<option value="1">2 lůžkový/ 1 dvoulůžko (SBL) + dítě</option>';
        html+= '<option value="2">2 lůžkový/ 2 lůžka (TWIN)</option>';
        html+= '<option value="3">2 lůžkový/ 2 lůžka zvlášť + dítě (TWIN)</option>';
        html+= '<option value="4">2 lůžkový / 2 lůžka+ dítě (TWIN)</option>';
        html+= '<option value="5">3 lůžkový  (TRP)</option>';
        html+= '</select>';
        html+= '</td>';
        html+= '<td><label for="roomtype'+rooms+'">Typ pokoje</label></td>';
        html+= '<td class="sleft">';
        html+= '<select name="roomtype[]" id="roomtype'+rooms+'">';
        html+= '<option value="0">Vyberte...</option>';
        html+= '<option value="1">Carmenere</option>';
        html+= '<option value="2">Pinot</option>';
        html+= '<option value="3">Sauvignon</option>';
        html+= '<option value="4">Merlot</option>';
        html+= '<option value="5">Cabernet</option>';
        html+= '<option value="6">Chardonnay</option>';
        html+= '<option value="7">Shiraz</option>';
        html+= '<option value="8">Shiraz Superior</option>';
        html+= '</select>';
        html+= '</td>';
        html+= '</tr>';

        $("#add_room_row").before(html);
    });

    $("#sendtofriends").click(function() {
        $(this).hide();							   
        $(this).next('fieldset').show();							   
    });

});

function loadCalendar(month) {
    if(!month) {
        month = "";
    }

    $.get($("#root").val()+"scripts/ajax-calendar.php", {"month":month}, function(data) {
        $("#calendar").html("");
        $("#calendar").html(data);
    });
}
