/*
 * params google
 */

	var	ga 				= false;
	var	ga_done  		= false;

/**
 * dispatch nombre d'arg variables
 */
function dispatch_adsense() {

	if ( ga_done == false) {
		return;
	}

	var ad;
	var	n;
	var s = '';
	
	if (ga.length == 0) {
		// y en a pu
		return;		
	}

	// si aucun argument , pas de limite
	if (arguments.length == 0) {
		n = 1000;
	}
	else {
		n = arguments[0];
	}
	
	// on en veut explicitement aucun
	if (n == 0) {
		return;
	}

	// Print "Ads By Google" -- include link to Google feedback page
	s 	+='<div class="googlead">';

	s	+='<a class="title" href="' 
		+ google_info.feedback_url 
		+ '">Annonces Google</a>' ;

    /*
     * Si une annonce illustrée est renvoyée, affichez cette annonce.
     * Sinon, créez une chaîne contenant toutes les annonces, puis
     * utilisez une commande document.write() pour imprimer cette chaîne.
     */
	if (ga[0].type == "image") {
    	s += '<a href="'+ google_ads[0].url 
			+ '" target="_top" title="go to ' 
			+ ga[0].visible_url 
			+ '"><img style="border:none;" src="' + ga[0].image_url 
			+ '"width="' + ga[0].image_width 
			+ '"height="' + ga[0].image_height 
			+ '"/></a>';
    }
	else {
		if (ga.length > 0) {

			var style = '';

			if (ga.length == 1) {
				// dans le cas d'une annonce unique, largeur max
				style = ' style="width:96%;" ';
			}

			// tant qu'il y des annonces, a concurrence de la limite
			while( n > 0 		 
			&&	(ad =  ga.pop()) )
			{
				s += '<a class="googlead" onclick="javascript:top.location.href=\'' 
					+ ad.url  
					+ '\'" onmouseover="window.status=\'' + ad.visible_url + '\'" onmouseout="window.status=\'\'"'
					+ style
					+ '>'
					+ '<span class="line1">' + ad.line1 + '</span>'
					+ ' <span class="line2">' + ad.line2 + '</span>'
					+ ' <span class="line3">' + ad.line3 + '</span>' 
					+ '<span class="visibleurl">' + ad.visible_url + '</span>'
					+ '</a>';
				
				n--;
			}
		}
	} 
	
	s += '<hr class="separateur" />';
	s += '</div>';
    document.write(s);
    return;
}

/**
 * Fonction de rappel google
 */
function google_ad_request_done(google_ads) {
    /*
     * Vérifiez qu'il existe bien des annonces à afficher.
    */
    if (google_ads.length == 0) {
      return;
    }

	// stocke en global
	ga = google_ads;
	ga_done = true;
	return;
}
