jQuery(function() {
	var bar = new foxgroup.utils.Bar('left', 'button_canvas border_color', 'button_bar ');
	window.bar = bar;

	bar.canvasJ.appendTo('body');

	bar.addButton('<img src="/data/images/renet_testo.png" alt="renet">',
		'button renet bg_color1',
		{href: '#'},
		{
			click: function(e) {
				e.preventDefault();

				bar.activateButton(this);
				foxgroup.utils.xhr('/dyna_content.html',
					'get',
					{action: 'get_portali', json: 1},
					function(data) {
						var portali = foxgroup.utils.JSON.parse(data.responseText);

						var select = document.createElement('select');
						select.onchange = function(e) {
							window.location = this.options[this.selectedIndex].innerHTML;
						};

						portali.forEach(function(portale, idx) {
							var option = document.createElement('option');
							option.value = idx;
							option.innerHTML = portale;
							select.appendChild(option);
						});

						var html = jQuery('script#tpl_bottone_renet').html();
						var content = jQuery('<div>' + html + '</div>')
							.find('#bottone_renet_select')
							.append(select)
							.end()
							.html();
						bar.updateContent(content);
					},
					foxgroup.utils.stub,
					'cache');
			}
		});

	bar.addButton('<img src="/data/images/gestionale_immobiliare_testo.png" alt="gestionale">',
		'button gestionale bg_color1',
		{href: 'http://www.gestionaleimmobiliare.it'},
		{
			click: function(e) {
				e.preventDefault();
				bar.activateButton(this);

				var html = jQuery('script#tpl_bottone_gestionale').html();
				bar.updateContent(html);

			}
		});

	bar.addButton('<img src="/data/images/aste_immobiliari_testo.png" alt="Aste Immobiliari Private">',
		'button aste_immobiliari bg_color1',
		{href: '#'},
		{
			click: function(e) {
				e.preventDefault();
				bar.activateButton(this);

				var html = jQuery('script#tpl_bottone_aste').html();
				bar.updateContent(html);
			}

		});

});

