/**
 * tooltips
 */
 
 /**
  * tooltips (error boxes) for label-tags, if they have a class named 'error'
  * required:
  * + jquery.js
  * + jquery.qtip.js
  */

(function($) {
	//function, to be able to reload tooltips live with acceptable performance.
	$.fn.qtipErrorTooltip = function(){
		$("div[id$=errorTooltip]").remove();
		$("label[class*='error'][title]").each(function(){
			var right = $(this).is("label[class*='errorRight'][title]");
			$(this).qtip({
					id: "errorTooltip",
					style: {
						tip: {
							corner: right ? "leftBottom" : "rightBottom",
							width: 10,
							height: 10
						}
					},
					position: {
						adjust: {
							x: right ? 10 : -10,
							y: 0
						},
						at: right ? "left top" : "right top",
						my: right ? "left bottom" : "right bottom",
						target: right ? "mouse" : false
					},
					show: {
						delay: 0
					},
					content: {
						title: {
							text: "Fehler"
						}
					}
				})
				.mouseover(function(){
				$(this).css('cursor', 'help');
			});
		});
	};
})(jQuery);

$(document).ready(function(){
	$.fn.qtipErrorTooltip();
});

(function($) {
	//function, to be able to reload tooltips live with acceptable performance.
	$.fn.qtipFileList = function(){
		$("div[id$=fileListTooltip]").remove();
		$("ul.fileList li[title], a.tooltip[title]").each(function(){
			$(this).qtip({
				id : 'fileListTooltip',
				style: {
					tip: {
						corner: "bottomLeft",
						width: 10,
						height: 10
					}
				},
				position: {
					target: "mouse",
					adjust: {
						x: 15,
						y: 5
					},
					at: "bottom left",
					my: "bottom left"
				},
				show: {
					delay: 0
				},
				content: {
					title: $(this).attr('title').split('\n',2)[0],
					text: $(this).attr('title').split('\n',2)[1]
				}
			})
			.attr("title","");
		});
	};
})(jQuery);

$(document).ready(function(){
	$.fn.qtipFileList();
});

$(document).ready(function(){
	$("img.tooltip[title]").each(function(){
		$(this).qtip({
			id: "imgTooltip",
			style: {
				tip: {
					corner: $(this).hasClass('tooltipLeft') ? 'bottomRight' : 'bottomLeft',
					width: 10,
					height: 10
				}
			},
			position: {
				target: "mouse",
				adjust: $(this).hasClass('tooltipLeft') ? {x: -5, y: -5} : {x: 5, y: 5},
				at: $(this).hasClass('tooltipLeft') ? 'bottom right' : 'bottom left',
				my: $(this).hasClass('tooltipLeft') ? 'bottom right' : 'bottom left'
			},
			show: {
				delay: 0
			},
			content: {
				title: $(this).attr('title').split('\n',2)[0],
				text: $(this).attr('title').split('\n',2)[1]
			}
		})
		.attr("title","");
	});
});

