

jQuery.createGalleries = function () {

	var galleries = [];
	
	$("a").each (function () {
		$rel = $(this).attr('rel');
		
		
		if ($rel.indexOf ('gallery') != -1) {
			$slug = $rel.replace ('gallery', '');
			$slug = $slug.replace (' ', '');
			
			
			if (galleries [$slug] == null) {
				
				
				// build the navigation DOM elements

				$("#numbers_"+$slug).after ("<span style='float:left; margin-left:10px'><a rel='gall' id='playPause_"+$slug+"' href='#' onclick='return false'>Pause</a></span><div id='arrows' style='float:left; margin-left:10px;'><a href='' rel='gall' onclick='return false' id='prev_"+$slug+"'>&lt;</a> &nbsp; <a href='' rel='gall' id='next_"+$slug+"' onclick='return false;'>&gt;</a></div><span style='float:left' id='counter_"+$slug+"'>Images (1 / --)</span><div id='copyright'>Copyright&nbsp;</div><div class='clear'></div>")
				galleries [$slug] = new Gallery ($slug, $("#"+$slug+"_img"));
				//$(this).html (" ");
			
			}
			$("#arrows").hide ();
		
			galleries [$slug].addImage ($(this).attr('href'));
			
			//$(this).fadeOut ();
			//$(this).changeColors ();
			//$(this).remove ();
		}
		
	})
	
	$('.separator').remove ();	
}



$('document').ready (function () {
	
		
		$("#content_for_layout").hide ();
		$("#content_for_layout").stop(true, false).fadeTo (1500, 1);
		
		
		//$("#title").hide ();
		//$("#title").stop (true, false).fadeTo (1000, 1);
		
	
		// Galleries
		$.createGalleries ();
	
		
		$(".menu").mouseover (function () {
			$(this).find('img').stop(true, false).fadeTo (1000, 0.17);
		})
		$(".menu").mouseout (function() {
			$(this).find('img').stop(true, false).fadeTo(1000, 1);
		})
		
		
		
		
		// pour tous les liens, si ils n'ont pas de http://, on va les charger en javascript 
		$("a").each(function() {
			
			$a = $(this);
			var this_href = $a.attr('href');
			var this_rel = $a.attr('rel');
			
			// si ce n'est ni un lien externe, ni un lien de la gallerie
			if (this_href.indexOf ('http://') == -1 && this_rel.indexOf ('gall') == -1 && this_rel.indexOf ('gallery') == -1) {
				$a.click (function () {
					
					
					
					//$(".description").stop(true, false).fadeTo (1000, 0);
					$("#content_for_layout").stop(true, false).fadeTo (1000, 0, function () {
						$(".menu").find ("img").stop ();
						$(".menu").find ("img").css ({'opacity':1});
					setTimeout (function() {
																
																	// on relance le fadeTo dans l'autre sens sinon 
																	// avec le Back du navigateur, on ne voit plus rien
																	$('#content_for_layout').fadeTo	(700, 1);
																	// on a peut-être aussi fadeOuté le menu, donc on va faire la même chose pour
																	// le menu
											//						$(".menu").find ('img').stop(true, false).fadeTo(20, 1);
																	$(".menu").find ("img").fadeTo (700, 1);
																	$(".teaser").fadeTo (700, 1);
																	/*stop (true, false);
																	$(".menu").find ("img").css ({'opacity':1});
																	$(".teaser").css ({'opacity':1})*/
																}, 2000)
					window.location = this_href;
					})
				//	$("#title").stop (true, false).fadeTo(1000, 0);
					return false;	
				})
			}
		})
})








