// Scripts that are post loaded (not needed at init time), let them cache by being in this separate file
$(function(){
	// Where the links are located on the header image
	var links = {
				linkedIn: 
					{ 
					href: 'http://se.linkedin.com/in/daniellervik/', 
					xMin: 102, xMax: 354, yMin: 165, yMax: 183 
					},
				mail: 
					{ 
					href: mailAddr, 
					xMin: 102, xMax: 295, yMin: 145, yMax: 163 
					}
				};
	
	// Get key for the coordinates, returns null if not found in links
	function getLinkKey(x, y) {
			var res = null;
			
			$.each(links, function (key, value) {
				if (x > value.xMin && x < value.xMax && 
					y > value.yMin && y < value.yMax) {
					// Match found, return the key!
					return res = key;
				}
			});
			
			return res;
		};
	
	// Check if cursor need to be changed
	$('header img').mousemove(function (e) {
		var x = e.pageX - $(this).offset().left;
		var y = e.pageY - $(this).offset().top;
		
		if (getLinkKey(x, y))
			$("header img").css('cursor','pointer');
		else
			$("header img").css('cursor', 'auto');
	});
	
	// If position over a link coordinate, follow the link
	$('header img').click(function (e) {
		var x = e.pageX - $(this).offset().left;
		var y = e.pageY - $(this).offset().top;
		var key = getLinkKey(x, y);
		
		if (key == 'mail')
			window.location.href = links[key].href;
		else if (key)
			window.open(links[key].href);
	});
	
	// All pdf links should open in new window
	$('#content a, #progress-designs, #daniel-lervik').click(function () {
		window.open($(this).attr('href'));
		
		return false;
	});
	
	// Tooltip for links
	$('a').tipTip({
		defaultPosition: 'top',
		delay: 200,
		maxWidth: 'auto'
	});
});
