$(document).ready(function() {
    $("div#sidebar li.f_country_v2 a").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "Homepage Sidebar" + " - Countries - " + $(this).text() + " - " + $(this).attr("href");
                _gaq.push(['_trackEvent', 'Homepage', 'Left Nav', param]);
            }
        }
        catch (err) {
        }
    });

    $("div#sidebar li.special-offers a").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "Homepage Sidebar - Special Offers" + " - " + $(this).text() + " - " + $(this).attr("href");
                _gaq.push(['_trackEvent', 'Homepage', 'Left Nav', param]);
            }
        }
        catch (err) {
        }
    });

    $("div#sidebar a[href='/19th-hole/']").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "Homepage Sidebar - 19th Hole " + $(this).attr("href");
                _gaq.push(['_trackEvent', 'Homepage', 'Left Nav', param]);
            }
        }
        catch (err) {
        }
    });

    $("#TopOffersIrelandUKOfferPanel div.offer a img").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "";
                if ($(this).attr("alt") == "Enquire") {
                    param = "Homepage - Enquire button - " + $(this).parent().parent().parent().find("h4 a").text() + " - " + $(this).attr("href");
                    _gaq.push(['_trackEvent', 'Homepage', 'UK and Ireland Offers', param]);
                } else if ($(this).attr("alt") == "Book") {
                    param = "Homepage - Book button - " + $(this).parent().parent().parent().find("h4 a").text() + " - " + $(this).attr("href");
                    _gaq.push(['_trackEvent', 'Homepage', 'UK and Ireland Offers', param]);
                } else {
                    param = "Homepage Offer Image link" + " - " + $(this).parent().find("h4 a").text() + " - " + $(this).attr("href");
                    _gaq.push(['_trackEvent', 'Homepage', 'UK and Ireland Offers', param]);
                }
            }
        }
        catch (err) {
        }
    });

    $("#TopOffersIrelandUKOfferPanel div.offer h4 span a").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "Homepage Top Offers - Top Offers Title - " + $(this).text() + " - " + $(this).attr("href");
                _gaq.push(['_trackEvent', 'Homepage', 'UK and Ireland Offers', param]);
            }
        }
        catch (ex) {
        }
    });

    $("#TopOffersIrelandUKOfferPanel div.offer h5 a").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "Homepage Top Offers - Top Offers Price - " + $(this).text() + " - " + $(this).attr("href");
                _gaq.push(['_trackEvent', 'Homepage', 'UK and Ireland Offers', param]);
            }
        }
        catch (err) {
        }
    });

    $("#TopOffersEuropeOfferPanel div.offer a img").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "";
                if ($(this).attr("alt") == "Enquire") {
                    param = "Homepage - Enquire button - " + $(this).parent().parent().parent().find("h4 a").text() + " - " + $(this).attr("href");
                    _gaq.push(['_trackEvent', 'Homepage', 'European Offers', param]);
                } else if ($(this).attr("alt") == "Book") {
                    param = "Homepage - Book button - " + $(this).parent().parent().parent().find("h4 a").text() + " - " + $(this).attr("href");
                    _gaq.push(['_trackEvent', 'Homepage', 'European Offers', param]);
                } else {
                    param = "Homepage Offer Image link" + " - " + $(this).parent().find("h4 a").text() + " - " + $(this).attr("href");
                    _gaq.push(['_trackEvent', 'Homepage', 'European Offers', param]);
                }
            }
        }
        catch (err) {
        }
    });

    $("#TopOffersEuropeOfferPanel div.offer h4 span a").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "Homepage Top Offers - Top Offers Title - " + $(this).text() + " - " + $(this).attr("href");
                _gaq.push(['_trackEvent', 'Homepage', 'European Offers', param]);
            }
        }
        catch (ex) {
        }
    });

    $("#TopOffersEuropeOfferPanel div.offer h5 a").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "Homepage Top Offers - Top Offers Price - " + $(this).text() + " - " + $(this).attr("href");
                _gaq.push(['_trackEvent', 'Homepage', 'European Offers', param]);
            }
        }
        catch (err) {
        }
    });

    $("#TopOffersWorldwideOfferPanel div.offer a img").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "";
                if ($(this).attr("alt") == "Enquire") {
                    param = "Homepage - Enquire button - " + $(this).parent().parent().parent().find("h4 a").text() + " - " + $(this).attr("href");
                    _gaq.push(['_trackEvent', 'Homepage', 'Worldwide Offers', param]);
                } else if ($(this).attr("alt") == "Book") {
                    param = "Homepage - Book button - " + $(this).parent().parent().parent().find("h4 a").text() + " - " + $(this).attr("href");
                    _gaq.push(['_trackEvent', 'Homepage', 'Worldwide Offers', param]);
                } else {
                    param = "Homepage Offer Image link" + " - " + $(this).parent().find("h4 a").text() + " - " + $(this).attr("href");
                    _gaq.push(['_trackEvent', 'Homepage', 'Worldwide Offers', param]);
                }
            }
        }
        catch (err) {
        }
    });

    $("#TopOffersWorldwideOfferPanel div.offer h4 span a").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "Homepage Top Offers - Top Offers Title - " + $(this).text() + " - " + $(this).attr("href");
                _gaq.push(['_trackEvent', 'Homepage', 'Worldwide Offers', param]);
            }
        }
        catch (ex) {
        }
    });

    $("#TopOffersWorldwideOfferPanel div.offer h5 a").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "Homepage Top Offers - Top Offers Price - " + $(this).text() + " - " + $(this).attr("href");
                _gaq.push(['_trackEvent', 'Homepage', 'Worldwide Offers', param]);
            }
        }
        catch (err) {
        }
    });

    $("div#topnav li.default a").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "Homepage Top Nav - Home" + " - " + $(this).attr("href");
                _gaq.push(['_trackEvent', 'Homepage', 'Top Nav', param]);
            }
        }
        catch (err) {
        }
    });

    $("div#topnav li.uk-golf-breaks a").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "Homepage Top Nav - Golf Breaks - " + $(this).text() + " - " + $(this).attr("href");
                _gaq.push(['_trackEvent', 'Homepage', 'Top Nav', param]);
            }
        }
        catch (err) {
        }
    });

    $("div#topnav li.golf-holidays a").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "Homepage Top Nav - Golf Holidays - " + $(this).text() + " - " + $(this).attr("href");
                _gaq.push(['_trackEvent', 'Homepage', 'Top Nav', param]);
            }
        }
        catch (err) {
        }
    });

    $("div#topnav li.golf-tours a").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "Homepage Top Nav - Golf Tours - " + $(this).text() + " - " + $(this).attr("href");
                _gaq.push(['_trackEvent', 'Homepage', 'Top Nav', param]);
            }
        }
        catch (err) {
        }
    });

    $("div#topnav li.speciality-breaks a").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "Homepage Top Nav - Speciality Breaks - " + $(this).text() + " - " + $(this).attr("href");
                _gaq.push(['_trackEvent', 'Homepage', 'Top Nav', param]);
            }
        }
        catch (err) {
        }
    });

    $("div#topnav li.corporate-golf a").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "Homepage Top Nav - Corporate Golf - " + $(this).text() + " - " + $(this).attr("href");
                _gaq.push(['_trackEvent', 'Homepage', 'Top Nav', param]);
            }
        }
        catch (err) {
        }
    });

    $("div#topnav li.tournament-packages a").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "Homepage Top Nav - Tournament Packages - " + $(this).text() + " - " + $(this).attr("href");
                _gaq.push(['_trackEvent', 'Homepage', 'Top Nav', param]);
            }
        }
        catch (err) {
        }
    });

    $("div#topnav li.tee-times a").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "Homepage Top Nav - Tee Times - " + $(this).text() + " - " + $(this).attr("href");
                _gaq.push(['_trackEvent', 'Homepage', 'Top Nav', param]);
            }
        }
        catch (err) {
        }
    });

    $("input.search").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "Homepage - Search - Top Search - " + $(this).text() + " - " + $("form#hLocation input.text").text();
                _gaq.push(['_trackEvent', 'Homepage', 'Top Search', param]);
            }
        }
        catch (err) {
        }
    });

    $("div.span-3 a").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "Homepage Right Sidebar - " + $(this).find("img").attr("alt") + " - " + $(this).attr("href");
                _gaq.push(['_trackEvent', 'Homepage', 'Right Nav', param]);
            }
        }
        catch (err) {
        }
    });

    $("div#footerinner_top a").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "Homepage Footer - " + $(this).attr("alt") + " - " + $(this).attr("href");
                _gaq.push(['_trackEvent', 'Homepage', 'Footer', param]);
            }
        }
        catch (err) {
        }
    });

    $("a#bottomEnquireButton").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "General Enquiry - Bottom General Enquiry Form - " + $(this).attr("href");
                _gaq.push(['_trackEvent', 'Homepage', 'General Enquiry', param]);
            }
        }
        catch (err) {
        }
    });

    $("a#YGTTopLogo").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "YGT Logo - YGT Logo - " + $(this).attr("href");
                _gaq.push(['_trackEvent', 'Homepage', 'YGT Logo', param]);
            }
        }
        catch (err) {
        }
    });

    $("input#CentreSearchButton").click(function() {
        try {
            if (window.location.pathname == '/') {
                var param = "Homepage Footer - " + $(this).find("img").attr("alt") + " - " + $(this).attr("href");
                _gaq.push(['_trackEvent', 'Homepage', 'Centre Search', param]);
            }
        }
        catch (err) {
        }
    });
});


function trackClick(cat, action, label, onlyFromHomePage) {
    try {
        if (onlyFromHomePage) {
            if (window.location.pathname == '/') {
                _gaq.push(['_trackEvent', cat, action, label]);
            }
        }
        else {
            _gaq.push(['_trackEvent', cat, action, label]);
        }
    }
    catch (err) {
    }
}

