/*--------------------------------------------------------*
* Copyright (C) 2006 Verthink S.r.l. - Italy
* 
* File: library.js
* Author: Aldo Armiento
* Version: 20080124.1
*---------------------------------------------------------*/

var my_google_position = "CENTER";
var my_google_ad_feed = null;
var my_google_afs_feed = null;
var sAdsSection = null;
var my_google_top_ads = 0;
var my_google_bottom_ads = 0;
var my_google_right_ads = 0;

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function google_ad_request_done(aAds)
{
	my_google_ad_feed = aAds;
	my_google_request_done('ad');
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function google_afs_request_done(aAds)
{
	my_google_afs_feed = aAds;
	my_google_request_done('afs');
}	

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function my_google_request_done(sType)
{
	var aAds = null;

	if (my_google_afs_feed == null || my_google_ad_feed == null)
		return;

	if (my_google_afs_feed)
	{	my_google_display_afs(my_google_afs_feed);
	}
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function my_google_afs_request_done(nNumber)
{
	if (my_google_afs_feed == null)
		return;

	if (my_google_afs_feed)
	{	my_google_display_afs(my_google_afs_feed, nNumber);
	}
}

/*---------------------------------------------------------*
*
*----------------------------------------------------------*/

function my_google_display_afs(aAds, nNumber, sFPos)
{
	var sRet = '';
	var i = 0;


	if (aAds.length == 0)
		return;

	var nAdsSectionMargin = 115;
	if (sAdsSection == 'lavoro') {
		nAdsSectionMargin = 0;
	}

	if (my_google_position == 'RIGHT') // SKYCRAPER (DESTRA)
	{
		if (aAds.length > (my_google_top_ads + my_google_bottom_ads)) {
			aAds = aAds.slice(my_google_top_ads + my_google_bottom_ads, my_google_top_ads + my_google_bottom_ads + nNumber);
			my_google_right_ads = aAds.length;
		} else {
			return;
		}

		if (typeof sFPos == 'undefined' || sFPos != 'b')
			sRet += '<div style="margin-bottom:8px;"><a target="_blank" href="' + google_info.feedback_url + '" style="font-size:11px; color:#9F9F9F; text-decoration:none;">Annunci Google</a></div>';

		for (i = 0; i < aAds.length; i++)
		{
			if (aAds[i].type == 'text/wide')
				continue;

			if (typeof nNumber != 'undefined' && nNumber > 0 && nNumber == i-1)
				break;

			sRet += '<div style="margin-bottom:';

			if (i == (aAds.length-1))
				sRet += '0';
			else	sRet += '10';

			sRet += 'px"><a style="text-decoration:none" target="_blank" href="' + aAds[i].url + '" ' +
				'onmouseover="window.status=\'' + aAds[i].visible_url.replace(/(&#39;|&#039;|')/g, "\\\'") + '\'" onmouseout="window.status=\'\'">' +
				'<span style="font-family:Arial; text-decoration:underline; color:#0000CC; font-size:12px; font-weight:bold">' + aAds[i].line1 + '<br></span></a>' +
				'<span style="font-family:Arial; font-size:12px; color:#000000">' + aAds[i].line2 + ' ' + aAds[i].line3 + '<br></span>' +
				'<a class="textline_url" style="text-decoration:none;" target="_blank" href="' + aAds[i].url + '" ' +
				'onmouseover="window.status=\'' + aAds[i].visible_url.replace(/(&#39;|&#039;|')/g, "\\\'") + '\'" onmouseout="window.status=\'\'">' + aAds[i].visible_url + '</a></div>';
		}

		if (typeof sFPos != 'undefined' && sFPos == 'b')
			sRet += '<div style="text-align:right; margin-top:-4px;"><a target="_blank" href="' + google_info.feedback_url + '" style="font-size:11px; color:#9F9F9F; text-decoration:none;">Annunci Google</a></div>';
	}
	else // RISULTATI
	{
		if (my_google_position == 'TOP') {
			aAds = aAds.slice(0, nNumber);
			my_google_top_ads = aAds.length;
		} else if (my_google_position == 'BOTTOM') {
			if (aAds.length > (my_google_top_ads)) {
				aAds = aAds.slice(my_google_top_ads, my_google_top_ads + nNumber);
				my_google_bottom_ads = aAds.length;
			} else {
				return;
			}
		} else {
			return;
		}

		sRet += '<table style="margin-top:10px;" cellspacing="0" cellpadding="0" border="0" width="100%">';

		sRet += '<tr><td><div style="margin-bottom:3px; margin-left: ' + String(Number(nAdsSectionMargin) + Number(3)) + 'px;">';
		sRet += '<a class="bottom_feedback_link" target="_blank" href="' + google_info.feedback_url + '">Annunci Google</a>';
		sRet += '</div></td></tr>';

		sRet += '<tr><td><div style="margin-top:4px; margin-bottom:4px; margin-left: ' + nAdsSectionMargin + 'px;">';

		if (my_google_position == 'TOP' && aAds.length == 1 && aAds[i].type != 'text/wide') // Output: Un solo ad con fonts grandi
		{
			i = 0;
			sRet += '<div style="border:1px solid white; padding:2px;">' + 
				'<a target="_blank" href="' + aAds[i].url + '"' +
				'onmouseover="window.status=\'' + aAds[i].visible_url.replace(/(&#39;|&#039;|')/g, "\\\'") + '\'" onmouseout="window.status=\'\'">' +
				'<span class="textline_b1"><b>' + aAds[i].line1 + '</b><br></span></a>' +
				'<img src="/images/pixt.gif" width="1" height="3" border="0"><br><span class="textline_b2">' + aAds[i].line2 + '</span> <span class="textline_b3">' + aAds[i].line3 + '</span>' +
				'<div class="desc_fonte"><a class="textline_burl" style="text-decoration:none;" target="_blank" href="' + aAds[i].url + '" ' +
				'onmouseover="window.status=\'' + aAds[i].visible_url.replace(/(&#39;|&#039;|')/g, "\\\'") + '\'" onmouseout="window.status=\'\'">' + aAds[i].visible_url + '</a></div>';
		} else {
			for (i = 0; i < aAds.length; i++)
			{
				if (aAds[i].type == 'text/wide')
					continue;

				sRet += '<div style="border:1px solid white; padding:2px;">' +
					'<a target="_blank" href="' + aAds[i].url + '"' +
					'onmouseover="window.status=\'' + aAds[i].visible_url.replace(/(&#39;|&#039;|')/g, "\\\'") + '\'" onmouseout="window.status=\'\'">' +
					'<span class="textline_1"><b>' + aAds[i].line1 + '</b><br></span></a>' +
					'<img src="/images/pixt.gif" width="1" height="4" border="0"><br><span class="textline_2">' + aAds[i].line2 + '</span> <span class="textline_3">' + aAds[i].line3 + '</span>' +
					'<div class="desc_fonte" style="margin-top:3px;"><a class="textline_url" style="text-decoration:none;" target="_blank" href="' + aAds[i].url + '" ' +
					'onmouseover="window.status=\'' + aAds[i].visible_url.replace(/(&#39;|&#039;|')/g, "\\\'") + '\'" onmouseout="window.status=\'\'">' + aAds[i].visible_url + '</a></div></div>';

				if (i < aAds.length - 1) {
					sRet += '<div class="results_item_separator"><img src="http://www.biglist.it/images/pixt.gif" width="1" height="1" border="0" /></div>';
				}
			}
		}

		sRet += '</div>';
		sRet += '</td></tr></table>';
	}
	document.write(sRet);
	return;
}
