// JavaScript Document
var swfu;
var page;


$(document).ready(function() {			
			
	//FIX IE6
	if((window.XMLHttpRequest == undefined) && (ActiveXObject != undefined)){
		$('#cont_menu ul.primary li h2 a').mouseover(function(){$(this).addClass('ie6fixhover');});
		$('#cont_menu ul.primary li h2 a').mouseout(function(){$(this).removeClass('ie6fixhover');});
		$('#cont_footer ul.primary li h2 a').mouseover(function(){$(this).addClass('ie6fixhover');});
		$('#cont_footer ul.primary li h2 a').mouseout(function(){$(this).removeClass('ie6fixhover');});
	}
	//FIN FIX
	
	$('embed, object').click(function(){top.location = "http://www.rio-mavuba.com/";});
	
	 $("a.fancyBox").fancybox(); 
	init();
	function init()
	{
		$('#reload_captcha').click(function(){
										document.getElementById('captcha').src = $('#basurl').val() + '/library/common/captcha/captcha_image.php?sid=' + Math.random(); return false;
										});
										
		$('#envoyer_form').click(function(){
				contactAjax();
				return false;
		});
		
		$("form").submit(function(){
				contactAjax();
				return false;
		});
		
		$('input, textarea').focus(function(){
								  $(this).css({border : "1px solid #795e0c", backgroundColor : "white"});
								});
		$('input, textarea').blur(function(){
								  $(this).css({border : "1px solid #5B5B5B", backgroundColor : "#E7E7E7"});
								});
		
		$('#envoyer_form').mouseover(function(){
								  $(this).css({border : "1px solid #795e0c", backgroundColor : "white"});
								});
		
		$('#envoyer_form').mouseout(function(){
								  $(this).css({border : "1px solid #5B5B5B", backgroundColor : "#E7E7E7"});
								});
	}
	
	function contactAjax()
	{
		$('.errMsg').fadeOut('normal', function(){$('.errMsg').remove();});
		$('.successMsg').fadeOut('normal', function(){$('.successMsg').remove();});
		$('form').after('<div class="loadMsg">Envoi du message...</div>');
		$('.loadMsg').hide();
		$('.loadMsg').fadeIn();
		var ent_pseudo = $('#ent_pseudo').val();
		var ent_message = $('#ent_message').val();
		var ent_mail = $('#ent_mail').val();
		var ent_code = $('#ent_code').val();
		var basurl = $('#basurl').val();
		var mdl = $('#mdl').val();
		if(mdl == 'contact'){
			var initurl = 'mdl=contact&action=send';
		}else if(mdl == 'livre-d-or'){
			var initurl = 'mdl=livre-d-or&action=ajout';
		}
		else{return false;}
		$.ajax({
				   type: "POST",
				   url: basurl + "/index.php",
				   data: "ajax=true&" + initurl + "&ent_pseudo="+ent_pseudo+"&ent_mail="+ent_mail+"&ent_message="+ent_message+"&ent_code="+ent_code,
				   async: false,
				   success: function(repPHP){
					  $('.loadMsg').fadeOut('normal', function(){
						  var t = setTimeout(function(){clearTimeout(t);}, 1000);
						  $('.loadMsg').remove();
						  if(repPHP == 'error'){
							  $('form').after('<div class="loadMsg">Une erreur inconnue s\'est produite.</div>');
							  $('.loadMsg').hide();
							  $('.loadMsg').fadeOut();
							  var t = setTimeout(function(){$('.loadMsg').fadeOut();$('.loadMsg').remove();clearTimeout(t);}, 4000);
							  return false;
						  }
						  $('#contenu_contact').html(repPHP);
						  $('.errMsg').hide();
						  $('.errMsg').fadeIn('slow');
						  $('.successMsg').hide();
						  $('.successMsg').fadeIn('slow');
						  var t3 = setTimeout(function(){
						  	$('.successMsg').fadeOut('normal', function(){
						  		$('.successMsg').remove();
						  		clearTimeout(t3);
						  	});
						  }, 3000);
						  var t2 = setTimeout(function(){
						  	$('.errMsg').fadeOut('normal', function(){
						  		$('.errMsg').remove();
						  		clearTimeout(t2);
						  	});
						  }, 3000);
						  init();
					  });
				   }
				});
	}
	
});

