if(!PRO) { var PRO = {}; }

//création du menu "Nos marques"
PRO.menuMarqueNoh = {
	type : "marques",
	insertTo :"marques",
	getUrl : function(){
		var lang = $$('html')[0].readAttribute('lang');
		if(lang == 'en'){
			lang = 'gb';
		}
		return '/hotel-cms/'+lang+'/js/menu-marque.js';
	},
	getJSONFragment: function(json, type) {
		return (typeof json == 'object' && json[type] && typeof json[type] != 'undefined') ? json[type] : null;
	},
	compileMenu: function(tplType, datas) {
		var tpl = '';
		if ($('tpl_'+tplType)) {
			if (tplType == 'marques') {
				if (datas.nom) {
					if (datas.url){
						tpl +='<li><a href="'+ datas.url +'">'+ datas.nom +'</a></li>';
					}
					else {
						tpl +='<li>'+ datas.nom +'</li>';
					}
				}
			}
		}
		return tpl;
	},
	//chargement du JSON et insertion du DOM dans le template
	addMarqueToPage: function() {
		var dom = $(PRO.menuMarqueNoh.insertTo);
		if (dom) {
			new Ajax.Request(PRO.menuMarqueNoh.getUrl() + '?time=' + new Date().getTime(), {
				method: 'get',
				onSuccess: function(request) {
					var json = request.responseText;
					if (typeof json == 'string' && json != '') {
						json = eval('(' + json + ')');
					}
					if (typeof json == 'object') {
						var fragment;
						if (PRO.menuMarqueNoh.code_pays) {
							fragment = PRO.menuMarqueNoh.getJSONFragment(json, PRO.menuMarqueNoh.code_pays);
							if (!fragment){
							fragment = PRO.menuMarqueNoh.getJSONFragment(json, 'DEF'); 
							}
						} else {
							fragment = PRO.menuMarqueNoh.getJSONFragment(json, 'DEF');
						}
						fragment = PRO.menuMarqueNoh.getJSONFragment(fragment || json, PRO.menuMarqueNoh.type);
						if (fragment != null && fragment.length != 0) {
							PRO.menuMarqueNoh.number = fragment.length;
							for (i = 0; i < PRO.menuMarqueNoh.number; i++){
								var n = i;
								var tpl = PRO.menuMarqueNoh.compileMenu(PRO.menuMarqueNoh.type, fragment[n]);
								dom.insert(tpl);
							}
							var lis = $(dom.id).childElements();
							$(lis.last()).addClassName('last');
						} else {
							$(dom.id).remove();	
						}
					} else {
						$(dom.id).remove();		
					}
				}
			});
		}		
	}
}
document.observe("dom:loaded",function() {
	PRO.menuMarqueNoh.addMarqueToPage();						 
});