
$(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(350, 1);
			}, function () {
				$img.stop().fadeTo(750, 0);
			});
		});
		
//////////The last one doesn't get a piece of cake
		$("ul").find("li:last").each(function(){
			$(this).css({"border":"none"});
		});
		
//////////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(value){
			document.cookie = "textSize="+value+"; expires=; path=/";
		}
		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 = $("body").css("font-size");
			var actualSize = actualSizePx.substr(-0,2);
			//alert(actualSize);
		return actualSize;
		
		
		}

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

		$("#minus").click(function(){
			showSize = getActualSize();
			parseSize = parseInt(showSize,10);
			var newSize = parseSize - 1;
			$("body").css({"font-size":newSize + "px"});
			setCookie(""+ newSize + "px");
			getActualSize();
			//alert(newSize);
		});
		$("#plus").click(function(){
			showSize = getActualSize();
			parseSize = parseInt(showSize,10);
			var newSize = parseSize + 1;
			$("body").css({"font-size":newSize + "px"});
			setCookie(""+ newSize + "px");
			getActualSize();
			//alert(newSize);		
		});
		
		
		
//////////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});
		});
		
		
//////////The french connection
		$("#connexion").each(function(){
			// options
			var hideDelay = 500;
			var hideDelayTimer = null;
			// tracker
			var beingShown = false;
			var shown = false;
			
			$("#connexion,#connectMe")
			.mouseover(function(){
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
				if (beingShown || shown) {
				return;
				} else {
				beingShown = true;
				
				$("#connectMe")
				.css({
					display: "block"
				})
				.animate({ 
					opacity:1,
					top:0
				},500, "swing", function() {
		          beingShown = false;
		          shown = true;
		        });
		        }
			}).mouseout(function(){
				hideDelayTimer = setTimeout(function () {
					hideDelayTimer = null;
					$("#connectMe")
					.animate({ 
						opacity:0,
						top:-45
					}, 500, 'swing', function () {
					shown = false;
					$("#connectMe").css('display', 'none');
					});
					}, hideDelay);
			});
		});

//////////Can I post it???
		$("#registerform").submit(function(){
			
			$(".require").each(function(){
				var require = $(this).val();
				if(require == ""){
					$(this).addClass("error");
					return false;
				}else{
					$(this).removeClass("error");
				}
			});
			
			var statut = $("#cimy_uef_9").val();
			var company = $("#cimy_uef_2").val();
			if(statut == "statut"){
				$("#cimy_uef_9").addClass("error");
				return false;
			}else{
				$("#cimy_uef_9").removeClass("error");
			}
			if(statut == "Agence"){
				$("label[for='cimy_uef_2']").append(" *");
			}
			if(statut == "Agence" && company == ""){
				$("#cimy_uef_2").addClass("error");
				return false;
			}else{
				$("#cimy_uef_2").removeClass("error");
			}
		});
		
//////////Print me me me...
		$("#print").click(function(){
			window.print();
		});
		
//////////Hide me and show my friend...
		$(".postTabs_divs").css("display","none");
		$(".postTabs_curr_div").css("display","block");
		
//////////To lay the table
		$("td.produit_longue_desc table").each(function(){
			var nbrTr = $(this).find("tr");
			var minTr = nbrTr.length;
			if( minTr > 3){
				$(this).addClass("tblPrix");
				$(this).attr("width","424");
				$(this).removeAttr("style");
				$(this).find("tr td:contains('    ')").empty();
				$(this).find("tr td").css("padding","10px");
				$(this).find("tr th").css("padding","10px");
				$(this).find("tr.startEven ~ tr:even").css("background","#dedede");
			};	
		});
		$("td.produit_longue_desc table.tblPrix").each(function(){
				$(this).attr("width","424");
				$(this).removeAttr("style");
				$(this).find("tr td:contains('    ')").empty();
				$(this).find("tr td").css("padding","10px");
				$(this).find("tr th").css("padding","10px");
				$(this).find("tr:even:not(.nbrJours)").css("background","#dedede");
		});

/////////She's The Form, you have to do what she say...
		$(".post").find(":text").each(function(){
			$(this).addClass("text");
		});
		$(".post").find(":password").each(function(){
			$(this).addClass("text");
		});
		$(".post").find(":checkbox").each(function(){
			$(this).addClass("check");
		});
		$(".post").find(":submit").each(function(){
			$(this).addClass("submit");
		});
		$(".post").find(":button").each(function(){
			$(this).addClass("submit");
		});
		$(".post:not(.fa)").find(":checkbox").each(function(){
			$(this).addClass("checkbox");
		});
		$(".post.fa").find(":checkbox").each(function(){
			$(this).addClass("checkPadding");
		});
		$(".post.fa").find(":radio").each(function(){
			$(this).addClass("checkPadding");
		});
		$("form input[name=code_postal_2]").addClass("codePostal");
		$("form input[name=code_postal_1]").addClass("codePostal");
		
//////////Look at my childs, they are beautifull...
		$("#mainMenu ul li").each(function(){
			$(this).find("ul").css("display","none");
			$(this).hover(function(){
				$(this).find("ul").css("display","block");
				$(this).find("ul ul").css("display","none");
			},function(){
				$(this).find("ul").css("display","none");
			});	
		});
				

//////////vip things
    $(':checkbox[name="attribute9"], :checkbox[name="attribute10"]').before('<div class="clear"></div>');
    $(':checkbox[name="attribute9"] + span, :checkbox[name="attribute10"] + span').wrap('<label class="deja checkbox left vip"></label>');
    $(':input[name="attribute4"] + label,:checkbox[name="attribute10"] + label + label, :checkbox[name="attribute9"], :checkbox[name="attribute10"], :input[name="attribute8"]').addClass('vip')
    $(':input[name="attribute8"]').after('<div class="clear vip"></div>');
    $('.vip').wrapAll('<div id="vip"></div>');
    $(':checkbox[name="list[4]"]').after($('#vip'));
    
    $(':checkbox[name="list[4]"]').click(function(){
      $('#vip').slideDown('slow');
      if ($(':checkbox[name="list[4]"]:checked').length !=1) {
        $('#vip').slideUp('slow');
      }
    });
    
    
    
//////////Count on me i'll be changing
		$("form input[name=code_postal_1]").keyup(function(){
			var text = $("form input[name=code_postal_1]").val();	
			var textlength = text.length;
			if(textlength == 3)
			{
				$("form input[name=code_postal_2]").focus();
			}
		});
		
//////////Picasso would have been proud...
		$(".gallery a").lightBox();
		
//////////You make me turning...
		$(".post form:not(.displayProduct)").corner();
		
//////////Register me please...
		$("a#registerMe").click(function(){
			$("#register").slideToggle("slow");
			return false;
		});
		
	});	
});