// JavaScript Document
window.addEvent('domready', init);



function init(){
	
	if($('menu') != null){ var menu = new DropMenu('menu',{ mode:'vertical' }); }
	else{ var menu = new DropMenu('menu_int',{ mode:'vertical' }); }
	
	$$('.submenu').getFirst().set('class' , 'menu_a premier');
	
	$$('.submenu').each(function(el) { el.getParents('li').getElement('a').set('class','sous_menu'); });
	
	$('menu_bas').getFirst().set('class' , 'menu_a premier');
	
	
	if($$('#contenu_article_haut') != null){ reecritureUrl($$('#contenu_article_haut').getElements('a')); }
	
	if($('article_home') != null){ reecritureUrl($('article_home').getElements('a')); }
	
	//SqueezeBox.initialize();
	SqueezeBox.assign($$('a[rel=boxed][href^=#]'),{ parse:'config' });
	
	SqueezeBox.assign($$('.box'),{ parse:'rel' });
	
	new vlaDatePicker('exampleIV-B', { style: 'apple_widget', offset: { x: 3, y: 1 }, filePath:jsPath+'inc/' });
	
	$$('.vlaCalendarPicker apple_widget').setStyle({ 
	  display: 'block',
	  opacity: '100',
	  visibility: 'visible'
	});
	
	
	//calendrier page article centrale de disponibilite
}

//fontion reecriture des liens
function reecritureUrl(lien_change){
	var url;
	var j;
	var params;
	lien_change.each(function(el) {
		if(el.get('href').contains('rhonalpcom') === true){
			params = el.get('href').toString().split('/');
			url = new Array();
			j = 0;
			for(var i = 0; i < params.length; i++){
				if(i == 2){
					url[j] = window.location;
					j++;
				}
				if(i > 2){
					url[j] = params[i]+"/";
					j++;
				}
			}
			
			el.set('href', url.join(""));
		}
	});
}

function checkForm(){
// on charge les valeurs des sélect
	$$('select').each(function(el){
		val = $(el).getAttribute('title')!=''?$(el).getAttribute('title'):$(el).getAttribute('value');
		$(el).getElements('option').each(function(op){
			if(val && $(op).getAttribute('value')==val){
				$(op).set('selected', 'selected');
			}
		})
	});
	// on charge les valeurs des boutons modifier
	$$('input[type=checkbox], input[type=radio]').each(function(el){
		if($(el).getAttribute('value')==$(el).getAttribute('check_value')){
			$(el).setAttribute('checked', 'checked');
		}
	});	
}


function sel(date){ 
	$('dateChange').set('html',date);
	$('datedebcentrale').set('value',date);
	return false;
}


function loadPopup(html){
	$$('select').each(function(el){ el.setStyle('display', 'none') });
	new Element('div').setProperty('id', 'TB_overlay').injectInside(document.body);
	$("TB_overlay").setStyles({ "z-index":999,"cursor":"pointer", "position":"absolute", "left":0, "top":0,"background-color":"#000000", "height": window.getScrollHeight()+'px', "width": window.getScrollWidth()+'px', 'opacity':0.6 });			
	new Element('div').setProperty('id', 'inputform').injectInside(document.body);
	$("inputform").setStyles({  "z-index":1000,"position":"absolute", "left":((window.getScrollWidth()-800)/2), "top":((window.getScrollHeight()-500)/2), "background-color":"#ffffff", "height": '500px', "width": '800px' });			
	$("inputform").set('html', html);
	$("TB_overlay").addEvent('click', function () { $("TB_overlay").destroy();$("inputform").destroy();  $$('select').each(function(el){ el.setStyle('display', '') }); });
}



