// JavaScript Document
function link_init(){
	$$('a').each(function(el,index){
		if(el.get('rel') == 'external') el.set('target','_blank');
	});
}
function ls_init(){
	slimbox_init();
	var lsAcc = new Accordion($$('#menu li.node'), $$('#menu ul.content'),{
		display:false,
		onActive:function(tog,el){
			tog.setStyle('background','url(__statics/triangle_down.png) no-repeat -1px 5px');
		},
		onBackground:function(tog,el){
			tog.setStyle('background','url(__statics/triangle.png) no-repeat left 3px');
		}
	});
	
	$$('#menu li.node').removeEvents('click');
	$$('#menu li.node').each(function(el,index){
		el.i = index;
		if(!el.hasClass('empty')){
			el.addEvent('mouseenter',function(ev){
				lsAcc.display(this.i);
			});
			el.addEvent('mouseleave',function(ev){
				lsAcc.display('none');
			});
		}
	});
	
	if($('main_news')){
		init_news();
	}
	if($$('li.rightcol_toggler')){
		var ls_rc_acc = new Accordion($$('li.rightcol_toggler'),$$('li.rightcol_stretcher'),{
			onActive:function(tog,el){
				tog.setStyle('background','url(__statics/triangle_down.png) no-repeat 0px 5px');
			},
			onBackground:function(tog,el){
				tog.setStyle('background','url(__statics/triangle.png) no-repeat left 3px');
			}
		});
	}
}

function init_news(){
	/* settings */
	var	news = $$('.news_main'),
		wait = 5000,
		scrollDuration = 500,
		index = 0,
		y = 0;
	
	news_fx = new Fx.Scroll($('main_news'), {
		duration:scrollDuration,
		onComplete:function() {
			if(index == news.length - 1) {
				index = y = 0;
			}else{
				++index;
			}
		}
	}).toTop();
	
	var move = function() {
		y = index*340;
		news_fx.start(0,y);		
	};
	news_timer = move.periodical(wait);
	init_news_shortcuts();
}

function init_news_shortcuts(){
	$$('.news_shortcuts').addEvent('click',function(ev){
		$clear(news_timer);
		news_fx.start(0,this.get('rel').toInt()*340);
	});
}
function slimbox_init(){
	$$('img.inserted_image_popup').addEvent('click',function(ev){
		var cap = this.get('rel') || null;
		Slimbox.open(this.get('src').replace('mini_',''),cap);
	});
}
var popupimage = function(chemin){
	Slimbox.open(chemin,null);
}
var news_fx,news_timer;
window.addEvent('domready',function(){
	link_init();
	ls_init();
});
