var countryList = {
    lang: (jQuery("html").attr("lang")=="en") ? "gb" : jQuery("html").attr("lang"),
    init: function(){
        this.fillCountryList();
    },
    fillCountryList: function() {
        if (jQuery("#search-destination-boo").length){
            jQuery.getJSON("/scripts-v66/booking/country-list-"+this.lang+".js", null, function(data) {
                jQuery.each(data.countryList, function(index, itemData) {
                    var optgroup = document.createElement("optgroup");
                    optgroup.label = index;

                    jQuery.each(itemData, function(index, itemData) {
                        var option = document.createElement("option");
                        option.value = itemData.value;
                        option.appendChild(document.createTextNode(itemData.text));
                        optgroup.appendChild(option);
                    });
                    jQuery("#search-destination-boo").append(optgroup);
                });
            });
        }
    }
}

jQuery(document).ready(function() {
    /* initialization of country list */
    countryList.init();
});
