jQuery(function($){	
	$.easy.navigation();
	$.easy.tooltip();
	$.easy.popup();
	$.easy.external();
	$.easy.rotate();
	$.easy.cycle();
	$.easy.forms();
	$.easy.showhide();
	$.easy.jump();
	$.easy.tabs();
	$.easy.accordion();	
	
	var fra = $('body').hasClass('fra'); 	
	
	// homepage intro 
	$('#intro').each(function(){
							  
		var obj = this; 
		var li = $('.news li', obj);
		var content = $('.body', obj);
		var timeout;
		var pause = 8000;
		var current = 0;
		var className = 'current';
	
		function next(){
			current = ( current < (li.length -1) ) ? current+1 : 0;
			show(current);
		};
		
		function show(i){
			clearTimeout(timeout);
			current = i;
			$.each(content,function(index,value){
				$(value).hide();
			})
			$(li[i]).fadeIn();			
			$(content[i]).fadeIn();
			$(li).removeClass(className);
			selected = $(li).get(i);
			$(selected).addClass(className);
			if(li.length > 1) timeout = setTimeout(function(){ next(); }, pause);
		};
		
		$(li).each(function(i){								
			$(this).css('cursor','pointer').click(function(){
				show(i);
			});
		});
		
		show(current);
	
	});

	// language change
	$('.lang').each(function(){		
		en = 'English';
		fr = 'Français';
		enurl = 'language=en';
		frurl = 'language=fr';
		url = window.location.href;
		host = window.location.hostname;
		url = url.replace(host,'');
		url = url.replace('http://','');
		url = url.replace('https://','');
		thisurl = (fra) ? frurl : enurl;
		thaturl = (fra) ? enurl : frurl;
		text = (fra) ? en : fr; 		
			
		if (url == '/' || url.indexOf('/?language') != -1){
			href = '/?'+ thaturl;
		} else if(url.indexOf('?language') != -1){
			url = url.replace(enurl,'');
			url = url.replace(frurl,'');
			href = url + thaturl;
		}else {
			url = url.replace('&'+ thisurl,''); 
			parts = url.split('#');			
			href = parts[0] + '&'+ thaturl;
			if(parts.length > 1) href = href +'#'+ parts[1];
		};	
		
		$('<a href="'+ href +'">'+ text +'</a>').prependTo(this);
	});

	
});
