/****************************************************************************
 *** clickable_box JS FILE
 ***
 *** This file contains:
 *** 	- Function to transform the "rel" attribute of DIV's, to a
 ***      global link on the DIV, in function of the type of target
 ***
 *** Author: Thierry Brodard <t.brodard@accessible.ch>
 *** Copyright: accessible Sàrl
 ***
 *****************************************************************************/

window.addEvent('domready', function() {

	var clickables = $$('.clickable');
	
	clickables.each(function(item) {
		// Reprendre la propriété "rel" du DIV
		var link = item.get('rel');
		
		// Rajouter un click global sur le DIV, en fonction du type de lien
		item.addEvent('click', function(el) {
			uri = link.toURI();
			
			linkString = new String(link);
					
			if (linkString.contains('html')  && (!linkString.contains('www')) && (!linkString.contains('http'))) {
				// Lien interne
				// => même fenêtre / tab
				document.location.href = link;
			}
			else {
				// Lien externe ou document
				// => nouvelle fenêtre / tab
				window.open('/' + link);
			}
		});
	});
	
	
	
	var popupbox = $$('div.popup');
	
	popupbox.each(function(item){
		item.addEvent('click', function(){
			new StickyWin.Modal({
				content: item.getElement('div.popup-content').clone().get('html'),
				relativeTo: $('main'),  
				offset:{
					x: 0,
					y: 40
				},   
    				edge: 'center', 
    				position: 'upperCenter',
				maskOptions: {
    					style:{
      						'z-index': 12
    					}
  				},
  				onDisplay: function(){
  					new Fx.Scroll(window, {duration:0}).toElement($('main'));
  				}
			});
		});
	});
});
