﻿
jQuery( document ).ready( function() 
{
	// Finds all the Google Ads slots: div which have an ID starting with "google_ads_"
    var googleAds = jQuery(".advertisement");

    jQuery(googleAds).each(function(index) 
	{
	    var adsContainer = jQuery(this);

		// Check wether we have flash advertisements
	    var objectContent = jQuery(adsContainer.find("object"));
		
		// Check wether we have images advertisements
	    var imagesContent = jQuery(adsContainer.find("img"));
		
		// Check wether we have iframes advertisements
	    var iframeContent = jQuery(adsContainer.find("iframe"));
		
		// If we have iframe, let's use the frameReady plugin
		if( iframeContent.length > 0 && objectContent.length == 0 && imagesContent.length == 0 )
		{
		    jQuery.frameReady(function()
			{ 
				iframeContent.contents().click( function()
				{
					pageTracker._trackPageview( '/asclick' );
				} );
			}, 
			"top." + iframeContent.attr( "name" ), 
			{ remote: false } );
		}
		else
		{
			// for all other types (flash, images links), simply track the container 
			// click event
		    if (jQuery.browser.msie)
			{
				// IE does not bubble click events of embedded flash objects 
				// but it does bubble focus. Unfortunalty, the focus event seems to loop...
				var done = false;
				adsContainer.children( "object:last, img:last" ).focus( function()
				{
					if( !done )
					{
						pageTracker._trackPageview( '/asclick' );
						done = true;
						return true;
					}
				} );
			}
			else
			{
				adsContainer.click( function()
				{
					pageTracker._trackPageview( '/asclick' );
				} );
			}
		}
	});
});
