﻿
$( document ).ready( function() 
{
	// Finds all the Google Ads slots: div which have an ID starting with "google_ads_"
	var googleAds = $( ".advertisement" );
		
	$( googleAds ).each( function( index ) 
	{
		var adsContainer = $( this);

		// Check wether we have flash advertisements 
		var objectContent = $( adsContainer.find( "object" ) );
		
		// Check wether we have images advertisements 
		var imagesContent = $( adsContainer.find( "img" ) );
		
		// Check wether we have iframes advertisements 
		var iframeContent = $( adsContainer.find( "iframe" ) );
		
		// If we have iframe, let's use the frameReady plugin
		if( iframeContent.length > 0 && objectContent.length == 0 && imagesContent.length == 0 )
		{
			$.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( $.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' );
				} );
			}
		}
	});
});

