this.screenshotPreview = function(){	
	/* CONFIG */
		
		xOffset = 260;
		yOffset = 60;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.screenshot").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");								 
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#screenshot").remove();
    });	
	$("a.screenshot").mousemove(function(e){
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};
function effacer (id_formulaire) {
  $(':input','#'+id_formulaire)
   .not(':button, :submit, :reset, :hidden')
   .val('')
   .removeAttr('checked')
   .removeAttr('selected');
}
$(document).ready(function() {
						   screenshotPreview();


//select all the a tag with name equal to modal
	$('a[name=modal]').each(function () {
    $(this).click(function(e) {
        //Cancel the link behavior
        e.preventDefault();
        //Get the A tag
        var id = $(this).attr('href');
		var page = $(this).attr('id');
     
        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();
     
        //Set height and width to mask to fill up the whole screen
        $('#mask').css({'width':maskWidth,'height':maskHeight});
         
        //transition effect    
        $('#mask').fadeIn(1000);   
        $('#mask').fadeTo("slow",0.8); 
     
        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();
               
        //Set the popup window to center
        $(id).css('top',  winH/2-$(id).height()/2);
        $(id).css('left', winW/2-$(id).width()/2);
     
        //transition effect
        $(id).fadeIn(2000);
     	$('.window').load(page+".php");
    });
     });
    //if close button is clicked
    $('.window .close').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
        $('#mask, .window').hide();
    });    
     
    //if mask is clicked
    $('#mask').click(function () {
        $(this).hide();
        $('.window').hide();
    }); 
	
	///////////////// toplink
	    $('body').prepend('<a href="#marge" class="top_link" title="Revenir en haut de page">Haut</a>');  
    $('.top_link').css({  
        'position'              :   'fixed',  
        'right'                 :   '20px',  
        'bottom'                :   '50px',  
        'display'               :   'none',  
        'padding'               :   '15px',  
		'padding-left'               :   '30px',
        'background'            :   '#fff',  
		'background-image'            :   'url(img/arrow_up3.png)',
		'background-repeat'            :   'no-repeat',
        '-moz-border-radius'    :   '5px',  
        '-webkit-border-radius' :   '5px',  
        'border-radius'         :   '5px',  
		'border'         :   '1px solid #3399cc',
        'opacity'               :   '0.9',  
        'z-index'               :   '2000'  
    });  
	    $(window).scroll(function(){  
        posScroll = $(document).scrollTop();  
        if(posScroll >=350)  
            $('.top_link').fadeIn(600);  
        else  
            $('.top_link').fadeOut(600);  
    });  
		function scrollTo(id) {
			var offset2 = $("#"+id).offset();
		$('html, body').animate({scrollTop: offset2.top}, 1000) ;
		
		return false;
	}

	
	$(".top_link").click(function(){
		scrollTo('top');
		return false;
	});
	////////////// form
	
	$("#contactForm").submit(function() {
 s = $("#contactForm").serialize(); 
    $.ajax({ 
        type: "POST", 
        data: s, 
        url: "contact_env.php", 
        success: function(retour){ 
		var strcheck= new RegExp("envoy", "g");
			var strtest= strcheck.test(retour,"envoy")
			if (strtest === true){
            effacer('contactForm');
			$("#rec").hide();
			}
			$("#recipient").empty().append(retour);
        } 
    }); 
    return false; 
});

});

