$(document).ready(function()
	{
	$(function () {
			
//////////When you pass over me, I'm shining like the sun
		$('#mainMenu li').find('a').each(function () {
			var $img = $('img.hover', this).css("opacity", "0");
			var $img = $('img.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(350, 0);
			});
		});
		$('#LeRestaurantMenu li').find('a').each(function () {
			var $img = $('img.hover', this).css("opacity", "0");
			var $img = $('img.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(200, 0);
			});
		});
		$('#printandresize li').find('a').each(function () {
			var $img = $('img.hover', this).css("opacity", "0");
			var $img = $('img.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(250, 1);
			}, function () {
				$img.stop().fadeTo(250, 0);
			});
		});
		$('#btnTop').find('a').each(function () {
			var $img = $('img.hover', this).css("opacity", "0");
			var $img = $('img.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(150, 0);
			});
		});
		$('#Activis').find('a').each(function () {
			var $img = $('img.hover', this).css("opacity", "0");
			var $img = $('img.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(150, 0);
			});
		});
		$('#visualisez').find('a').each(function () {
			var $img = $('img.hover', this).css("opacity", "0");
			var $img = $('img.hover', this).css("display", "block");
			$(this).hover(function () {
				$img.stop().fadeTo(150, 1);
			}, function () {
				$img.stop().fadeTo(150, 0);
			});
		});
		
		
//////////The last one doesn't get a piece of cake
		$("ul").find("li:last").each(function(){
			$(this).css({"border":"none"});
		});
		
		
	
		
		
////////////////////////

			
	$(" #mainMenu ul .second ").css('opacity', 0);
	$(" #mainMenu ul .second ").css({display: "none"}); // Opera Fix		
	$('#mainMenu li:not(#mainMenu li li)').each(function () {
	    // options
	    var distance = 10;
	    var time = 250;
	    var hideDelay = 500;
	
	    var hideDelayTimer = null;
	
	    // tracker
	    var beingShown = false;
	    var shown = false;
	    
	    var trigger = $(this);
	    var popup = $('.second', this);
		if ($(this).find('.second').length !=0) {	
	    // set the mouseover and mouseout on both element
		    $([trigger.get(0), popup.get(0)]).mouseover(function () {
		      // stops the hide event if we move from the trigger to the popup element
		      if (hideDelayTimer) clearTimeout(hideDelayTimer);
		
		      // don't trigger the animation again if we're being shown, or already visible
		      if (beingShown || shown) {
		        return;
		      } else {
		        beingShown = true;
		
		        // reset position of popup box
		        popup.parents("li").find('a:first').addClass("borderImg");
		        popup.css({visibility: "visible"})
		
		        // (we're using chaining on the popup) now animate it's opacity and position
		        .animate({ 
					"height": "toggle",
					opacity: 1      
			    }, 300,"linear", function(){
			    	beingShown = false;
						shown = true;
			    });
		      }
		    }).mouseout(function () {
		      // reset the timer if we get fired again - avoids double animations
		      if (hideDelayTimer) clearTimeout(hideDelayTimer);
		      
		      // store the timer so that it can be cleared in the mouseover if required
		      hideDelayTimer = setTimeout(function () {
		        hideDelayTimer = null;
		        popup.animate({
		          height:'toggle',
		       	  opacity: 0
		        }, time, 'swing', function () {
		          // once the animate is complete, set the tracker variables
		          shown = false;
		          popup.parents("li").find('a:first').removeClass("borderImg");
				  popup.css({visibility: "hidden"});
		          // hide the popup entirely after the effect (opacity alone doesn't do the job)
		          popup.css('display', 'none');
		        });
		      }, hideDelay);
		    });
		}
	});
	



//////////When you look at me ... I completely disappear
		$("#top").find("input").each(function(){
			$(this).focus(function () {
				$(this).val("");
			});
		});
		
//////////Make me bigger or smaller, I don't care

		function setCookie(name,value){
			document.cookie=name+ "=" +escape(value)+";path=/;domains=";
		}
		function getCookie(c_name){
			if (document.cookie.length>0){
			  c_start=document.cookie.indexOf(c_name + "=");
				  if (c_start!=-1){ 
				    c_start=c_start + c_name.length+1; 
				    c_end=document.cookie.indexOf(";",c_start);
				    if (c_end==-1) c_end=document.cookie.length;
				    return unescape(document.cookie.substring(c_start,c_end));
			    } 
			}
		return "";
		}
		
		
		function getActualSize(){
			var actualSizePx = $("#colTexte").css("font-size");
			var actualSize = actualSizePx.substr(-0,2);
			//alert(actualSize);
		return actualSize;
		
		
		}

		
		getSize = getCookie("textSize");
		if(getSize!=null && getSize!=""){
			$("#colTexte").css({"font-size":""+getSize+""});
			getActualSize();	
		};

		$("#minus").click(function(){
			showSize = getActualSize();
			parseSize = parseInt(showSize,10);
			var newSize = parseSize - 1;
			$("#colTexte").css({"font-size":newSize + "px"});
			setCookie(""+ newSize + "px");
			getActualSize();
			//alert(newSize);
			return false;
		});
		$("#normal").click(function(){
			showSize = getActualSize();
			parseSize = parseInt(showSize,10);
			var newSize = 13;
			$("#colTexte").css({"font-size":newSize + "px"});
			setCookie(""+ newSize + "px");
			getActualSize();
			//alert(newSize);
			return false;
		});
		$("#plus").click(function(){
			showSize = getActualSize();
			parseSize = parseInt(showSize,10);
			var newSize = parseSize + 1;
			$("#colTexte").css({"font-size":newSize + "px"});
			setCookie(""+ newSize + "px");
			getActualSize();
			//alert(newSize);
			return false;
		});
		
		
		
//////////Vacances 
/*
		function closeMe(){
			setCookie('jozephilvacances','true');
			return false;
		}

		function openMe(){
			$("#box").css("z-index", "9999");
			var api = $("#box").overlay({api: true, expose: '#091421'});
			api.load();
			api.onClose(function (){
				closeMe();			
			});			
		}
			
		
		var estquejesuisvenuici = getCookie("jozephilvacances");
		if(estquejesuisvenuici == 'true'){
			return false;
		}else{
			openMe()
		}		
		
*/		
//////////Little bubble falling from the sky
		$("#bubble").css('opacity', 0);
		$("#soon").hover(function(){
			$("#bubble")
			.css({
				display: "block"
			})
			.animate( { opacity:1 }, { queue:false, duration:500 })
			.animate({top: "0px"},{ queue: false, duration:500});
		}, function(){
			$("#bubble").stop()
			.animate( { opacity:0 }, {duration:500 })
			.animate({top: "-45px"},{duration:1});
		});
		

///////////input text image 
		$('.newsfield ').each(function(){
			if ($(this).val()!='') {
				$(this).removeClass("fooImg");
			};
			if ($(this).val()=='') {
				$(this).addClass("fooImg");
			};
		});
		
				
		$('.newsfield ').focus(function(){
			$(this).removeClass("fooImg");
		});
		
		$("body").bind("mousemove",function(){
				$('.newsfield ').each(function(){
					if ($(this).val()!='') {
						$(this).removeClass("fooImg");
					};
					if ($(this).val()=='') {
						$(this).addClass("fooImg");
					};
				});
			});
		

//////////Formulaire de contact
		$(".button").click(function() {   
    // validate and process form here   
  		});
		
		$('.error').hide();
	  	$('input.text-input').css({backgroundColor:"#FFFFFF"});
	  	$('input.text-input').focus(function(){
			$(this).css({backgroundColor:"#D7CA9E"});
	  	});
	 	 $('input.text-input').blur(function(){
			$(this).css({backgroundColor:"#FFFFFF"});
	  	});
	
	 	 $(".button").click(function() {
			// validate and process form
			// first hide any error messages
		$('.error').hide();
			
		  var name = $("input#name").val();
			if (name == "") {
		  $("label#name_error").show();
		  $("input#name").focus();
		  return false;
		}
			var l3irruoc = $("input#l3irruoc").val();
			if (l3irruoc == "") {
		  $("label#l3irruoc_error").show();
		  $("input#l3irruoc").focus();
		  return false;
		}
			var message = $("textarea#message").val();
			if (message == "") {
		  $("label#message_error").show();
		  $("textarea#message").focus();
		  return false;
			
		}
			/*var typevenement = $("input#typevenement").val();
			var date = $("input#date").val();
			var heure = $("input#heure").val();
			var nbrpersonnes = $("input#nbrpersonnes").val();
			var typemenu = $("input#typemenu").val();*/
			
			var dataString = 'name='+ name + '&l3irruoc=' + l3irruoc + '&message=' + message;
			//alert (dataString);return false;
			
		$.ajax({
		  type: "POST",
		  url: "/bin/process.php",
		  data: dataString,
		  //data: "name=john&l3irruoc=eduplessis@gmail.com&phone=6876",
		  success: function() {
			$('#formMail').html("<div id='messageConf'></div>");
			$('#messageConf').html("<h6>Votre message a été envoyé avec succès.</h6>")
			.append("<p class='highLight'>Nous vous contacterons dans les plus brefs délais.</p>")
			.hide()
			.fadeIn(1500, function() {
			  $('#messageConf').append("<img id='checkmark' src='../img/good_32x32.gif' />");
			});
		  }
		 });
		return false;
		}); 
		
//////////Print me me me...
		$("#print").click(function(){
			window.print();
			return false;
		});
		
	});
});