/**
 * @author trochette at tommyrochette.com
 */
var Silq = new Class({
    textButton:[],
	lastClicked: 0,
	
    initialize: function(options){
		if($$(".text_acc"))this.setTextAccessibility();
		if($("accueil_img_id"))this.setAccueilBanner();
		if($("activity_table"))this.setActivityActions();
		if($("authors_table"))this.setAuthorActions();
		if($('day_form'))this.setDayAction();
		this.setExternalLinks();
		this.setStyleMod();
    },
	setDayAction:function(options){
		$('day').addEvent('change',function(_e){
			window.location=$('day').value;							 									 
		});
	},
	setExternalLinks:function() {
		$$('a.external').each(function(value, key){
			$(value).addEvent('click', function(event) {
				value.target = '_blank';
			});
		}.bind(this));
		$$('a.external_no_icon').each(function(value, key){
			$(value).addEvent('click', function(event) {
				value.target = '_blank';
			});
		}.bind(this));
		$$('a.pdf').each(function(value, key){
			$(value).addEvent('click', function(event) {
				value.target = '_blank';
			});
		}.bind(this));
		
	},
	setAuthorActions:function(){
		$("authors_table").lastClicked = "first";
		$$('.book_title').each(function(_e){
			var activityRoot    = _e.getParent().getParent();
			var oldHeight       = _e.getStyle('height');
				_e.activityRoot = activityRoot;
				_e.set('tween', {duration: 'short'});

				
				_e.setProperty("oldHeight", oldHeight);
				_e.setStyle("cursor","pointer")
				_e.addEvent('click',function(){
					
					if(_e.opened == true){
						_e.activityRoot.lastClicked.getElement("div").set('tween', {duration: 'short'});
						_e.activityRoot.lastClicked.getElement("div").tween('height', '0px');
						_e.opened = false;
					}else{
						if(_e.activityRoot.lastClicked !="first"){
							_e.activityRoot.lastClicked.getElement("div").tween('height', '0px');
						}
						_e.getElement("div").set('tween', {duration: 'short'});
						_e.getElement("div").tween('height', _e.getProperty("oldHeight"));
						_e.opened = true;
						_e.activityRoot.lastClicked = _e;	
					}
				});
		});
		
		$$('.activity_description').each(function(_e){
			_e.set('style','height:0;overflow:hidden;');
		});
	},
	setActivityActions:function(){
		$("activity_table").lastClicked = "first";
		$$('.activity_title').each(function(_e){
			var activityRoot    = _e.getParent().getParent();
			var oldHeight       = _e.getStyle('height');
				_e.activityRoot = activityRoot;
				_e.set('tween', {duration: 'short'});

				
				_e.setProperty("oldHeight", oldHeight);
				_e.addEvent('click',function(){
					
					if(_e.opened == true){
						_e.activityRoot.lastClicked.getElement("div").set('tween', {duration: 'short'});
						_e.activityRoot.lastClicked.getElement("div").tween('height', '0px');
						_e.opened = false;
					}else{
						if(_e.activityRoot.lastClicked !="first"){
							_e.activityRoot.lastClicked.getElement("div").tween('height', '0px');
						}
						_e.getElement("div").set('tween', {duration: 'short'});
						_e.getElement("div").tween('height', _e.getProperty("oldHeight"));
						_e.opened = true;
						_e.activityRoot.lastClicked = _e;	
					}
				});
		});
		
		$$('.activity_description').each(function(_e){
			_e.set('style','height:0;overflow:hidden;');
		});
	},
	
	setAccueilBanner:function(){
		var idNo =0;
		var refClass = this;
		$$('.banner_toggler').each(function (_el){
			_el.id = idNo;
			_el.refClass = refClass;
			
			_el.addEvent('click',function(_e){
			    _el.refClass.swapImages(_el.id)
			});
			idNo++
		});		
		this.autoChange.bind(this).periodical(5000);
	},
	swapImages:function(_id){
		this.lastClicked = _id;
		var number = parseInt(this.lastClicked)-1;
		var idNo   = 0;
		var id     = _id;
		
			if(number<=home_image_url.length)number=home_image_url.length;
			
		$$('.banner_toggler').each(function (_el){
											 _el.setStyle("color","#9d9d9b");
			if(idNo == id){
				_el.setStyle("color","#000000");
			
			};
			
		
				
			
			idNo++
		});	
	
		var _img=$("accueil_img_id");
			$("accueil_img_id").setProperty("src",home_image_url[_id]);
			$("comment_title").set("html",home_image_title[_id]);
			$("comment_desc").set("html",home_image_desc[_id]);
			
		
	},
	autoChange:function(_e){
		
		var number = parseInt(this.lastClicked)+1;
			if(number>=home_image_url.length)number=0;
			
		this.swapImages(number);
	},
	setTextAccessibility: function(){
		var cookie;
		
		if(Cookie.read('fontSize')){
			$$('html').set('style','font-size:'+Cookie.read('fontSize')+'em');
		}else{
			Cookie.dispose('fontSize');
			cookie = Cookie.write('fontSize', '1', {duration: 1});
		}
		
		$('text-').addEvent('click', function(_e){
			var fontSize = Cookie.read('fontSize');
				fontSize = parseFloat(fontSize)-0.1;
				if(fontSize>0.6){
					Cookie.dispose('fontSize');
					$$('html').set('style','font-size:'+fontSize+'em');
					cookie = Cookie.write('fontSize', fontSize, {duration: 1});
				}
		});
		$('text').addEvent('click', function(_e){
			$$('html').set('style','font-size:1em');
			cookie = Cookie.write('fontSize', '1');
		});
		$('textplus').addEvent('click', function(_e){
			var fontSize = Cookie.read('fontSize');
				fontSize = parseFloat(fontSize)+0.1;
				if(fontSize<1.4){
					Cookie.dispose('fontSize');
					$$('html').set('style','font-size:'+fontSize+'em');
					cookie = Cookie.write('fontSize', fontSize, {duration: 1});
				}
			
		});
		$('imprimer').addEvent('click', function(_e){
			window.print();							 
		});
	
	},
	
	setStyleMod: function(){
		$$('.text_acc').each(function(_e){
			_e.set('style','display:block');
		})
		$('main_menu_menu').getElements('a').each(function(_e){
			_e.set('style','float:none');
			
		})
	}
});
/**
 * Add window ready event
 */
window.addEvent('domready', function() {
	var silq = new Silq();
	var menu = new UvumiDropdown('main_menu_menu');
});

try {
	var pageTracker = _gat._getTracker("UA-1441569-7");
	pageTracker._trackPageview();
} catch(err) {}