$(function(){
	if('_notioDocLoad' in window){   
        window.setTimeout('loadAdditive()',50);
    }else{
       
        $(window).load(function(){   
           window.setTimeout('loadAdditive()',50);
        })
       
     }
})

function loadAdditive(){

$(function(){
	
	var initSlideShow=function(){
		$('#slideshow img[asrc]').each(function(){
			$(this).attr('src',$(this).attr('asrc'));
		})

		$('#gallery img[asrc]').each(function(){
			$(this).attr('src',$(this).attr('asrc'));
		})



		$('#photoShow').cycle(
				{fx:'fade',
				timeout:4000,
				next:$('#slideshow .next'),
				prev:$('#slideshow .prev')				
				}
		)
	}
	
	//mode div avec un callback
	new fadeInAfterLoad({
		element:$('#firstSlide'),
		imagecheck:$('#firstSlide img'),
		animate:{duration:1200,easing:'jswing'},
		callback:initSlideShow
	})
	
	new fadeInAfterLoad({
		element:$('#header'),
		imagecheck:$('#header'),
		animate:{delay:1000,duration:800,easing:'jswing'}		
	})

	$(".scroll").click(function(event){
 		event.preventDefault();
 		var full_url = this.href;
 		var parts = full_url.split("#");
		var trgt = parts[1];
 		var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top;
 		$('html, body').animate(
			 {scrollTop:target_top},
			 {duration: 1000, easing: 'easeOutExpo',  queue: false})
	});


	$('#gallery li').hover(function(){
			$(".caption", this).stop().animate({top:'67px'},{queue:false,duration:400});
		}, function() {
			$(".caption", this).stop().animate({top:'160px'},{queue:false,duration:900});
		}); 		


});	
 }


 


function fadeInAfterLoad(opt){
	this.element=opt.element
	this.imagecheck=opt.imagecheck
	this.animate=opt.animate
	this.callback=('callback' in opt)?opt.callback:function(){};
	this.delay=('delay' in opt.animate)?opt.animate.delay:0;
	
	var meO=this;
	meO.timer=0;
	
	this.element.css({'opacity':0,'visibility':'visible'});
	
	this.fadeMeIn=function(){
		
		meO.element.delay(meO.delay).animate({'opacity':1},meO.animate.duration,meO.animate.easing,meO.callback)
	}
	
	this.imagecheck=function(){
		var allLoaded=true;
		
		var l=meO.imagecheck.length;
		for(var i=0;i<l;i++){
			if(!meO.imagecheck[i].complete){
				allLoaded=false
				break;
			}
		}
		
		
		if(allLoaded){
			window.clearInterval(meO.timer);
			meO.fadeMeIn();
		}
		
	}
	
		
	
	meO.timer=window.setInterval(meO.imagecheck,100)
	
	
}


/**************************************************************

	Script		: Contact Post
	Version		: 1.3.2

**************************************************************/



function sendMyMail(){
	var objInfo={
	'prenom':$('#formcontact_prenom').val(),
	'nom':$('#formcontact_nom').val(),
	'email':$('#formcontact_email').val(),
	'message':$('#formcontact_message').val()
	}
	if(objInfo['email'] =='' || objInfo['email'].indexOf('@')==-1 ){
		
		hightlit2('#formcontact_email');
		return true;
	}
	
 	
	$('#sendingtext').show('drop',{ direction: "right" });
	
	//hide a little bit the post page, to prevent spam.
	var postPage=['/nova_external/con','tact_post','.','php'].join('');
	
	jQuery.ajax({
		url:postPage,
		data:objInfo,
		async:true,
		cache:false,
		success:function(txt){
					if(txt=='ok')
						fadeOutFadeInThanks2();
					else
						alert('an error has occured, please reload this page '+txt)
				},
		error:function(){
			alert('an error has occured, please reload this page')
		},
		type:'POST'	
	})
	


}
function hightlit2(what){
	var box=$(what);
	box.css({position:'relative','left':'0px'});
	
	box.animate({'left':'14px'},{duration:100});
	box.animate({'left':'-14px'},{duration:100});
	box.animate({'left':'14px'},{duration:100});
	box.animate({'left':'-7px'},{duration:100});
	box.animate({'left':'0px'},{duration:100});
	
}





function fadeOutFadeInThanks2(){
	$('#contact_form').fadeOut();
	$('#thanks_form').fadeIn();
}
	


/*************************************************************/


