function trackClick(link, app, obj, id) {
	var url = link.href;
	var trImg = new Image();
	trImg.src = "http://ads.worldgolf.com/track/click.php?app="+app+"&type="+obj+"&id="+id;
	return true;
}

function trackImpressionLazy(app, obj, id) {
	if ( typeof jQuery != 'undefined' ) {
		jQuery(document).ready(function($) {
			_trackImpressionLazy(app, obj, id);
		});
	}
	else {
		_trackImpressionLazy(app, obj, id);
	}
}


function _trackImpressionLazy(app, obj, id) {
	var d1 = document.createElement("div");

	d1.style.position="absolute";
	d1.style.left="0px";
	d1.style.top="0px";
	d1.style.visiblity="hidden";

	d1.innerHTML = '<img width="0" height="0" style="width:0px;height:0px;" alt="" src="http://ads.worldgolf.com/track/view.php?t2=1&app='
	+ app
	+ '&type=' 
	+ obj
	+'&id='
	+ id
	+ '"/>' ;
	return true;
}

/* old function.. used for compatibility.. New stuff should call trackImpressionLazy() */
function trackImpression(app, obj, id) {
	document.write(
	'<div style="position:absolute;left:0px;top:0px;visibility:hidden;">'
	+ '<img width="0" height="0" style="width:0px;height:0px;" alt="" src="http://ads.worldgolf.com/track/view.php?app='
	+ app
	+ '&type=' 
	+ obj
	+'&id='
	+ id
	+ '"/>'
	+ '</div>'
	 );
	return true;
}


if ( typeof jQuery != 'undefined' ) {
	jQuery(document).ready(function($) {
		$("a[@href*='secure.guestdesk.com'], a[@href^=http://www.golffacility.com/], a[@href^=https://book.golfswitch.com/WebPro/search.asp]").bind('click keypress', function() {
			var a = $(this);
			var parentEls = a.parents().map(function () { return this.tagName + "#" + this.id + "." + this.className; }).get().join(">");
			var href = a.attr('href');
			var category = 'booking'; 
			var event = 'click'; 
			var label =  parentEls ;
			try { pageTracker._trackEvent(category, event, label); } catch(err) {}
		});
	});
}

if ( typeof jQuery != 'undefined' ) {
	jQuery(document).ready(function($) {
		$("a[@href*=/cgi-bin/xpackage/package-redirect.php]").bind('click keypress', function() {
			var a = $(this);
			var parentEls = a.parents().map(function () { return this.tagName + "#" + this.id + "." + this.className; }).get().join(">");
			var href = a.attr('href');
			var onclick = a.attr("onclick") + "";
			temp = onclick.split(',');
			var category =  temp[2] + "." + temp[1];
			category = category.replace(/["']/g, '');
			var event = 'click'; 
			var label =  temp[3] +  " | " + parentEls ;
			var obj_id = temp[3];
			obj_id = obj_id.replace(/\).*/g, '');
			obj_id = obj_id.replace(/['"]/g, '');
			label = parentEls;
			//alert (temp[0] + "|" + temp[1]);
			try { pageTracker._trackEvent(category, event, label); } catch(err) {}
		});
	});
}
