$(document).ready(function(){
	
	//////////////////////////////////////////////////////////////////////////////////////
	//						Function d'agrandissement des images 						//
	//////////////////////////////////////////////////////////////////////////////////////
	// jQuery(function()
	// {
		// jQuery.fn.zoomImg = function(options){
			// var i=0;
			// var setting = jQuery.extend({
				
				// initWidth:100,
				
				// finalWidth:'100%',
				
				// marginLeftGo:0,
				
				// marginLeftReturn:0,
				
				// marginLeftFinal:0,
				
				// marginTopGo:0,
				
				// marginTopFinal:0,
				
				// marginTopCSS:"auto",
				
				// clickBody:true,
				
				// speed:300
				
				
			// },options);
			
			
			// function zoomPlus(options)
			// {
				
				// Div Parent //
				// parentDiv.css({'width':parentDiv.width(),'height':parentDiv.height()});
				
				// Body //
				// $('body').attr('id',elem.attr('id'));
				
				// Margin top // 1 = Firefox ; 2 = Internet Exploere ; 3 = Safari/Chrome
				// marginTopGo = 0;
				// marginTopGo = jQuery.browser.mozilla && setting.marginTopGo ? parseFloat($('.caroussel').scrollTop() + 400 - 128 * (elem.attr('id').substring(7)-1)) : marginTopGo;	
				// marginTopGo = jQuery.browser.msie && setting.marginTopGo ? parseFloat($('.caroussel').scrollTop()+400 - 128 * (elem.attr('id').substring(7)-1)) : marginTopGo;	
				// marginTopGo = jQuery.browser.safari && setting.marginTopGo ? parseFloat($('.caroussel').scrollTop()*-1 +400 - 128 * (elem.attr('id').substring(7)-1)) : marginTopGo;	

				// Animation //
				// elem
					// .css({ 'position':'absolute','z-index':i})
					// .animate({ 'width':setting.finalWidth,'margin-left':setting.marginLeftGo, 'margin-top':marginTopGo},setting.speed,function(){
						// $(this).addClass('imgout');//.attr('title',setting.initWidth);
						
					// });
				// i++;
			// }
			// function zoomMoins(options)
			// {
				// Margin top //
				// setting.marginTopFinal = marginTopGo =! 0 ? 0 : setting.marginTopFinal ;
				
				// Animation //
				// elem
					// .animate({ 'width':setting.initWidth, 'margin-left':setting.marginLeftReturn, 'margin-top':setting.marginTopFinal },setting.speed,function(){
						// $(this).css({ 'position':'relative','margin-top': setting.marginTopCSS})
						// if(setting.marginLeftFinal != 0)
							// $(this).css({'margin':setting.marginLeftFinal}).removeClass('imgout');;
							
					// })
				
			// }
			
			// $(this).bind('click', function (options) {
				
				// elem = $(this);
				// parentDiv = elem.parent();
				// widthElem = elem.width();
				// marginElem = elem.css('margin');
				
				// if(widthElem <= setting.finalWidth && widthElem > setting.initWidth)
					// zoomMoins(options);
	
				// else
					// zoomPlus(options);
					
				// if($('img.imgout').length >= 1)
					// zoomMoins(options);
            // });
			
			// $('#'+$(this).attr('id')).bind('click',function(options){
				// alert($(this).attr('id'))
				// elem = $('img.imgout');
				
				// if(elem.length >= 1)
				// {
					// setting.initWidth = $(elem).attr('title');
					// zoomMoins();
				// }
			
			// });
		// }
	// });


	// $('img.pres').zoomImg({
		
		// initWidth:60,
		// finalWidth:400,
		// marginTopCSS:"9px",
		// marginLeftFinal:"auto"
		
	// });		

	// $('img.galerie').zoomImg({
			
		// initWidth:170,
		// finalWidth:642,
		// marginLeftFinal:'auto',
		// marginLeftReturn:'19px',
		// marginLeftGo:'200px',
		// marginTopGo:1
		
	// });	
	// $('img.page').zoomImg({
			
		// initWidth:160,
		// finalWidth:400,
		// marginLeftFinal:'auto',
		// marginLeftReturn:'5px'
		
	// });	

	
	
	
	

	$('img.pres,img.galerie,img.page').click(function(){
	
		$('.bloc_flash').hide();
		
		var imgAlt = $(this).attr('alt');
		
		var imgSrc = $(this).attr('src').match(/vignette/) ? "./logiciel-immobilier/produit/"+$(this).attr('src').substring(31) : $(this).attr('src');
		
		var img = new Image();
		
			$("#loader").fadeIn(500,function(){
			
				$(img).load(function(){
			
					$('.imageloader').html('<img src="'+imgSrc+'" alt="'+imgAlt+'"/>').css("opacity",0);
					
					var heightImg = $('.imageloader img').height(),
						widthImg = $('.imageloader img').width();
					
					if(	heightImg >= $(window).height())heightImg = $(window).height()-100;
					widthImg = (heightImg/$('.imageloader img').height())* $('.imageloader img').width();
					
					$('.imageloader img').width(widthImg).height(heightImg);
					
					$('.imageloader')
						.animate({'width':widthImg,'opacity':1})
						.animate({'height':heightImg+25})
						.css({'border':'3px solid #FFF',"top": ( $(window).height() - heightImg ) / 2,'right': ( $(window).width() - widthImg ) / 2})
						.append("<br/><div style='background:#FFFFFF;height:25px;'><div class='fermer'><b>Fermer</b></div></div>");

				}).attr("src",imgSrc);
				
			});
	});
	
	$("#loader").click(function(){
		
		$(this).fadeOut(500,function(){$('.bloc_flash').show();});
		$(".imageloader").html("").animate({width:10,height:10},500);
		// $('body').css('overflow','auto');
		
		
	});
	
	
	// if($.browser.msie)
	// {
		// var marginleft_retour = 11;
		// var marginleft_aller = 90;
		// var marginleft_css = 0;
	// }
	// else
	// {
		// var marginleft_retour = 19;
		// var marginleft_aller = 170;
		// var marginleft_css = 19;
	// }	
	
	// var i = 0;
	
	// $('img.galerie').click(function(){
		
		// var pages = $('.caroussel').scrollTop();
		// var margintop_css = 0;
		
		// if($.browser.safari) 	
		// {
			// var margintop = parseFloat((pages * -1) + 400 - 128 * ($(this).attr('id').substring(7)-1));
			// margintop_css = -pages;
		// }
		// if($.browser.version != 8.0)	var margintop = parseFloat(pages + 400 - 128 * ($(this).attr('id').substring(7)-1));
		// else							
		// {
			// var margintop = parseFloat(400 - 128 * ($(this).attr('id').substring(7)-1));
			// margintop_css = -pages;
		// }
		
		// if($(this).width()<= 642 && $(this).width()> 170)
		// {

			// $(this)
				// .animate({ 'width':170,'margin-left':marginleft_retour,'margin-top':margintop_css },300,function(){
					// $(this).css({ 'position':'relative','z-index':0,'margin-top':0,'margin-left':marginleft_css })
				// })
				// .removeClass('imgout');
		// }	
		// else
		// {

			// $(this)
				// .css({ 'position':'absolute','z-index':i,'margin-left':11,'margin-top':margintop_css })
				// .animate({ 'width':642,'margin-left':marginleft_aller,'margin-top':margintop },300,function(){$(this).addClass('imgout');})
				
			
			// $('img.detail_image[alt!='+$(this).attr('id')+']').each(function(){
				
				// if($(this).width()<= 642 && $(this).width() > 170)
				// {	
					// $(this)
						// .animate({ 'width':137,'margin-left':marginleft_retour,'margin-top':margintop_css },300,function(){
							// $(this).css({ 'position':'relative','z-index':0,'margin-top':0,'margin-left':marginleft_css })
						// })
						// .removeClass('imgout');
				// }
			// });
			
		// }
		// i++;
	// });	
	
	 // $('body').click(function(){
	 
		// $('img.imgout').each(function(){
			
			// var pages = $('.caroussel').scrollTop();
			
			// if($.browser.version == 8.0 || $.browser.safari )
				// var margintop_css = -pages;
			// else
				// var margintop_css = 0;
			
			// $(this)
				// .animate({'width':170,'margin-left':marginleft_retour,'margin-top':margintop_css},300,function(){
					// $(this).css({'position':'relative','z-index':0,'margin-top':0,'margin-left':marginleft_css})
					
				// }).removeClass('imgout');
			
		// });
	 
	 // });

	//////////////////////////////////////////////////////////////////////////////////////
	//								Function caroussel		 							//
	//////////////////////////////////////////////////////////////////////////////////////
	$(".fleche").click(function(){

		var ul = $(this).parent().find('ul'),
			div = $('.caroussel');
			sens = $(this).attr('id').substring(5) < 2 ? -1 : 1;
		
		div.filter(':not(:animated)').animate({scrollTop : '+='+ sens*810},1500);
		
	});
	
	setInterval(function () {
		var sens = 1;
			sens = $('.caroussel_text').scrollTop() <= 0 ? 1 : -1;
		
			$('.caroussel_text').animate({scrollTop : '+='+ sens*390},10000);
    }, 150);

	
	//////////////////////////////////////////////////////////////////////////////////////
	//								Function Verif Form Contact							//
	//////////////////////////////////////////////////////////////////////////////////////
	$('.submit_contact').click(function(){
		
		var not = 0;
		var required = 0;

		$('input[name*=required_contact],textarea[name*=required_contact]').each(function(){
			
			if($(this).val() == "")
			{
				$(this).css({ 'backgroundColor' : '#EE0000', 'border':'1px solid #CCCCCC'});
				not++;
			}
			else
			{
				$(this).css({ 'backgroundColor' : '#FFFFFF', 'border':'1px solid #CCCCCC'});
				not = 0;
			}
			required++;
		});
		
		if(!$('input[name=required_contact_email]').val().match(/\b[\w\.-]+@[\w\.-]+\.\w{2,4}\b/i))
		{
			$('.form_contact:not(:contains(Email non valide))').append('Email non valide<br/>');
			$('input[name=required_contact_email]').css({ 'backgroundColor' : '#EE0000', 'border':'1px solid #CCCCCC'});
			not++;
		}
		else
			$('span').not('.error');
		
		if(not > 0) $('.form_contact:not(:contains(Veuillez remplir correctement le formulaire))').append('Veuillez remplir correctement le formulaire');
		
		else
			$('#form_contact').submit();
	});
	
	$('input[name*=required_contact],textarea[name*=required_contact]').keyup(function(){
	
		$(this).css({ 'backgroundColor' : '#FFFFFF', 'border':'1px solid #CCCCCC'});
		
	});
	
	
	
	//////////////////////////////////////////////////////////////////////////////////////
	//								Function Verif Form Contact							//
	//////////////////////////////////////////////////////////////////////////////////////

	var height = 0;
	
	$('a.menu')
	.mouseover(function(){
		
		var id = this.id;
	
		
		$('#'+id+'s').css('height',0).animate({'height':150},{duration: 100, queue: false}).show();
		$('#'+id+'d').show();
		
	}).mouseout(function(){
	
		var id = this.id;
	
		$('#'+id+'s').animate({'height':0},{duration: 200, queue: false,complete:function(){
			$(this).hide();
			$('#'+id+'d').hide();
		}});

	});
	$('div.sousmenu')
	.mouseover(function(){
		
		$(this).stop();
	
	})
	.mouseout(function(){
		$(this).animate({'height':0},{duration: 200, queue: false,complete:function(){
			$(this).hide();
			$('.divespace').hide();
		}});
	});	
	$('.divespace')
	.mouseover(function(){
		
		$('div.sousmenu').stop();
	});	


	
});