Event.observe(window, 'load', function(){
	$('f_sb1').setOpacity(0.5);
	initSB2($$('#sb1 .item a').first().hash.substr(1));	
	var sb1 = new SwitchBloc('sb1','item',{
		SwiDirection : 'vertical'
	});
	$$('#sb1 .item a').each(function(e){
		e.observe('click',function(){
			/*
			if(navigator.userAgent.include('MSIE') == false){
				sb2.pause();
			}
			*/
			initSB2(e.hash.substr(1));
		});
	});
});

var initSB2 = function(id){
	$$('#sb1 .item a').each(function(e){
		e.removeClassName('on');							  
	});
	$('a'+id).addClassName('on');
	$('sb2').update('<div id="loading_sb2"></div>');	
	new Ajax.Request('./_ajax.php?ACT=Creation',{
		parameters : {'id' : id},
		onComplete : function(transport){
			$('sb2').update('');			
			tab = transport.responseJSON;
			tpl= '<a title="'+tab[0].nom+'" href="'+tab[0].zoom+'" id="zoom_sb" rel="lightbox">Zoom</a>';
			tpl+='<a href="javascript:void(0);" id="precedent_sb2">Pr&eacute;c&eacute;dent</a>';
			tpl+='<a href="javascript:void(0);" id="suivant_sb2">Suivant</a>';
			tpl+='<div id="cont_sb2"><ul id="liste_sb2">';
			tab.each(function(e){
				tpl+='<li class="item"><img src="'+e.visuel+'" /><h2>'+e.nom+'</h2><p>'+e.texte+'</p></li>';
			});
			tpl+='</ul></div>';
			$('sb2').insert({top:tpl});
			/*
			if(navigator.userAgent.include('MSIE') == false){
				sb2 = new SwitchBloc('sb2','item',{
					SwiDefilAuto : true,
					SwiDefilTempo : 5
				});
			}else{
				var sb2 = new SwitchBloc('sb2','item');
			}
			*/
			var sb2 = new SwitchBloc('sb2','item');
			$('suivant_sb2').observe('click',function(){
				num = sb2.SwiEcran;
				if(num != tab.size()){
					$('zoom_sb').href = tab[num].zoom;
				}
			});
			$('precedent_sb2').observe('click',function(){
				num = sb2.SwiEcran-2;
				if(sb2.SwiEcran != 1){
					$('zoom_sb').href = tab[num].zoom;
				}
			});
			/*
			if(navigator.userAgent.include('MSIE') == false){
				$('zoom_sb').observe('click',function(){
					sb2.pause();
				});
			}
			*/
		}
	 });
};
