$(function (){
	// Supression du texte par défaut lors de la réception du focus
	$(":input").focus(function(srcc) {
		if ($(this).val() == $(this)[0].title)
			$(this).val("");
	});

	// Application de la valeur par défaut lors de la perte du focus, si ce dernier est vide
	$(":input").blur(function()	{
		if ($(this).val() == "")
			$(this).val($(this)[0].title);
	});

	$(":input").blur();

	// Les fancy (mediabox)
	$(".mediabox").fancybox({
		'padding' : 0,
		'titleShow' : true,
		'titlePosition' : 'over',
		'overlayOpacity' : 0.6
	});


	$('#slide').nivoSlider({
		effect:'random',
		animSpeed:500,
		pauseTime:4000,
		directionNav:false,
		controlNav:false,
		pauseOnHover:false
	});

	/////////////////////////////////////////////////////////////////////////
	//                         BATIMENT - ANTICO
	/////////////////////////////////////////////////////////////////////////
	// OnChange des form batiment on submite les forms bat ...
    $("#form1, #form2").change(function(){
		$(this).submit();
	});

	// Gestion des forms batiment.
	$("#form1, #form2").submit(function(){
        $(this).ajaxStart(function(){
			$('#colonne_droite_liste, #form1, #form2').fadeTo(300,0.3);
        });

        $.ajax({
            type: "POST",
            url: $(this).attr("action"),
            data: $("#form1, #form2").serializeArray(),
            success:function(responseText){
                insert = responseText;
            },
            complete:function(){
				$('#colonne_droite_liste').html(insert);
				$("#colonne_droite_liste, #form1, #form2").fadeTo(300,1,function(){
					// Les fancy (mediabox)
					$(".picto_box").fancybox({
						'width' : '50%',
						'height' : '60%',
						'autoScale' : false,
						'transitionIn' : 'elastic',
						'transitionOut' : 'fade',
						'speedIn'		:	1000,
						'speedOut'		:	500,
						'type' : 'iframe'
					});
					$("#colonne_droite_liste td ul li").hover(function(){
						$(this).css({'z-index' : '10'});
						$(this).append('<div class="caption">' + $(this).find("img").attr("alt") + '</div>')
						$(this).find(".caption").fadeIn(200);
						$(this).find('img').addClass("hover").stop()
							.animate({
								top: '-23px',
								left: '-23px',
								width: '80px',
								height: '80px'
							}, 200);
					},function(){
						$(this).css({'z-index' : '0'});
						$(this).find("div.caption").remove();
						$(this).find('img').removeClass("hover").stop()
							.animate({
								top: '0',
								left: '0',
								width: '30px',
								height: '30px'
							}, 200);
					});
				});
            }
        });

        return false;
    });

	// Submit à l'ouverture de la page bat - ant ...
	$("#form2").submit();




	/////////////////////////////////////////////////////////////////////////
	//                               SOL
	/////////////////////////////////////////////////////////////////////////
	$("#form_sol_prod, #form_sol_sys").submit(function(){
		$.ajax({
			type: "POST",
			url: $(this).attr("action"),
			data: $(this).serializeArray(),
			success:function(responseText){
				insert_sol = responseText;
			},
			complete:function() {
				$('#colonne_droite_liste, #colonne_droite_liste2').html(insert_sol);
				$('#colonne_droite_liste').fadeTo(300,1);
				$(".sol_box").fancybox({
					'width' : '50%',
					'height' : '60%',
					'autoScale' : false,
					'transitionIn' : 'elastic',
					'transitionOut' : 'fade',
					'speedIn'		:	1000,
					'speedOut'		:	500,
					'type' : 'iframe'
				});
			}
		});

		return false;
	});

	// Gestion des onglets ...
	$("#LinkSolOne, #LinkSolTwo").click(function(){
		var MyID = $(this).attr('id');
		if(MyID == 'LinkSolOne')
		{
			var MyForm		= '#form_sol_prod';
			var NoForm 		= '#form_sol_sys';
			var NoClass		= '#LinkSolTwo';
		}

		if(MyID == 'LinkSolTwo')
		{
			var MyForm 		= '#form_sol_sys';
			var NoForm 		= '#form_sol_prod';
			var NoClass		= '#LinkSolOne';
		}

		$(NoForm)[0].reset();
		$(NoForm).css("display", "none");
		$(MyForm).css("display", "block");

		$(MyForm).submit();
		return false;
    });

	$("#form_sol_prod, #form_sol_sys").change(function(){
		$(this).submit();
	});

	$("#form_sol_prod").submit();


	/////////////////////////////////////////////////////////////////////////
	//                             PHOTOS
	/////////////////////////////////////////////////////////////////////////
	$("#form_foto").submit(function(){
		$.ajax({
			type: "POST",
			url: $(this).attr("action"),
			data: $(this).serializeArray(),
			success:function(responseText){
				insert = responseText;
			},
			complete:function() {
				$('#Contain2Change').html(insert);
				$(".photo_box").fancybox({
					'autoScale' : false,
					'transitionIn' : 'elastic',
					'transitionOut' : 'fade',
					'speedIn'		:	1000,
					'speedOut'		:	500
				});
			}
		});

		return false;
	});


	// Onglet galerie de photos ...
	$("#bat, #rou, #ant, #sol").click(function(){
		var MyIdPhoto = $(this).attr('id');
		$('#bat, #rou, #ant, #sol').removeClass("on");
		$("#"+MyIdPhoto).addClass(" on");
		$("#ColorToChange, #Contain2Change, #2Change4pict").removeClass();
		$("#ColorToChange, #Contain2Change, #2Change4pict").addClass(MyIdPhoto);
		$("#Data2Change").val(MyIdPhoto);
		$("#refGamme").val(MyIdPhoto);
		$("#form_foto").submit();

		return false;
	});

	$("#form_foto").submit();

	/////////////////////////////////////////////////////////////////////////
	//                     Slide Fabricant de peinture
	/////////////////////////////////////////////////////////////////////////
	$('#slide-langue div').cycle({
        speed:700,
        timeout:1000
    });

	/////////////////////////////////////////////////////////////////////////
	//                        Execution de l'ancre
	/////////////////////////////////////////////////////////////////////////
	if($("#center").hasClass('include/inc-contact') || $("#center").hasClass('include/inc-cgu') || $("#center").hasClass('include/inc-products') || $("#center").hasClass('include/inc-company') || $("#center").hasClass('include/inc-dev_durable') || $("#center").hasClass('include/inc-batiment') || $("#center").hasClass('include/inc-sol') || $("#center").hasClass('include/inc-antico') || $("#center").hasClass('include/inc-photos') || $("#center").hasClass('include/inc-routiere') || $("#center").hasClass('include/inc-export')){
		hauteur = $("#nav").offset().top;
		$('html,body').animate({scrollTop:hauteur},1);
	}

	/////////////////////////////////////////////////////////////////////////
	//                        Rollover des boutons
	/////////////////////////////////////////////////////////////////////////
    if($("#center").hasClass('batiment') || $("#center").hasClass('sol') || $("#center").hasClass('antico') || $("#center").hasClass('routiere'))
    {
        $("#nav a:not(.on)").hoverAd({
            callbackFadeIn:function (elmt){
                elmt.find("img").attr("src",function(){
                    var tmp = $(this).attr("src").split("/");
                    tmp[tmp.length-1] = 'on-' + tmp[tmp.length-1];
                    return tmp.join('/');
                });
            },
            callbackFadeOut:function(elmt){
                elmt.find("img").attr("src",function(){
                    var tmp = $(this).attr("src").split("/");
                    tmp[tmp.length-1] = tmp[tmp.length-1].replace("on-","");
                    return tmp.join('/');
                });
            }
        });
    }
    else
    {
		$("#link_bat").hover(function(){var newSrc = '/img/structure/on-back_bat.png';$("#img_bat").attr('src', newSrc);},function(){var newSrc	= '/img/structure/back_bat.png';$("#img_bat").attr('src', newSrc);});
		$("#link_rou").hover(function(){var newSrc = '/img/structure/on-back_rout.png';$("#img_rou").attr('src', newSrc);},function(){var newSrc	= '/img/structure/back_rout.png';$("#img_rou").attr('src', newSrc);});
		$("#link_ant").hover(function(){var newSrc = '/img/structure/on-back_antico.png';$("#img_ant").attr('src', newSrc);},function(){var newSrc	= '/img/structure/back_antico.png';$("#img_ant").attr('src', newSrc);});
		$("#link_sol").hover(function(){var newSrc = '/img/structure/on-back_sol.png';$("#img_sol").attr('src', newSrc);},function(){var newSrc	= '/img/structure/back_sol.png';$("#img_sol").attr('src', newSrc);});

	}
});

//**************************************************************************************
//	                            Rollover des boutons suite ...
//**************************************************************************************
(function($){
    $.fn.hoverAd = function(options) {
        var defaults = {
            fadeTransi:0.4,
            speed: "slow",
            callbackFadeIn:"",
            callbackFadeOut:""
        };

        var opts = $.extend(defaults, options);

        $(this).fadeTo(0, opts.fadeTransi);

        $(this).live('mouseover',function(){
            opts.callbackFadeIn($(this));
            $(this).stop().fadeTo(0, 1);
        });
        $(this).live('mouseout',function(){
            opts.callbackFadeOut($(this));
            $(this).stop().fadeTo(opts.speed, opts.fadeTransi);
        });

        return $(this);
    };
})(jQuery);


