$(document).ready(function() {
    /* 	Auto event tagging. Ensure that the correct class and title attributes are applied.	*/
	
  jQuery.fn.log = function (msg) {
      console.log("%s: %o", msg, this);
      return this;
  };
	

    /* set default vars*/
    var pageTitle = document.title
    $(function() {
        // track main nav
        $("#mainPrimary a").click(function() {
            var label = $(this).attr("title");
            pageTracker._trackEvent('Main Nav', 'Click Event', 'Nav Item: ' + label + '');
        });
        //track secondary navs
        $("#mainSecondaryAbout a").click(function() {
            var label = $(this).attr("title");
            pageTracker._trackEvent('About The Project Secondary', 'Click Event', 'Nav Item: ' + label + '');
        });
        $("#mainSecondaryProject a").click(function() {
            var label = $(this).attr("title");
            pageTracker._trackEvent('Project Regions Secondary', 'Click Event', 'Nav Item: ' + label + '');
        });
        $("#mainSecondaryNews a").click(function() {
            var label = $(this).attr("title");
            pageTracker._trackEvent('News Secondary', 'Click Event', 'Nav Item: ' + label + '');
        });
        $("#mainSecondaryActivities a").click(function() {
            var label = $(this).attr("title");
            pageTracker._trackEvent('Activities Secondary', 'Click Event', 'Nav Item: ' + label + '');
        });
		//snippet link tracking
		$(".pressSnippetIcon a,.pressSnippetCopy a").click(function() {
			var label = $(this).attr("eventTrack");			
			pageTracker._trackEvent('Press Release Snippet', 'Click Event', '' + label + '');
		});
		$(".announcementSnippetIcon a,.announcementSnippetCopy a").click(function() {
			var label = $(this).attr("eventTrack");			
			pageTracker._trackEvent('Announcement Snippet', 'Click Event', ' ' + label + '');
		});
		$(".activitySnippetIcon a,.activitySnippetCopy a").click(function() {
			var label = $(this).attr("eventTrack");			
			pageTracker._trackEvent('Scheduled Work Activities Snippet', 'Click Event', ' ' + label + '');
		});		
		$(".pressSnippetAltIcon a,.pressSnippetAltCopy a").click(function() {
			var label = $(this).attr("eventTrack");			
			pageTracker._trackEvent('Press Release Snippet Alt', 'Click Event', ' ' + label + '');
		});	
		$(".activitySnippetAltIcon a,.activitySnippetAltCopy a").click(function() {
			var label = $(this).attr("eventTrack");			
			pageTracker._trackEvent('Scheduled Work Activities Snippet Alt', 'Click Event', ' ' + label + '');
		});			
        // track footer links
        $("#footerRightTop a,#footerRightBottom a").click(function() {
            var label = $(this).attr("title");
            pageTracker._trackEvent('Footer Nav', 'Nav Click Event', ' ' + label + '');
        });
        // Auto tag all outbound links
        $("a").click(function() {
            var target = $(this).attr("target");
            var linkURL = $(this).attr("href");
            if (target == '_blank') {
                pageTracker._trackEvent('Link Out', 'Click Event', '' + linkURL + '');
            }
            return;
        });
		//snippets hover states
		function init () {
		$(".announcementSnippet").find("a").bind("mouseenter", function() {
			if (this.parentNode.nodeName.toUpperCase() == "H3") {
				$(this.parentNode.parentNode.parentNode).find("div.news-icon").removeClass("news-icon").addClass("news-icon2");
				$(this).css("text-decoration", "underline");
			} else {
				$(this).find("div.news-icon").removeClass("news-icon").addClass("news-icon2");
				$(this.parentNode).find("h3 a").css("text-decoration", "underline");
			}
		}).bind("mouseleave", function() {
			if (this.parentNode.nodeName.toUpperCase() == "H3") {
				$(this.parentNode.parentNode.parentNode).find("div.news-icon2").removeClass("news-icon2").addClass("news-icon");
				$(this).css("text-decoration", "none");
			} else {
				$(this).find("div.news-icon2").removeClass("news-icon2").addClass("news-icon");
				$(this.parentNode).find("h3 a").css("text-decoration", "none");
			}
		});
	}
	
	$(window).load(init);


    });
});
