// lancement des différents moduls javascript après le chargement de la page

function box_image_event(ancre) {
	ancre.addEvent('click',function(event){
		event.stop();
		var motif = /id_document=(\d+)/;
		var id_document = ancre.getProperty('href').match(motif);
		var requete = new Request.JSON({
				url :'http://localhost/spip/spip.php?page=box_image&'+id_document[0],
				onComplete: function(resultat){
					box_image_open(resultat);
				}
			});
		requete.send();
	});
}

function box_presse_event(ancre) {
	ancre.addEvent('click',function(event){
		event.stop();
		var motif = /id_article=(\d+)/;
		var id_article = ancre.getProperty('href').match(motif);
		var requete = new Request.JSON({
				url :'http://localhost/spip/spip.php?page=box_presse&'+id_article[0],
				onComplete: function(resultat){
					box_presse_open(resultat);
				}
			});
		requete.send();
	});
}

function box_news_event(ancre) {
	ancre.addEvent('click',function(event){
		event.stop();
		var motif = /id_article=(\d+)/;
		var id_article = ancre.getProperty('href').match(motif);
		var requete = new Request.JSON({
				url :'http://localhost/spip/spip.php?page=box_news&'+id_article[0],
				onComplete: function(resultat){
					box_news_open(resultat);
				}
			});
		requete.send();
	});
}

function box_image_open(json) {
	Shadowbox.open({
        player:     'img',
        title:      json.titre,
        content:    json.url,
        height:     json.hauteur,
        width:      json.largeur
    });
}

function box_presse_open(json) {

	Shadowbox.open({
        player:     'html',
        title:      json.title,
        content:    json.content,
		height:		400,
        width:      600
    });
}

function box_news_open(json) {

	Shadowbox.open({
        player:     'html',
        title:      json.title,
        content:    json.content,
		height:		400,
        width:      600
    });
}

Shadowbox.loadSkin('classic', 'squelettes/cgi/shadowbox/skin');
Shadowbox.loadLanguage('fr', 'squelettes/cgi/shadowbox/lang');
Shadowbox.loadPlayer(['flv', 'html', 'iframe', 'img', 'qt', 'swf', 'wmp'], 'squelettes/cgi/shadowbox/player');

window.addEvent('domready', function(){
		
	Shadowbox.init({
        skipSetup: true // skip the automatic setup
    });
	
	var liens_images = $(document.body).getElements('a[rel^=box_image]');
	liens_images.each(function(ancre){
			box_image_event(ancre);
		}
	);
	var liens_presse = $(document.body).getElements('a[rel^=box_presse]');
	liens_presse.each(function(ancre){
			box_presse_event(ancre);
		}
	);
	var liens_news = $(document.body).getElements('a[rel^=box_news]');
	liens_news.each(function(ancre){
			box_news_event(ancre);
		}
	);
	
	
	var menu = new Menu();
});
