/*******************************
Tracking / Analytics 
*******************************/

conoco.track = {

    /* Navigation Links
    advertising: function() {
    this.track('/nav_advertising');	
    },
    promotions: function() {
    this.track('/nav_cheetos');		
    },
    ourgas: function() {
    this.track('/nav_ourgas);		
    },
    creditcards: function() {
    this.track('/nav_creditcards');	
    },
    sponsorships: function() {
    this.track('/nav_sponsorships');	
    },
    entertainment: function() {
    this.track('/nav_entertainment');	
    },
    findstation: function() {
    this.track('/nav_findstation');	
    },
    plantrip: function() {
    this.track('/nav_plantrip');	
    },
	
	*/
    /* Conoco Gas Register */
    subscribe: function() {
        this.track('/nav_subscribe');
    },

    /* Credit Card Exits */
    creditClick: function(category, action, title) {
        try {
            category = category.toLowerCase();
        }
        catch (e) { }
        title = this.safeTitle(title);

        this.trackEvent('credit-cards', category, title + '-' + action);
    },

    safeTitle: function(str) {
        var myRegxp = new RegExp(" ", "gi");
        newstr = str.replace(myRegxp, "-");
        newstr = newstr.replace(/[-]/g, "-");
        newstr = newstr.replace(/[^A-Za-z0-9_-]/g, '');

        return newstr.toLowerCase();
    },

    doubleClickShare: function() {
        // code generated by doubleclick
        // activity name for this tag is "UNDEFINED"
        var axel = Math.random() + "";
        var a = axel * 10000000000000;
        $("#doubleclickTrack").html('<img src="http://ad.doubleclick.net/activity;src=1358061;type=2010c837;cat=cheet779;ord=' + a + '?" width="1" height="1" border="0" />');
    },
    // Call tracking services
    track: function(trackingEvent) {
        console.log(trackingEvent);
        try {
            _gaq.push(['_trackPageview', trackingEvent]);
        }
        catch (e) {
            console.log('a pageview error occurred');
            // log error	
        }
    },
    protectBounce: false,
    trackEvent: function(category, action, label, value) {
        if (action == "viewing_paused_video") this.protectBounce = false;
        if (action == "viewing_rewind_video") this.protectBounce = false;

        if (!this.protectBounce) {
            if (typeof (value) != 'undefined') {
                var tracker = function() { _gaq.push(['_trackEvent', category, action, label, value]); };
            }
            if (typeof (label) != 'undefined') {
                var tracker = function() { _gaq.push(['_trackEvent', category, action, label]); };
            }
            else {
                var tracker = function() { _gaq.push(['_trackEvent', category, action]); };
            }
            // push to analytics queue
            try {
                tracker();
                console.log('_gaq.push([\'_trackEvent\', ' + category + ', ' + action + ', ' + label + ', ' + value + ']);');
            }
            catch (e) {
                // log error
                console.log('an event tracking error occurred');
            }
        }
        else
            console.log("protected bounce no trackEvent");
    }
};

$(function () {

    //custom tracking

    $("#creditCardPromoTrack").click(function () {
        _gaq.push(['_trackEvent', 'credit-cards', 'business','conoco-personal-card-apply']);
    });

}); 



