﻿var lang = 'fr';
var path = 'fr';
var firstClick = 0;
  $(function(){
		
	if(jQuery.browser.msie && parseInt(jQuery.browser.version) == 6) { 
		var ieH = $(window).height();
		if(ieH >= 720){
			$('#global').css({height: '100%'});
		}
		$(window).resize(function(){
			if($(window).height() >= 720){
				$('#global').css({height: '100%'});
			}else{
		  		$('#global').css({height: 720});
			}
		});
	}
	$("#menu_top").fadeIn(2500);
	$("#lang").fadeIn(2500);
	$(".msk").animate({ left: 800 }, 2500);
	setTimeout(removeMsk,10000);
	
	$('#lang li a').click(function(){

		lang = $(this).attr('lang');
		
		if(lang=='fr'){
			$('#menu_bottom').addClass('fr');
			path='fr';
		}else{
			$('#menu_bottom').addClass('en');
			path='en';
		}

		$("#slogan").fadeOut(500);
		$('#lang').fadeOut(500);
		$("#ch_pics").fadeIn(1500, showImg);
		$('#ch_pics li a').css({opacity:0});
		
		//$('#offre').fadeOut(5000);
						
		return false;
	});
	
	$('#menu_bottom li a').click(function(){
	
		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{
				openBlock($(this)[0].name, 1);
			}
			$('#menu_bottom li a').css({marginTop:-13});
			$(this).css({marginTop:0});
			$('#menu_page').fadeOut("slow");
			$('#text_page').fadeOut("slow");
		}
		return false;
	});	
	
	
  });
  
  function removeMsk(){
  	$(".msk").animate({left: 0}, 1500);
	$("#slogan").animate({opacity: 0},1500);
  }
  
  function activate(id){
  	if(jQuery.browser.msie && parseInt(jQuery.browser.version) == 6) { 
		return false;
	}else{
		$('#menu_bottom li').removeClass('actif');
		$(id).parent().addClass('actif');
		$('#menu_bottom li').css({opacity : 1});
		$('#menu_bottom li.actif').css({opacity : .5});
		$(id).hover(function(){
			return false;
		},function() {
			return false;
		});
	}
  }
  
  function showImg(){
  	var nbr = $('#ch_pics li').size();
	var oldLeft = Array(230,376,522,668);
	for(i=1;i<=nbr;i++){
		$('.ch'+i).animate({left : oldLeft[i-1]}, 1000, 
		function (){
			$('#ch_pics li span').animate({opacity:0},500);
			$('#ch_pics li a').hover(function(){
				$(this).stop().animate({ opacity: 1 });
			}, function() {
				$(this).stop().animate({ opacity: 0 });
			});
			$("#menu_bottom").fadeIn(1500);
		});
	}
	if(jQuery.browser.msie && parseInt(jQuery.browser.version) == 6) { 
		return false;
	}else{
		$('#menu_bottom li').hover(function(){
			$(this).stop().animate({ opacity : .5 });
		}, function() {
			$(this).stop().animate({ opacity: 1 });
		});
	}
  }
  
  function closeAnime(name, id){
	$('#ch_pics li a').animate({opacity : 1},
		function(){
			$('#ch_pics li').animate({left : 530}, 1000,
			function(){
				$('#ch_pics li').css({background:"none"});
				$('#ch_pics li a').animate({opacity : 0}, 250);
				$('#ch_pics li span').animate({opacity : 1, backgroundColor : "#b4ada5"}, 
				function(){
					if(!$('#content')[0]){
						$('<div id="content"></div>').appendTo('#wrapper');
						$('#content').animate({width : 980, left : 0}, 1000).animate({height: 400, top:-215}, 1000,
						function(){ 
							$("#menu_bottom2").fadeIn(2500);
							$('<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){
				id = id-1;
				$('#menu_bottom li a').css({marginTop:0, background:"none"});
				$('#loader').remove();
				$('#txt')[0].innerHTML += data1;
				
				if(name != "carte"){
					$('#menu_page').fadeIn("slow");
				}
				$('#text_page').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});
				$('#menu_page li a:eq('+id+')').addClass('actif');
				
				$('#menu_page li a').click(function(){
					openBlock(name, $(this)[0].id);	
					return false;				
				});
				
				
				if(name == "carte"){
					if(lang=='fr'){
						$('<p id="relativeIE" class="relative"><p class="carte_info">Déplacer le rectangle pour agrandir l\'image</p></p>').insertBefore('.holder')
					}else{
					$('<p id="relativeIE" class="relative"><p class="carte_info">Drag to zoom</p></p>').insertBefore('.holder')
					}
					$('.jScrollPaneContainer').css({width : 900});
					$('#main_content').css({width : 900, overflow: "hidden"});
					$('#txt').css({width : 900,paddingLeft : 0});
					$('#text_page').css({width : 900,top:0, marginTop:0});
					var options = {
						zoomWidth: 430,
						zoomHeight: 320,
						showPreload:false,
						alwaysOn: true,
						yOffset:-1,
						title:false,
						position: "right"
					}
					$('.zoom').jqzoom(options);
				}else{
					$('#txt').css({"paddingLeft" : "250px","width" : "650px"});
				}
				$('#content').css({
					"width" : "980px",
					"height" : "400px",
					"overflow":"hidden"
				});
			});
			
		});

  }
