/*
AdLogger Tracking Script
Modified with permission from the following:
Jim Rotherford's Adsense Pepper (http://www.digitalmediaminute.com),
Shawn from Digital Point for the YPN support (http://forums.digitalpoint.com/showthread.php?t=39549&page=3),
SeoBook.com for Google Analytics support (http://www.seobook.com),
Dolly's Tracking Script (http://asp-net-whidbey.blogspot.com).
Reference: http://www.webmasterworld.com/forum89/1788.htm
These copyright notices must remain intact!
*/
function ad_click () {
	var ad_target_url = '';
	// check for ad Url/AdLinks text (is disabled in Firefox by default)
	if (window.status) {
		var adsenseClickedAd = window.status;
		if (adsenseClickedAd != '') {
			ad_target_url = escape(adsenseClickedAd);
		}
	}

	adlogger_url_image = new Image();
	adlogger_url_image.src = adlogger_loc + '/trackclick.php?ch_id=' + channel_id + '&ad_target=' + ad_target_url + '&ad_format=';

	// If running analytics, set up an adlogger goal to track the clicks there, too
	if (typeof urchinTracker == 'function') {
		urchinTracker ('/adlogger');
	}
}
// incredibly funky onload add-event scripting, for all browsers

		 if(typeof window.addEventListener != 'undefined')
		 {
		 	//.. gecko, safari, konqueror and standard
		 	window.addEventListener('load', adsense_init, false);
		 }
		 else if(typeof document.addEventListener != 'undefined')
		 {
		 	//.. opera 7
		 	document.addEventListener('load', adsense_init, false);
		 }
		 else if(typeof window.attachEvent != 'undefined')
		 {
		 	//.. win/ie
		 	window.attachEvent('onload', adsense_init);
		 }

		 //** remove this condition to degrade older browsers
		 else
		 {
		 	//.. mac/ie5 and anything else that gets this far

		 	//if there's an existing onload function
		 	if(typeof window.onload == 'function')
		 	{
		 		//store it
		 		var existing = onload;

		 		//add new onload handler
		 		window.onload = function()
		 		{
		 			//call existing onload function
		 			existing();

		 			//call adsense_init onload function
		 			adsense_init();
		 		};
		 	}
		 	else
		 	{
		 		//setup onload function
		 		window.onload = adsense_init;
		 	}
		 }

function adsense_init () {

	if (document.all) {  //ie

		var el = document.getElementsByTagName("iframe");

		for(var i = 0; i < el.length; i++) {
			if(el[i].src.indexOf('googlesyndication.com') > -1) {
				el[i].onfocus =  ad_click;
			} else if (elements[i].src.indexOf('overture.com') > -1) {
				elements[i].onfocus = ad_click;
			}
		}
	} else {   // firefox

		window.addEventListener('beforeunload', doPageExit, false);
		window.addEventListener('mousemove', getMouse, true);

	}
}

//for firefox
var px;
var py;

function getMouse(e) {
	px=e.pageX;
	py=e.clientY;
}

function findY(obj) {
	var y = 0;
	while (obj) {
		y += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return(y);
}

function findX(obj) {
	var x = 0;
	while (obj) {
		x += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	return(x);
}

function doPageExit(e) {
	ad = document.getElementsByTagName("iframe");
	for (i=0; i<ad.length; i++) {
		var adLeft = findX(ad[i]);
		var adTop = findY(ad[i]);
		var inFrameX = (px > (adLeft - 10) && px < (parseInt(adLeft) + parseInt(ad[i].width) + 15));
		var inFrameY = (py > (adTop - 10) && py < (parseInt(adTop) + parseInt(ad[i].height) + 10));
		if (inFrameY && inFrameX) {
			ad_click();
		}
	}
}
//end for firefox