/*!
 * @author Nicolas DOUILLET (Appgratuites)
 * @description Define Tracking events
 */
$(document).ready(function()
{
	if ( !window._gaq )
	{
		return;
	}
	
	function push(a)
	{
		//console.log(a);
		window._gaq.push(a);
	}
	
	/*
	 * Click on deals 
	 */
	
	// short deals
	$("div.deal div.app-profile a").click
	(
		function()
		{
			var home 	= $("body").is(".home");
			var title	= $(this).closest("div.app-profile").find("h3.app-title").text();
			var soldout	= $(this).is(".soldout");
			
			push(['_trackEvent', 'link', (home ? 'home-deal' : 'archive-deal') + (soldout ? '-soldout' : ''), title]);
		}
	);
	
	// main deals
	$("#main-deal div.app-profile a").click
	(
		function()
		{
			var home 	= $("body").is(".home");
			var title	= $(this).closest("div.app-profile").find("h3.app-title").text();
			var soldout	= $(this).is(".soldout");
			
			push(['_trackEvent', 'link', (home ? 'home-main-deal' : 'single-deal') + (soldout ? '-soldout' : ''), title]);
		}
	);
	
	/*
	 * Internal
	 */
	
	// deals links
	$("#main-deal h2 a, div.deal h2 a").click
	(
		function()
		{
			var home 	= $("body").is(".home");
			var title	= $(this).closest("div").find("div.app-profile").find("h3.app-title").text();
			var soldout	= $(this).is(".soldout");
			
			push(['_trackEvent', 'internal', (home ? 'home-main' : 'page-main') + (soldout ? '-soldout' : ''), title]);
		}
	);
	
	
	// top
	$("#download-app-ad-buttons a").click
	(
		function()
		{
			var ipad = $(this).is("#download-app-ad-button-ipad");
			push(['_trackEvent', 'internal', 'home-top', ipad ? 'appStore-iPad' : 'appStore-iPhone' ]);
		}
	);
	
	// liens du footer
	$("#footer-links ul.links li.menu-item a").click
	(
		function()
		{
			var home 	= $("body").is(".home");
			var link	= $(this).attr("href");
			
			push(['_trackEvent', 'internal', home ? 'home-bottom' : 'page-bottom', link]);
			
		}
	);
	
	// liens vers facebook et le copains
	$("#footer-links ul.links.social li a").click
	(
		function()
		{
			var home 	= $("body").is(".home");
			var klass	= $(this).attr("class");
			
			push(['_trackEvent', 'internal', home ? 'home-bottom' : 'page-bottom', klass]);
		}
	);
	
	// sidebar iphone
	$("div.sidebar #promobox-iphone-ad a").click
	(
		function()
		{
			var home = $("body").is(".home");
			push(['_trackEvent', 'internal', home ? 'home-side' : 'page-side', 'appStore-iPhone']);
		}
	);
	
	// sidebar
	$("div.sidebar p.right a").click
	(
		function()
		{
			var link = $(this).attr("href");
			push(['_trackEvent', 'internal', 'home-side', link]);
		}
	);
	
	// sidebar ipad
	$("div.sidebar #promobox-ipad-ad a").click
	(
		function()
		{
			push(['_trackEvent', 'internal', 'page-side', 'appStore-iPad']);
		}
	);
});
