/**
* This script ensures that all CTAs are tracked
* Required because CTAs can now be added to the copy, which would not include the tracking in the onclick attribute
*/
$(document).ready(function() {
    
    // Absolutely every funnel CTA will link to /cart/update...
    $('#wrapper a[href^="/cart/update"]').click(function(e) {
        // if the parent doesn't have a class of CTA, it's been put in the copy by the AM
        if($(this).parent().hasClass('cta')) {
            var cta_id = $(this).parent().attr('id');
        }
        else {
            var cta_id = $(this).attr('id');
            if('' == cta_id) {
                cta_id = 'copycta';
            }
        }
        
        // if the page path is empty, we're on the home page
        var page_path = window.location.pathname.replace('/', '');
        if('' == page_path) {
            page_path = 'home';
        }
        
        // Google Analytics
        if('undefined' != typeof _gaq) {
            _gaq.push(['_trackEvent', 'cta_click', cta_id, location.pathname, 1]);
        }
        
        // infinity
        if('undefined' != typeof __NAS) {
            __NAS.trig('CTA', {'t':'CLICK', 'txr': cta_id});
        }
    });
    
    // This will ensure giftcard CTAs are tracked
    $('#wrapper a[href*="giftcard.magazine.co.uk"]').click(function() {
        // Google Analytics
        if('undefined' != typeof _gaq) {
            _gaq.push(['_trackEvent', 'giftcard', 'giftcard_click', location.pathname, 1]);
        }
    });
    
});
