// JavaScript Document

$(document).ready(function(){
	$("#corp").animate ({marginLeft: 70},1000).animate ({height:380},1000,function () {
		$("#centre_corp").removeClass("anim_fl");
		$('#corp .scroll').jScrollPane({animateTo:true, animateInterval:50, animateStep:5});
	})  ;
	var txt_intro_h = $(".txt_intro").css('height');
	$(".prod")
	.hover( function() { $(this).addClass ("on");},function(){$(this).removeClass('on');})
	.each ( function (length_num) {
		$(this)
		.addClass ('length_num'+length_num)
		.click ( function () {
			$(this).click_projet (length_num);
		});
	});	
	$("#bt_fl").click (function (){
		if ($(this).attr('etap')=='hom') {
			txt_intro_h = $(".txt_intro").css('height');
			$('.length_num0').click_projet (0);
			ferm_footer();
		}else {
			$("#corp")
			.animate({width: 370},1000, function(){
				$(this).removeClass("fiche_projet");
				$('.txt_corp').remove();
			});
			
			$(".txt_intro").css ({height:txt_intro_h}).attr ('ouver','true');
			
			$(".fiche_projet_on")
			.animate ({height:0}, 800,function () {
				$(this).remove();					
			});
			ferm_footer();
			$(this).attr('etap','hom');
			$('#corp .actif').removeClass('actif');
			$('#corp .jScrollPaneTrack').css({left:"auto", width:10})
			
		}
	});
	$(".txt_intro")
	.click (function () {
		txt_intro_h = $(".txt_intro").css('height');
		$(this).animate ({height:3}, 600);
		$('.length_num0').click_projet (0);
		ferm_footer();
	})
	.hover( function() { $(".fle_bot_off").addClass ("fle_bot_over");},function(){$(".fle_bot_off").removeClass('fle_bot_over');})
	
	$('#footer .bt-open').click(function() {
		if($(this).attr('ouvert')!='true') {
			$('.cont_txt').html($('.src',this).html());
			$('#footer .bt-open').attr('ouvert','ok').removeClass('on');
			$(this).attr('ouvert','true').addClass('on');
			if($(this).attr('ouvert')!='ok') {
				$('.cont_txt').addClass ('cont_txt-actif');
				$("#anim_top_corp").animate ({marginTop: -550},1000);	
				$('.cont_txt').animate ({height: 300},1000, function(){
					$('#footer .cont_txt .scroll').jScrollPane({animateTo:true, animateInterval:50, animateStep:5});													 
				});
			}else{
				$('#footer .cont_txt .fd').jScrollPane({animateTo:true, animateInterval:50, animateStep:5});
			}
		}else{
			ferm_footer();
		}
	});
	function ferm_footer(){
		var txt_intro_h = $(".txt_intro").css('height');
		$("#anim_top_corp").animate ({marginTop: 0},1000)	
		$('.cont_txt').animate ({height: 1},1000, function() {
			$('.cont_txt').removeClass ('cont_txt-actif').html('');													
		})
		$('#footer .bt-open').attr('ouvert','false').removeClass('on');
	}
	$.fn.extend({
		click_projet : function (length_num) {
			var this_length = length_num;
			var this_html = $('.col_txt', this).html();
			var this_img;
			var this_pager ='<ul class="pager_images">';
			$('.img a', this).each ( function (i) {
				if (i==0){ 
					this_img = $(this).attr('href');
				}
				var num =i+1;
				this_pager +='<li>'+num+'</li>';
			});
			this_pager +='</ul>';
			var this_lien = $('.lien', this).html();
			$(".actif").removeClass("actif");
			$(this).addClass("actif");
			$(".txt_corp").remove(".txt_corp");
			$("#corp")
			//.addClass("fiche_projet")
			.after("<div class='txt_corp'>"+this_html+"</div>");
			if($("#corp").css("width")!='62px') {
				$(".txt_intro").animate ({height:3}, 600).attr ('ouver','false');
				$("#corp")
				.animate({width: 62},1000,function(){
					affVis ();
				})
			}else{
				affVis ();
			}
			function affVis () {
				$("#corp .jScrollPaneTrack").css({left:4, width:7 });
				$(".fiche_projet_on").remove();
				$("#px")
				.addClass("on")
				.before("<div class='fiche_projet_off'><div class='img_site'  style='background:url("+this_img+");'></div><div class='lien_site'>"+this_lien+"</div>"+this_pager+"</div>")
				.animate ({bottom:220}, 400, function (){
					$(".fiche_projet_off")
					.removeClass("fiche_projet_off")
					.addClass("fiche_projet_on")
					.animate ({height:191}, 600, function (){
							$(this).css({top:48}).animate ({height:383},900,
								function () {
									$('.pager_images li',this).click (
										function () {
											var src_img ;
											var num_img = $(this).html()-1;
											$(".prod").each (function (i){
												if (i==this_length) {
													$(".img a",this).each ( function (y) {
														if (y==num_img) {
															src_img = $(this).attr('href');
														}
													});
												}
											})
											$(".img_site").css({background: "url("+src_img+")"});
										}
									);
									
								}
							)
						}
					)
				})
				.animate ({bottom:500}, 600,function () {									  
					$("#px").css({bottom:0}).removeClass("on");
				});
			}
			$("#bt_fl").attr('etap','projet');
		}
	})
})