$(document).ready(function(){
    $("#content p:first:not(body.search p)").addClass("intro");
    
    
    //Define action and string to send to GA
    var gaCategories = [
    {
	act:'Download',
	cat:'.pdf'
    },

    {
	act:'Download',
	cat:'.xls'
    },

    {
	act:'Download',
	cat:'.doc'
    },

    {
	act:'Click',
	cat:'mailto:'
    }
    ];

    //Loop through download categories and get tracking info
    $.each(gaCategories, function(i,val){

	//When link contains category
	$("a[href*=" + val.cat + "]").click(function(e){

	    //Stop the link returning while we gather tracking information
	    e.preventDefault();

	    //Store tracking details
	    var category = val.cat;
	    var action = val.act;
	    var href = $(this).attr("href");

	    //Pass these details to our google tracking code
	    gaEventTracking(category, action, href, function(){
		_gaq.push(['_trackPageview', '/' + action + '/' + category + '/' + href]);
	    });

	});

    });

    function gaEventTracking(category, action, href, extracb) {

	//Push the event to Google Analytics
	_gaq.push(['_trackEvent', category, action, href]);
	
	// Run something else, like track pageview if set
	if( 'function' == typeof(extracb) ){
	    extracb();
	}

	//Return the original href
	window.location = href;

    };
    
    
    
});		
