(function ($) {

    /*!
    Pollinate Analytics Tracking
    Created: 1/17/2012
    Last Updated: 1/18/2012
    Credit to Robert Stevenson-Leggett @ Building Blocks UK for creating the 
    Google Analytics Event Tracking jQuery Plugin on which this is based.

    This plugin will do the following:
    - Track events if data attribute specified by the trackAttribute is present
    - Track downloads as pageviews
    - Track exits to external sites
    
    Usage:
    
    $(function () {
    //track all links with trackAttribute, downloads, and exits
    $("a").gaTrack({
    trackAttribute: 'data-ga-track',
    categoryAttribute: 'data-ga-category',
    actionAttribute: 'data-ga-action',
    trackDownloads: true,
    trackExits: true
    });
    });
    */

    //Wrap the track event function
    var trackEvent = function (category, action, label, value) {
        _gaq.push(['_trackEvent', category, action, label, value]);
    };

    //Wrap the track pageview function
    var trackPageView = function (href) {
        _gaq.push(['_trackPageview', href]);
    };

    //Check if link is external
    var isExternal = function (url) {
        var match = url.match(/^([^:\/?#]+:)?(?:\/\/([^\/?#]*))?([^?#]+)?(\?[^#]*)?(#.*)?/);
        if (typeof match[1] === "string" && match[1].length > 0 && match[1].toLowerCase() !== location.protocol) {
            return true;
        }
        if (typeof match[2] === "string" && match[2].length > 0 && match[2].replace(new RegExp(":(" + {
            "http:": 80,
            "https:": 443
        }[location.protocol] + ")?$"), "") !== location.host) {
            return true;
        }
        return false;
    };

    var defaultOptions = {
        //Track downloads of non HTML files.  Note, selector must be broad enough to include these link (i.e. $('a').gaTrack({ trackDownloads: true });
        trackDownloads: true,
        //Track exits to links not within same domain.  Note, selector must be broad enough to include these link (i.e. $('a').gaTrack({ trackExists: true });
        trackExits: true,
        //The category name for Google Analytics events on exit
        exitCategory: 'Exit',
        //The category attribute that indicates that a link event should be tracked
        trackAttribute: 'data-ga-track',
        //The category attribute
        categoryAttribute: 'data-ga-category',
        //The action attribute
        actionAttribute: 'data-ga-action',
        //The label attribute (could be changed to href when tracking file downloads)
        labelAttribute: 'data-ga-label',
        //The value attribute (must be integer)
        valueAttribute: 'data-ga-value',
        //Whether to look for the label
        useLabel: false,
        //Whether to look for a value
        useValue: false,
        //false = track as soon as the plugin loads, true = bind to an event
        useEvent: true,
        //The event to bind to if useEvent is true
        event: 'click',
        //A method to call to check whether or not we should call the tracking when the event is clicked
        valid: function (elem, e) {
            return true;
        },
        //Tracking complete callback
        complete: function (elem, e) { },
        //Category should always be set if using gaTrackEvent
        category: 'Unspecified',
        //Action should always be set if using gaTrackEvent
        action: 'Unspecified'
    };

    // gaTrackEvent simply adds GA event tracking without the overhead of
    // checking other avalaible options
    //
    // This allows to do sitewide event tracking e.g. Document Downloads just
    // by selecting the elements e.g.
    //
    //
    //  $('.track-submit').gaTrackEvent({
    //          category:'Submit', action:'Click', useEvent:true, event:'click'
    //    });
    //
    $.fn.gaTrackEvent = function (options) {
        options = $.extend(defaultOptions, options);

        return this.each(function () {
            var element = $(this);
            element.attr(options.categoryAttribute, options.category);
            element.attr(options.actionAttribute, options.action);

            if (options.useLabel) {
                element.attr(options.labelAttribute, options.label);
            }
            if (options.useValue) {
                element.attr(options.valueAttribute, options.value);
            }

            element.gaTrack(options);
        });
    };

    // Create the plugin
    // gaTrack expects you to add the data attributes either via server side code
    // or direct into the mark up.
    $.fn.gaTrack = function (options) {

        //Merge options
        options = $.extend(defaultOptions, options);

        //Keep the chain going
        return this.each(function () {

            var _this = $(this);
            var href = _this.attr("href");
            //Wrap the tracking so we can reuse it.
            var callTrackEvent = function () {
                //Retreive the info
                var trackHtmlEvent = _this.attr(options.trackAttribute);
                var category = _this.attr(options.categoryAttribute);
                var action = _this.attr(options.actionAttribute);
                var label = _this.attr(options.labelAttribute);
                var value = _this.attr(options.valueAttribute);
                if (trackHtmlEvent && _this.attr(options.trackAttribute)) {
                    if (options.useLabel && options.useValue) {
                        trackEvent(category, action, label, value);
                    }
                    else if (options.useLabel) {
                        trackEvent(category, action, label);
                    }
                    else {
                        trackEvent(category, action);
                    }
                }
				if (href){
                	if (options.trackDownloads) {

	                    if (href.match(/\.(zip|mp\\d+|mpe*g|pdf|docx*|pptx*|xlsx*|jpe*g|png|gif|tiff*)($|\&|\?)/)) {
	                        trackPageView(href);
	                    }

	                }
	                if (options.trackExits) {
	                    if (isExternal(href)) {
	                        trackEvent(options.exitCategory, href);
	                    }
	                }
				}
            };

            //If we want to bind to an event, do it.
            if (options.useEvent === true) {

                //This is what happens when you actually click a button
                var constructedFunction = function (e) {
                    //Check the callback function
                    if (options.valid(_this, e) === true) {
                        callTrackEvent();
                        options.complete(_this, e);
                    }
                };

                //E.g. if we are going to click on a link
                _this.bind(options.event, constructedFunction);
            }
            else {
                //Otherwise just track immediately (e.g. if we just came from a post-back)
                callTrackEvent();
            }
        });
    };

    // Aan alternative way to call the function.
    // Can be used anywhere in your Javascript like so:
    // $.ga.trackEvent('Category', 'Action', 'Label', 0.0);
    // $.ga.trackEvent('Category', 'Action');
    // $.ga.trackEvent('Category', 'Action', 'Label');
    // $.ga.trackPageView('Somepage.html');
    $.extend({
        ga: {
            trackEvent: trackEvent,
            trackPageView: trackPageView
        }
    });


})(jQuery);

	/*
	CSS Browser Selector v0.3.5 (Feb 05, 2010)
	http://rafael.adm.br/css_browser_selector
	License: http://creativecommons.org/licenses/by/2.5/
	*/
	function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',o='opera',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);

