/**
 * @author jeremymondon
 */

 
$(document).ready(function(){
	
	
	$("#societe").change(function(){
		
		$("#projet").val("");
		
		$(".sliding img").each(function()
		{
			if ($("#societe").val() != "") {
				if ($(this).attr("soc") != $("#societe").val()) {
					$(this).fadeOut();
				}
				else {
					$(this).fadeIn();
				}
			}else
			{
				$(".sliding img").fadeIn();
			}
			
			
		});
		
	});
	
	$("#projet").change(function(){
		
		$("#societe").val("");
		
		$(".sliding img").each(function()
		{
			if ($("#projet").val() != "") {
				if ($(this).attr("proj") != $("#projet").val()) {
					$(this).fadeOut();
				}
				else {
					$(this).fadeIn();
				}
			}else
			{
				$(".sliding img").fadeIn();
			}
			
			
		});
		
	});
	
	$(".thumbs img").hover(function(){
		
		
		 $(this).attr("src", "/images/thumbs/" + $(this).attr("class") + "_on.jpg"); 
		
	}, function(){
		
		 if (!$(this).attr("disabled") || $(this).attr("disabled") == "false") 
$(this).attr("src", "/images/thumbs/" + $(this).attr("class") + ".jpg"); 
		
	});
	
	
	$(".thumbs img").each(function(){
		
		if($(this).attr("disabled") != "true") $(this).attr("disabled",false);
		
	});
	
	
	$(".metier_menu a").click(function()
	{
		$(".metier_menu a").removeClass("act")	;
		
		var alink = $(this);
		
		$(".metier_menu .active").animate({top: $(this).attr("top")}, 
		function(){
				alink.addClass("act");
				var type = alink.attr("type");
				
				$(".metier_captures img").each(function(){
					
					if($(this).attr("type") != type) $(this).hide();
					else $(this).fadeIn();
					
				});
				
				$(".metier_txt .inner_txt").each(function(){
					
					if($(this).attr("type") != type) $(this).hide();
					else $(this).fadeIn();
					
				});
				
		});
		
	});
	
	
	$(".controlright").click(function(){
		
		var posx = parseInt($(".sliding").css("left"),10);
		
		var max = 126 * $(".sliding img").length;
		max -= 762;
		
		if(posx>= (max * (-1)))
		{
			posx -= 762;
			
		}
		
		$(".sliding").animate({ left : posx },"normal");

				
	});
	
	$(".controlleft").click(function(){
		
		var posx = parseInt($(".sliding").css("left"),10);
		
		
		
		if(posx< 0)
		{
			posx += 758;
			
		}
		
		$(".sliding").animate({ left : posx },"normal");

				
	});
	
	
	$(".thumbs img").click(function(){
		
		$(".real").hide();
		
		$("#" + $(this).attr("class")).fadeIn();
		
		$(".thumbs img").each(function(){
		
			$(this).attr("src", "/images/thumbs/" + $(this).attr("class") + ".jpg"); 
			$(this).attr("disabled",false);
		
		});
		
		$(this).attr("src", "/images/thumbs/" + $(this).attr("class") + "_on.jpg"); 
		
		$(this).attr("disabled",true);
		
	});
	
	$(".package").click(function(){
		
		$("#package").dialog({modal : true, width: 500, autoOpen: false, title : "Site institutionnel"});
		$("#package").dialog('open');
		
	});
	

	
});
