;SF.TM = 
{
    init: function()
    {
        this.cookieTracking();
    },
    
    isWithinThreeClicks: function()
    {
        return ($.cookie('tourismMediaClicks') != null && parseInt($.cookie('tourismMediaClicks'), 10) <= 3);
    },
    
    /**
     * Tourism Media receive commission for each enquiry if the enquiry is made within 3 clicks from a Tourism 
     * Media content page.
     *  
     * Therefore, we use a counting cookie "tourismMediaClicks", set this to 0 whenever the user is on a Tourism
     * Media page and when they are on an ET page, the cookie value is incremented.
     *
     * The cookie is also not created until the user visits a Tourism Media page.
     */
    cookieTracking: function()
    {
        if(window.location.pathname.indexOf('world-travel') == 1)
        {   		    
            $.cookie('tourismMediaClicks', 0, { path: '/' });
        }
        
        if(window.location.pathname.indexOf('world-travel') != 1 && $.cookie('tourismMediaClicks') != null)
        {
            $.cookie('tourismMediaClicks', parseInt($.cookie('tourismMediaClicks'), 10) + 1,  { path: '/' });
        }
    },
    
    googleAnalyticsReporting: function(timestamp)
    {
        timestamp = (typeof(timestamp) == 'undefined' ? function() { d = new Date(); return d.getTime(); }() : timestamp);
        if(this.isWithinThreeClicks() || SF.getQueryVariable('tourismMediaTracking') == 'true')
        {
            SF.registerGAPageView({ path: 'tourism-media/' + timestamp });
        }
    }
};
SF.TM.init();


