/* JavaScript Document

--------------------------------
GlobalAuto
(c) Adam Kudrna 2011
Last edited: 2011-04-01
--------------------------------

*/



// Initialize
$(document).ready(function () {

	// Load Google Analytics
	$.ga.load('UA-13223783-1');

	// Thumbnail link URL rape (n) Fuj!
	$('div.magcat1 a[rel^="singlepic"], div.magcat1 a.fancybox img.ngg-singlepic').attr('href', function() {
		return $(this).parent().parent().find('h2.headline a').attr('href');
	}).removeClass('fancybox');

	// External Links - Not used because WP generates all URLs absolute (w)
	/*$('a[href^="http://"]').click(function() {
		this.target = '_blank';
		$.ga.trackEvent('External websites', 'Gone to', this.href);
	});*/

	// E-mails
	$('a[href^="mailto:"]').click(function() {
		var email = this.href.match(/[^:]*$/);
		$.ga.trackEvent('E-mail addresses', 'Write a message', email);
		
		return true;
	});

	// Files
	$('a.file').click(function() {
		this.target = '_blank';

		// Get file extension
		var result = this.href.match(/[^.]*$/);
		var extension = result? result[0].toUpperCase() : 'unknown';

		$.ga.trackEvent('Downloads', extension, this.href);
		
		return true;
	});

	// Fancybox
	$('a.fancybox').fancybox({
		'centerOnScroll'	:	true,
		'hideOnContentClick'	:	true,
		'titleShow'		:	false,
		'titlePosition'		:	'over',
		'overlayColor'		:	'#000',
		'overlayOpacity'	:	0.5,
		'onComplete'		:	function() {

			// Show/hide title on hover
			$("#fancybox-wrap").hover(function() {
				$("#fancybox-title").show();
			}, function() {
				$("#fancybox-title").hide();
			});

			//$.ga.trackEvent('Pictures', 'Show', this.href);
		}
	});

});

