﻿var SEO = {
    init: function() {
        $(document).ready(SEO._init);
    },

    _init: function() {
        $('#footer .left .hotel a').each(function() {
            $(this).click(function(index) {
                var hotel = $(this).html();
                SEO.tracking('/footer/hotel/' + escape(hotel));
            });
        });

        $('#footer .right a').each(function(index) {
            $(this).click(function() {
                var link = $(this).attr('href');
                if (link.search(/facebook.com/gi) > -1) {
                    SEO.tracking('/footer/share/facebook');
                } else if (link.search(/twitter.com/gi) > -1) {
                    SEO.tracking('/footer/share/twitter');
                } else if (link.search(/mailto\:/gi) > -1) {
                    SEO.tracking('/footer/' + escape(link));
                } else if (link.search(/skype\:/gi) > -1) {
                    SEO.tracking('/footer/' + escape(link));
                }
            });
        });

        $('#content a').each(function(index) {
            var link = $(this).attr('href');

            if (link != null) {
                if (link.search(/^mailto\:/gi) > -1) {
                    if ($(this).attr('onclick') != null) {
                        if ($(this).attr('onclick').toString().search(/googleTracking/gi) == -1) {
                            $(this).click(function() {
                                SEO.tracking('/email/' + escape(link));
                            });
                        }
                    } else {
                        $(this).click(function() {
                            SEO.tracking('/email/' + escape(link));
                        });
                    }
                } else if (link.search(/\.(pdf|doc)$/gi) > -1) {
                    if ($(this).attr('onclick') != null) {
                        if ($(this).attr('onclick').toString().search(/googleTracking/gi) == -1) {
                            $(this).click(function() {
                                SEO.tracking('/download/' + escape(link));
                            });
                        }
                    } else {
                        $(this).click(function() {
                            SEO.tracking('/download/' + escape(link));
                        });
                    }
                } else if (
						(link.search(/anantara\.com/gi) == -1) &&
						(
							(link.search(/^http\:\/\//gi) > -1) ||
							(link.search(/^https\:\/\//gi) > -1)
						)
					) {
                    if ($(this).attr('onclick') != null) {
                        if ($(this).attr('onclick').toString().search(/googleTracking/gi) == -1) {
                            $(this).click(function() {
                                SEO.tracking('/outgoing/' + escape(link));
                            });
                        }
                    } else {
                        $(this).click(function() {
                            SEO.tracking('/outgoing/' + escape(link));
                        });
                    }
                }
            }
        });
    },
    tracking: function(path) {
       // var _gaq = _gaq || [];
        _gaq.push(['_trackPageview', path]);
    }
}

SEO.init();
