$(function() {

    $('#intro').click(function() {
        $('#intro').hide();
    })
     
});

$(function() {

    if (document.getElementById("arrive")) {
    $.datepicker.setDefaults($.datepicker.regional[''+$('#lang_input').val()+'']);
    $("#arrive").datepicker({minDate: 0});
    $("#depart").datepicker({minDate: 0});
    }
    
    
});


function setOptions(room_class, room_title) {

    $("#room_title_1").attr('disabled', false);
    $("input:radio[value='"+room_class+"']").attr('checked', 'checked');
    for (var i = 0; i < $rooms.length ; i++ ) {
        var exploded = $rooms[i].split("_");
        if(exploded[0] == room_class) {
            if(room_title == exploded[1])
                $("#room_title_1").append( new Option(exploded[1],exploded[1], 0, 1) );
            else
                $("#room_title_1").append( new Option(exploded[1],exploded[1], 0, 0) );
        }
    }
    $("#total_rooms").attr('value', '1');

}


$(function() {

    $('input:radio').live('click', function() {

        form_name = $(this).attr('title').split("_");
        $("#room_title_" + form_name[2]).empty();
        $("#room_title_" + form_name[2]).attr('disabled', false);
        for (var i = 0; i < $rooms.length ; i++ ) {
            var exploded = $rooms[i].split("_");
            if(exploded[0] == $(this).val())
             $("#room_title_" + form_name[2]).append('<option value="'+exploded[1]+'">'+exploded[1]+'</option>');
        }

        if($('#total_rooms').val() == 0)
            $('#total_rooms').attr('value', parseInt($('#total_rooms').val()) + 1);

    })

})

$(function() {

    $('.add_text').live('click', function() {

        $('#place_' + $(this).attr('title')+' input:radio:checked').attr('id', 'selected_'+$(this).attr('title'));
        var another = $('#place_' + $(this).attr('title')).clone();
        $('.add_text').remove();
        form_name = another.find("input:radio").attr('title').split("_");
        id = parseInt(form_name[2]) + 1;
        another.find("input:radio").attr({'title': 'room_type_'+id}).attr('checked', false);
        
        another.find("input:radio").each(function(i, elem){
            var newName = 'room_type_'+id
            if ($.browser.msie === true){ 
                $(elem).replaceWith(document.createElement(
                    this.outerHTML.replace(/name=\w+/ig, 'name='+newName)
                ));
            } else {
                $(elem).attr('name',newName);
            }
           // $("body").append(some_cloned_element);
        });

        another.find("select").each(function(i, elem){
            var newName = 'room_title_'+id;
            if ($.browser.msie === true){ 
                $(elem).replaceWith(document.createElement(
                    this.outerHTML.replace(/name=\w+/ig, 'name='+newName)
                ));
            } else {
                $(elem).attr('name',newName);
            }

        });
        another.find("select").attr({id: 'room_title_'+id, disabled: true}).empty();
        another.find(".add_text").attr({title: id});
        another.find('#selected_'+$(this).attr('title')).removeAttr('id');
        $(another).attr({id: 'place_'+id});
        $("#rooms").append(another);
        $('#selected_'+$(this).attr('title')).attr('checked', true);
        $('#total_rooms').attr('value', parseInt($('#total_rooms').val()) + 1);

    })

});

function showPicture(picUrl1, picUrl2) {

    $('#medium_picture').fadeTo('slow', 0, function() {
    $('#medium_picture').attr('src', picUrl2).ready(function() {
    $('#fimage').attr('href', picUrl1);
    $('#medium_picture').fadeTo('slow', 1.0);
    });
  });

}

