$().ready(function() {
	
	$("a[rel^='prettyPhoto']").prettyPhoto({
		theme: 'pp_default', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
		overlay_gallery: false,
		deeplinking: false
		// social_tools: false
	});
	// initiate slide
	$('#coda-slider-1').codaSlider();
	// allow analytics to track external links
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	// use jQuery to call the Google Analytics JavaScript
	$.getScript(gaJsHost + "google-analytics.com/ga.js", function(){
		// tell Analytics about the current page load using standard _trackPageview method
		try {
			var pageTracker = _gat._getTracker("<?php echo $analytics; ?>");
			pageTracker._trackPageview();
		} catch(err) {}
		// loop though each anchor element
		$('a[href]').each(function(){
			
			var href = $(this).attr('href');
			var filetypes = /\.(zip|exe|pdf|doc*|xls*|ppt*|mp3|jpg)$/i;
			
			// check for links starting with http or https, making sure that links to our own domain are excluded
			if ((href.match(/^https?\:/i)) && (!href.match(document.domain))){
				$(this).click(function() {
					var extLink = href.replace(/^https?\:\/\//i, '');
					pageTracker._trackEvent('External', 'Click', extLink);
				});
			}
			// check for links with file extension that match the filetypes regular expression:
			else if (href.match(filetypes)){
				$(this).click(function() {
 					var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
					var filePath = href.replace(/^https?\:\/\/(www.)mydomain\.com\//i, '');
					pageTracker._trackEvent('Download', 'Click - ' + extension, filePath);
				});
			}
		});
	})
	
	// Fading buttons
	$('.playbutton,.readbutton,.playbuttonbig').append('<span class="hover"></span>').each(function () {
		var $span = $('> span.hover', this).css('opacity', 0);
	 	$(this).hover(function () {
	 $span.stop().fadeTo(500, 1);
	 }, function () {
	 	$span.stop().fadeTo(500, 0);
	 });
	});
});

// GA outbound links http://iso-100.com/blog/post/updated-script-for-tracking-outbound-links-in-google-analytics-with-jquery/
$('a:not(.popupwindow)').filter(function() {
	var theHref = this;
	if (theHref.hostname && theHref.hostname !== location.hostname) {
		$(theHref).not(".noAutoIcon").addClass("offSite");
		$(theHref).not(".noAutoLink").attr('target','_blank').bind('click keypress', function(event) {
			var code=event.charCode || event.keyCode;
			if (!code || (code && code == 13)) {
				if(pageTracker){
					var fixedLink = this.href;
					fixedLink = fixedLink.replace(/https?:\/\/(.*)/,"$1");
					fixedLink = '/outgoing/' + fixedLink;
					pageTracker._trackPageview(fixedLink);
				};
			};
		});
	};
});
