/*
 * 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 = 3;
	yOffset = 3;

	// these 2 variable determine popup's distance from the cursor
	// you might want to adjust to get the right result

	/* END CONFIG */
	xOffset = 3;
	yOffset = 3;

	// these 2 variable determine popup's distance from the cursor
	// you might want to adjust to get the right result

	/* END CONFIG */
	$("a.previewtip").hover(function(e) {
				this.t = this.title;
				this.title = "";
				var c = (this.t != "") ? "<br/>" + this.t : "";
				var preview_link = $('#' + this.id + '-url')[0];
				$("body").append("<p id='previewtip'><img src='" + this.href + "' alt='Loading Image Preview' />" + c + "</p>");
				$("#previewtip")
						.css("top", (e.pageY - xOffset) + "px")
						.css("left", (e.pageX + yOffset) + "px")
						.css("z-index", "3")
						.fadeIn("fast");
			},
			function() {
				if (this.t) {
					this.title = this.t;
				}
				$("#previewtip").remove();
			});
	$("a.previewtip").mousemove(function(e) {
		var posY;

		if (e.pageY - $(window).scrollTop() + $('#previewtip').height() >= $(window).height()) {
			posY = $(window).height() + $(window).scrollTop() - $('#previewtip').height() - 15;
		} else {
			posY = e.pageY - 15;
		}
		$("#previewtip")
				.css("top", (posY) + "px")
				.css("left", (e.pageX + 15) + "px");
	});
	/*
	 $("a.previewtip").hover(function(e){
	 this.t = this.title;
	 this.title = "";
	 var c = (this.t != "") ? "<br/>" + this.t : "";
	 $("body").append("<p id='previewtip'><img src='"+ this.href +"' alt='Image previewtip' />"+ c +"</p>");
	 /*
	 $("#previewtip")
	 .css("left",(e.pageX + xOffset) + "px")
	 .css("top",(e.pageY - $("#previewtip").height()) + "px");
	 yOffset = $("#previewtip").height();

	 $("#previewtip")
	 .css("top",(e.pageY - xOffset) + "px")
	 .css("left",(e.pageX + yOffset) + "px")
	 .fadeIn("fast");

	 },
	 function(){
	 this.title = this.t;
	 $("#previewtip").remove();
	 });
	 $("a.previewtip").mousemove(function(e){
	 $("#previewtip")
	 .css("left",(e.pageX + xOffset) + "px")
	 .css("top",(e.pageY - $("#previewtip").height()) + "px");
	 yOffset = $("#previewtip").height();
	 /*
	 .css("top",(e.pageY - xOffset) + "px")
	 .css("left",(e.pageX + yOffset) + "px");

	 });		 */
};

this.imagePreview2 = function() {
	/* CONFIG */

	xOffset = 3;
	yOffset = 3;

	$("img.previewtip").hover(function(e) {
				this.t = this.title;
				this.title = "";
				var c = (this.t != "") ? "<br/>" + this.t : "";
				$("body").append("<p id='previewtip'><img src='" + this.src + "' alt='Image previewtip' />" + c + "</p>");
				$("#previewtip")
						.css("top", (e.pageY - xOffset) + "px")
						.css("left", (e.pageX + yOffset) + "px")
						.fadeIn("fast");
			},
			function() {
				this.title = this.t;
				$("#previewtip").remove();
			});
	$("img.previewtip").mousemove(function(e) {
		$("#previewtip")
				.css("left", (e.pageX + xOffset) + "px")
				.css("top", (e.pageY - $("#previewtip").height()) + "px");
		yOffset = $("#previewtip").height();
	});
};

// starting the script on page load
$(document).ready(function() {
	imagePreview();
	imagePreview2();
	$("a.level1-a").hover(function() {
		var el = $(this);
		var currentId = $(this).attr('id');
		var showID = currentId + "show";

		var timeoutId = setTimeout(function() {

			$('.listHolder').each(function(index) {
				var elementId = $(this).attr('id');
				if (elementId == showID) {
					$("#" + showID).show();
				}
				else {
					$('#' + elementId).hide(1000);
				}
			});

			$("#" + showID).show();
			//alert(showID);

		}, 500);

	});

});



