/* Event Tracking methods and variables */
var pagelocation = document.location.href;

function TrackEvent(Category, Action, Label, Value) {
    jQuery(document).ready(function () {        
        try
        {
			tempLabel = Label.substr(Label.lastIndexOf("/")+1);
			Label = document.location.pathname + tempLabel;
            _gaq.push(['_setAccount', 'UA-223854-20']);
            _gaq.push(['_setDomainName', 'www.endurancewindpower.com']);
            _gaq.push(['_setAllowLinker', true]);
            _gaq.push(['_trackEvent', Category, Action, Label, Value]);
        }
        catch (err)
        {
            //alert('Event Error\nCategory:' + Category + '\nAction:' + Action + '\nLabel:' + Label + '\nValue:' + Value + '\n ' + err.description);
        }
        //alert('Event Tracked\nCategory:' + Category + '\nAction:' + Action + '\nLabel:' + Label + '\nValue:' + Value);
    });
}

/* Begin Google Maps Click Tracking */
function TrackOffsiteClicks() {
    /*jQuery("a").not("[href^='/']").not("[href*='.endurancewindpower.com']").not("[href*='maps.google.com']").not("[href*='/g.co/']").not("[href*='tel:']").not("[href*='mailto:']").not("[href*='.vcf']").click(function () {
        //setTimeout was required so that this wouldn't be blocked by google popup blocker
        //alert($(this).attr("target"));
        if (jQuery(this).attr("target").toLowerCase() == "_blank") {
            setTimeout('TrackEvent(\'Page Engagement\', \'Clicked Offsite Link\', \'' + jQuery(this).attr("href") + '\', 1);', 0);
        }
        else {
            TrackEvent('Page Engagement', 'Clicked Offsite Link', jQuery(this).attr("href"), 1);
        }
    });*/
	jQuery("[href*='youtube.com']").click(function () {
        TrackEvent('Page Engagement', 'Clicked YouTube', jQuery(this).attr("href"), 1);
    });
	
}

/* Begin Google Maps Click Tracking */
function TrackExtensionClicks() {
    jQuery("[href$='.zip']").click(function () {
        TrackEvent('Page Engagement', 'Clicked Zip', jQuery(this).attr("href"), 1);
    });
    jQuery("[href$='.pdf']").click(function () {
        TrackEvent('Page Engagement', 'Clicked PDF', jQuery(this).attr("href"), 1);
    });
    jQuery("[href$='.xls']").click(function () {
        TrackEvent('Page Engagement', 'Clicked XLS', jQuery(this).attr("href"), 1);
    });
    jQuery("[href$='.xlsx']").click(function () {
        TrackEvent('Page Engagement', 'Clicked XLSX', jQuery(this).attr("href"), 1);
    });
    jQuery("[href$='.doc']").click(function () {
        TrackEvent('Page Engagement', 'Clicked DOC', jQuery(this).attr("href"), 1);
    });
    jQuery("[href$='.docx']").click(function () {
        TrackEvent('Page Engagement', 'Clicked DOCX', jQuery(this).attr("href"), 1);
    });
    jQuery("[href$='.ai']").click(function () {
        TrackEvent('Page Engagement', 'Clicked AI', jQuery(this).attr("href"), 1);
    });
    jQuery("[href$='.eps']").click(function () {
        TrackEvent('Page Engagement', 'Clicked EPS', jQuery(this).attr("href"), 1);
    });
    jQuery("[href$='.tif']").click(function () {
        TrackEvent('Page Engagement', 'Clicked TIF', jQuery(this).attr("href"), 1);
    });
    jQuery("[href$='.jpg']").click(function () {
        TrackEvent('Page Engagement', 'Clicked JPG', jQuery(this).attr("href"), 1);
    });
    jQuery("[href$='.gif']").click(function () {
        TrackEvent('Page Engagement', 'Clicked GIF', jQuery(this).attr("href"), 1);
    });
}

/* Begin Google Maps Click Tracking */
function TrackEmailClicks() {
    jQuery("[href*='mailto:']").click(function () {
        TrackEvent('Page Engagement', 'Clicked Mail To', jQuery(this).attr("href"), 1);
    });
}

/* Begin Google Maps Click Tracking */
function TrackGoogleMaps() {
    jQuery("[href*='maps.google.com']").click(function () {
        TrackEvent('Page Engagement', 'Clicked Google Maps', jQuery(this).attr("href"), 1);
    });
    jQuery("[href*='/g.co/']").click(function () {
        TrackEvent('Page Engagement', 'Clicked Google Maps', jQuery(this).attr("href"), 1);
    });
}

/* Exec event tracking functions */
jQuery(document).ready(function () {
    TrackGoogleMaps();
    TrackOffsiteClicks();
    TrackExtensionClicks();
    TrackEmailClicks();
});
