// JavaScript Document
$(document).ready(function(){
	delete_cookie("compteur");
	delete_cookie("nbrLoaded");
	$(window).load(function(){
		mipotsaka($(".mnuActive").attr("id"));
	});
	//$(document).pngFix();
	$("img").pngfix();
});

function nothing(){
}

function compteCharge(){
	if(!get_cookie("nbrLoaded")){
		set_cookie("nbrLoaded", 0);
	}
	nb = get_cookie("nbrLoaded");
	if(nb >= 5){
		$(".enCharge").animate({opacity:0}, 2000, function(){
			$(".enCharge").remove();
		});
	}else{
		nb++;
		set_cookie("nbrLoaded", nb)
	}
	$(".enCharge").animate({opacity:0}, 2000, function(){
		$(".enCharge").remove();
	});
}

function mipotsaka(nomPage){
	tab = nomPage.split(" ");
	$("div[id='accordeonMenu']").animate({height:"0px", marginTop:"-22px"}, 0, function(){
		$("div[id='accordeonMenu']").html("<table style='height:100%;'><tr><td valign='middle'>"+tab[0]+"<br />"+tab[1]+"</td></tr></table>");
		$("div[id='accordeonMenu']").animate({height:"0px", marginTop:"-22px"}, 200, function(){
			$("div[id='accordeonMenu']").animate({height:"0px", marginTop:"-26px"}, 100, function(){
				$("div[id='accordeonMenu']").animate({height:"102px", marginTop:"10px"}, 700);
			});
		});
	});
}

function goDiapo(series){
	$("div[id='cacheDiapo']").show();
	$("div[id='cacheDiapo']").animate({opacity:0}, 1, function(){
			$("div[id='cacheDiapo']").animate({opacity:0.8}, 500, function(){
				$("div[id='grand']").show();
				$("div[id='grand']").animate({opacity:1}, 300);
			});
	});
	$("#gallery").html("<object type='application/x-shockwave-flash' data='images/makiGallery.swf' width='800' height='500'><param name='wmode' value='transparent' /><param name='play' value='true' /><param name='movie' value='images/makiGallery.swf' /><param name='menu' value='false' /><param name='quality' value='high' /><param name='scalemode' value='noborder' /><param id='sendVar' name='flashvars' value='series="+series+"' /></object>");
	
}

function finDiapo(){
	$("div[id='grand']").animate({opacity:0},300, function(){
		$(this).hide();
	});
	$("div[id='cacheDiapo']").animate({opacity:0},300, function(){
		$(this).hide();
	});
	$("#sendVar").remove();
}

function manjavona(){
	if(!get_cookie("compteur")){
		set_cookie("compteur", 0);
	}
	x = get_cookie("compteur");
	if(x >= 5){
		$("img[id='photo0']").animate({opacity:1}, 1);
		$("img[id='photo1']").animate({opacity:1}, 1);
		$("img[id='photo2']").animate({opacity:1}, 1);
		$("img[id='photo3']").animate({opacity:1}, 1);
		$("img[id='photo4']").animate({opacity:1}, 1);
		$("img[id='photo5']").animate({opacity:1}, 1);
		set_cookie("compteur", 0);
		manjavona();
	}else{
		$("img[id='photo"+x+"']").animate({opacity:1}, 3000, function(){
			$(this).animate({opacity:0}, 1000, manjavona);
		});
		x++;
		set_cookie("compteur", x);
	}
}

function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure ){
  var cookie_string = name + "=" + escape ( value );
  if ( exp_y ){
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }
  if ( path ) cookie_string += "; path=" + escape ( path );
  if ( domain ) cookie_string += "; domain=" + escape ( domain );  
  if ( secure ) cookie_string += "; secure";
  document.cookie = cookie_string;
}

function get_cookie ( cookie_name ){
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

function delete_cookie ( cookie_name ){
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

function chargeImg() {
	$("img[id='photo5']").load(function () {
		//$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
		$(this).hide();
		$('#loader').removeClass('loading').append(this);
		$(this).fadeIn();
	}).error(function () {
		// notify the user that the image could not be loaded
	}).attr('src', 'images/makimadagascar5w.jpg');
}

function verifMail(a){
if(a == ""){
	alert("Vous avez oublié de saisir votre adresse email.");
}else{
testm = false ;
	for (var j=1 ; j<(a.length) ; j++) {
		if (a.charAt(j)=='@') {
			if (j<(a.length-4)){
				for (var k=j ; k<(a.length-2) ; k++) {
					 if (a.charAt(k)=='.') testm = true;
				}
			}
		}
	}
	if (testm==false){
		alert('Votre adresse e-mail est incorrecte.');
	}else{
		verifForm();
	}
}
}

function verifForm(){
	if($("#nom").attr("value")!=""){
		if($("#prenom").attr("value")!=""){
			if($("#tel").attr("value")!=""){
				if($("#sujet").attr("value")!=""){
					if($("#msg").attr("value")!=""){
						$("#frmContact").submit();
					}else{
						alert("merci de remplir le formulaire correctement : Message.");
					}
				}else{
					alert("merci de remplir le formulaire correctement : Objet");
				}
			}else{
				alert("merci de remplir le formulaire correctement : N° Tel.");
			}
		}else{
			alert("merci de remplir le formulaire correctement : Prénom");
		}
	}else{
		alert("merci de remplir le formulaire correctement : Nom");
	}
}