
// starting the script on page load
$(document).ready(function(){
	imagePreview();
	screenshotPreview();
	logoDfnPreview();
	titleTooltips();
	tooltip();
	// enCours();
});





this.enCours = function(){
	//prepend span tag to H1
	$("h1").prepend("<span class='gradient'></span>");
	$("h2").prepend("<span class='gradient'></span>");
	$("h3").prepend("<span class='gradient'></span>");
	$("h4").prepend("<span class='gradient'></span>");

	//add image for external links, for new window
	$("a[href^='http://']").not("a[href^="+document.domain+"]").not(":has(img)").each(function(i){
		$(this).after("&nbsp;<a href='"+$(this).attr("href")+"' onclick='window.open(this.href); return false;' style='border: none;'><img src='/img/icons/link_go.png' alt='' title='Ouvrir ce lien dans une nouvelle fenÃƒÂªtre' /></a>");
	});
}


/* Dfn preview  */
this.logoDfnPreview = function(){
	/* CONFIG */
		xOffset = 210;
		yOffset = 410;
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result

	/* END CONFIG */
	$("#logo dfn.screenshot").hover(function(e){
		this.t = this.title;
		this.title = "";
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='logoDfnScreenshot'><img src='/img/LOGOS/ailurus_couple.jpg' alt='Un couple de panda roux' /><img src='/img/LOGOS/ailurus_dort_au_soleil.jpg' alt='Un panda roux qui dort au soleil' />"+ c +"</p>");
		$("#logoDfnScreenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.css("z-index", "200")
			.css("font-size", ".8em")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;
		$("#logoDfnScreenshot").remove();
    });
	$("dfn.screenshot").mousemove(function(e){
		$("#logoDfnScreenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
};

/* Tooltips */
this.titleTooltips = function(){
	/* CONFIG */
		xOffset = 10;
		yOffset = 20;

		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
	/* END CONFIG */
	$(".tooltip").hover(function(e){
		this.t = this.title;
		this.title = "";
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;
		$("#tooltip").remove();
    });
	$(".tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
};



/*
 * Image preview script
 * powered by jQuery (http://www.jquery.com)
 *
 * written by Alen Grakalic (http://cssglobe.com)
 *
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
this.imagePreview = function(){
	/* CONFIG */

		xOffset = 10;
		yOffset = 30;

		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result

	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Prévisualisation de l\'image' />"+ c +"</p>");
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;
		$("#preview").remove();
    });
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
};

/* Url preview script  */
this.screenshotPreview = function(){
	/* CONFIG */

		xOffset = 10;
		yOffset = 30;

		// 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='Prévisualisation du site' />"+ 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");
	});
};

/* A href Tooltip */
this.tooltip = function(){
	/* CONFIG */
		xOffset = 10;
		yOffset = 20;
		$("a")

			.each(function(){
			$("a")
				.not( $("#logo a") )
				.not( $("#headlinks a") )
				.addClass("tooltip");
		})

		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
	/* END CONFIG */
	$("a.tooltip").hover(function(e){
		this.t = this.title;
		this.title = "";
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.css("max-width", "400px")
			.css("text-align", "justify")
			.css("background-image", "url(/img/ICONS/link_go.png)")
			.css("background-position", "5px 40%")
			.css("background-repeat", "no-repeat")
			.css("padding-left", "26px")
			.css("height", "auto")
			.css("min-height", "16px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;
		$("#tooltip").remove();
    });
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
};

