// JavaScript Document

ShowTooltip = function(e)
{
	var text = $(this).next('.show-tooltip-text');
	if (text.attr('class') != 'show-tooltip-text')
		return false;
     
	text.show()
	.css('top', e.pageY-58)
	.css('left', e.pageX-40);
     
	return false;
}

HideTooltip = function(e)
{
	var text = $(this).next('.show-tooltip-text');
	if (text.attr('class') != 'show-tooltip-text')
		return false;
     
	text.hide();
}
     
SetupTooltips = function()
{
	$('.clickMe')
	.each(function() {
		
		var t = $(this).attr('title');
//		var t = t.replace("[", "<");
//		var t = t.replace("]", ">");
		
		for (i = 0 ; i < 3 ; i++) {
			var t = t.replace("[", "<");
			var t = t.replace("]", ">");
		}
		
		$(this)
		.after($('<span/>')
		.attr('class', 'show-tooltip-text')
		.html(t))
		.attr('title', '');
	})

	.hover(ShowTooltip, HideTooltip);
}


this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 280;
		yOffset = 30;
		
		xOffset2 = 280;
		yOffset2 = -645;
		
		xOffset3 = 280;
		yOffset3 = -120;

		xOffset4 = 280;
		yOffset4 = -645;
		
	$("a.preview, #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.rel +"' alt='Image preview' />"+ 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");
	});	
	
	
	
	$("a.preview2").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview2'><img src='"+ this.rel +"' alt='Image preview' />"+ c +"</p>");								 
		$("#preview2")
			.css("top",(e.pageY - xOffset2) + "px")
			.css("left",(e.pageX + yOffset2) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview2").remove();
    });	
	$("a.preview2").mousemove(function(e){
		$("#preview2")
			.css("top",(e.pageY - xOffset2) + "px")
			.css("left",(e.pageX + yOffset2) + "px");
	});	
	
	
	$("a.preview3").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview3'><img src='"+ this.rel +"' alt='Image preview' />"+ c +"</p>");								 
		$("#preview3")
			.css("top",(e.pageY - xOffset3) + "px")
			.css("left",(e.pageX + yOffset3) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview3").remove();
    });	
	$("a.preview3").mousemove(function(e){
		$("#preview3")
			.css("top",(e.pageY - xOffset3) + "px")
			.css("left",(e.pageX + yOffset3) + "px");
	});	
	
	
	$("a.preview4").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview4'><img src='"+ this.rel +"' alt='Image preview' />"+ c +"</p>");								 
		$("#preview4")
			.css("top",(e.pageY - xOffset4) + "px")
			.css("left",(e.pageX + yOffset4) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview4").remove();
    });	
	$("a.preview4").mousemove(function(e){
		$("#preview4")
			.css("top",(e.pageY - xOffset4) + "px")
			.css("left",(e.pageX + yOffset4) + "px");
	});	
	
};


// starting the script on page load
$(document).ready(function(){
	imagePreview();
    SetupTooltips();
});
