$(document).ready(function(){
	/* This code is executed after the DOM has been completely loaded */
	
	// random color for logo
	var colors = new Array('pink','yellow','black','blue','green','brown');
	var color = colors[Math.floor(Math.random()*colors.length)];
	$('#hm').attr('src','images/logos/hello-media-'+color+'.gif');
	$('#hm').fadeIn(10000);			
	
	
	
	/* main menu */
	
	$('#main-menu ul li a').click(function(e){

			
			/* modif du li actif : act => inact , modif src image en PAS _select */
			var li1 = $(this).parent().siblings().filter(".act");
			li1.removeClass('act').addClass('inact');
			
			/* modif du li clique : l'image est deja en "select" puisque hover avant de cliquer */
			var li2 = $(this).parent();
			li2.addClass('act').removeClass('inact');
			
			var targetId = $(this).parent().attr("title");
			$.scrollTo('#'+targetId, 700 );
			
			// change logo color
			if ( targetId == 'hello' ){
				var colors = new Array('pink','yellow','black','blue','green','brown');
				var color = colors[Math.floor(Math.random()*colors.length)];
				$('#hm').fadeTo(10, 0.1, function (){
													$(this).attr('src','images/logos/hello-media-'+color+'.gif');
													$(this).fadeTo(1000, 0.5, function(){
															$(this).fadeTo(2000, 1);
																						}
																	)
															}
										);
			}
			
			e.preventDefault();
			/* Prevent the default action of the link */
	});
	
	$("#main-menu ul li a").mouseover(function() { 
	
			/*$(this).parent().fadeTo(10, 0.1, function (){
													$(this).fadeTo(500, 1, function(){})
															}
										);*/
				
	});
	

	$(".rubrique").mouseover(function() { 
				$('#main-menu').fadeIn(5000);
				// pour le cas ou on arrive sur la page, pas encore d'élément de menu spécifié
				if ( ! $('#main-menu li').hasClass('act') ){
					var ru = $(this).attr("id");
					$('#main-menu li[title='+ru+']').addClass('act');
				}
	});
	
	
	/* sub-menus */
	
	$('.sub-menu ul li a').click(function(e){

			/* On a thumbnail click */

			/* modif du li actif : act => inact , modif src image en PAS _select */
			var li1 = $(this).parent().siblings().filter(".act");
			li1.removeClass('act').addClass('inact');
			
			/* modif du li clique : l'image est deja en "select" puisque hover avant de cliquer */
			var li2 = $(this).parent();
			li2.addClass('act').removeClass('inact');
				
			/* hides the old  */
			var idToHide = li1.attr("title");	
			/*$('#'+idToHide).css("display","none");*/
			$('#'+idToHide).hide();
					
			/* show the new  */
			var idToShow = li2.attr("title");
			// reset: vérifie que le ul thumbnails est bien visible (si il y en a 1)
			$('#'+idToShow+' ul.thumbs').css("display","block");
			// reset: vérifie que tout le reste est bien invisible (dans le cas ou il y a un ul thumbnails)
			$('#'+idToShow+' ul.thumbs').siblings("div:not(.clear)").css("display","none");
			// reset: vérifie que tous les thumbs sont inactifs (pour les thumbnails)
			$('#'+idToShow+' ul.thumbs li.act').removeClass('act').addClass('inact');
			// show the new
			$('#'+idToShow).show("slow");
		
			e.preventDefault();
			/* Prevent the default action of the link */
	});
	
	$(".sub-menu ul li a img").mouseover(function() { 
			$(this).parent().parent().addClass('hover');
			/*$(this).parent().fadeTo(10, 0.1, function (){
													$(this).fadeTo(500, 0.5, function(){
															$(this).fadeTo(1000, 1)
																						}
																	)
															}
										);*/
			
		})
		.mouseout(function() {
			$(this).parent().parent().removeClass('hover');
		});
	
	
	$('.sub-menu ul li:first-child').addClass('act').siblings().addClass('inact');
	/* On page load, mark the first thumbnail as active */
	/* ATTN: li:first => only in the first sub-menu */
	/* li:first-child => all the submenus  */
	
	
	
	/* item-menus thumbnails for work-content */
	
	$('#work-content div ul li a').click(function(e){

			/* On a thumbnail click */
			/* modif du li actif : act => inact , modif src image en PAS _select */
			var li1 = $(this).parent().siblings().filter(".act");
			li1.removeClass('act').addClass('inact');
			
			/* modif du li clique : l'image est deja en "select" puisque hover avant de cliquer */
			var li2 = $(this).parent();
			li2.addClass('act').removeClass('inact');
			
			// hides the old
			var idToHide = li1.attr("title");
			$('#'+idToHide).hide();
			
			/* show the new  */
			var idToShow = li2.attr("title");
			$('#'+idToShow).show("slow");
	
		
			e.preventDefault();
			/* Prevent the default action of the link */
	});
	
	//$('#work-content div ul li:first-child').addClass('act').siblings().addClass('inact');
	$('#work-content div ul li').addClass('inact');
	/* On page load, mark the first thumbnail as active ( even if the content is not visible ) */
	/* ATTN: li:first => only in the first sub-menu */
	/* li:first-child => all the submenus  */
	
	
	
	
	$("ul.thumbs img").mouseover(function() { 
			$(this).addClass('hover');
		})
		.mouseout(function() {
			$(this).removeClass('hover');
		});
		
	
	
});

