var lang = 'fr';
var path = 'fr';
var firstClick = 0;	
  $(function(){
	

	$('.header_img1').animate({
		opacity: 'show',			  
		left:0
	},1500);
	$('.header_img2').animate({
		opacity: 'show',			  
		right:0
	},1500,function(){
		$("#menu_top").addClass('fr').stop().fadeIn(1500);
		$("#lang").stop().fadeIn(1500, function(){
			$('#menu_bottom2').stop().fadeIn(1500, function(){
				$('.logo').stop().fadeIn(1500);										 
			});
		});
	});
	//showImg();
	
	$('#lang li a').click(function(){
		lang = $(this).attr('lang');
		if(lang=='fr'){
			$('#menu_top').removeClass('en');
			$('#menu_top').addClass('fr');
			path='fr';
		}else{
			$('#menu_top').removeClass('fr');
			$('#menu_top').addClass('en');
			path='en';
		}
		return false;
	});
	
	$('#menu_top li a').click(function(){	
		//console.log('click')							   
		var cssname = $(this).parent().get(0).className.substr(-5);
		activate(this);
		if(cssname != 'actif'){
			if(firstClick == 0){
				firstClick = 1;
				closeAnime($(this)[0].name, 1);
			}else{
				//console.log('firstClick = 1');
				openBlock($(this)[0].name, 1);
			}
			$(this).css({marginTop:0});
			$('#menu_page').fadeOut("slow");
			$('#text_page').fadeOut("slow");
		}
		return false;
	});	
  });
  
  function activate(id){
  	if(jQuery.browser.msie && parseInt(jQuery.browser.version) == 6) { 
		return false;
	}else{
		$('#menu_top li').removeClass('actif');
		$(id).parent().addClass('actif');
		$('#menu_top li').css({opacity : .5});
		$('#menu_top li.actif').css({opacity : 1});
		$(id).hover(function(){
			return false;
		},function() {
			return false;
		});
	}
  }
  
  function showImg(){
	if(jQuery.browser.msie && parseInt(jQuery.browser.version) == 6) { 
		return false;
	}else{
		$('#menu_top li').css({ opacity : .5 });
		$('#menu_top li').hover(function(){
			$(this).stop().animate({ opacity : 1 });
		}, function() {
			$(this).stop().animate({ opacity: .5 });
		});
	}
  }
  
  function closeAnime(name, id){
	if(!$('#content')[0]){
		$('<div id="content"></div>').appendTo('#wrapper');
		$('#content').animate({opacity: "show"},
		function(){ 
			$('<div class="holder"><div id="txt"></div></div>').appendTo('#content');
			openBlock(name, id)
		});
	}
  }
  
  function openBlock(name, id){
  		
		$('<div id="loader"></div>').appendTo('#content');

		$('#txt')[0].innerHTML = "";
	
		if($('.jqZoomWindow')[0]){
			$('.jqZoomWindow').remove(); // voir pour ie6
			$('.carte_info').remove();
			$('#relativeIE').remove();
			if(jQuery.browser.msie && parseInt(jQuery.browser.version) == 6) { 
				$('.zoom_ieframe').remove();
			}
		}
		$.get("contenu/" + path + "/" + name + "/" + name + "_menu.php", function(data){
			$('#txt')[0].innerHTML = data;
			
			$.get("contenu/" + path + "/" + name + "/" + name + "_" + id + ".php", function(data1){
				$('span.zoom').hide();
				$('#zoom'+id).show();
				id = id-1;
				$('#menu_bottom li a').css({marginTop:0, background:"none"});
				$('#loader').remove();
				$('#txt')[0].innerHTML += data1;

				$('#menu_page').stop().fadeIn("slow");
				$('#text_page').stop().fadeIn("slow");

				$('#main_content').jScrollPane({scrollbarWidth: 11, scrollbarMargin: 25, showArrows:true});
				
				$('<span></span>').appendTo('.jScrollPaneDrag');
				var h = $('#text_page').height();
				if(h <= 320){
					var marg = h/2;
					$('#text_page').addClass('small');
					$('#text_page').css({marginTop : -marg});
				}
				
				var hMenu = $('#menu_page').height();
				$('#menu_page').css({marginTop : -hMenu/2});
				
				if(id > 4){
					$('#menu_page li a:eq(4)').addClass('actif');
				}else{
					$('#menu_page li a:eq('+id+')').addClass('actif');
				}
				
				$('#menu_page li a').click(function(){
					if($(this)[0].id != 10){								
						openBlock(name, $(this)[0].id);	
						return false;
					}
				});
				
				$('#txt').css({"paddingLeft" : "250px","width" : "650px"});
				
				$('#content').css({
					"width" : "980px",
					"height" : "400px",
					"overflow":"hidden"
				});
			});
			
		});

  }
