$(document).ready(function() {
	function escapeHtml(s) {
		return s.replace('&', '&amp').
		         replace('<', '&lt;').
		         replace('>', '&gt;').
		         replace('"', '&quot;');
	}
	function renderTemplate(tmpl, ctx, escape) {
		escape = escape || escapeHtml;
		return tmpl.replace(/\{\{\s*([^\s}]+)\s*\}\}/g, function(s) {
			var m = s.match(/\{\{\s*([^\s}]+)\s*\}\}/);
			return (ctx[m[1]] != undefined ? escape(ctx[m[1]]) : m[0]);
		});
	}
	$('#clients a').each(function() {
		var img = $(this).find('img')[0];
		$(this).qtip({
			content: renderTemplate(
				'<div class="title">{{ title }}</div>' +
				'<div class="description">{{ description }}</div>', {
					title: img.alt,
					description: img.title
				}
			),
			style: {
				name: 'dark',
			},
			position: {
				corner: {
					target: 'topMiddle',
					tooltip: 'bottomMiddle'
				}
			},
			show: 'mouseover',
			hide: 'mouseout'
		});
		img.alt = img.title = '';
	});
});
