// JavaScript Document
var _trackingADAReady = false; // messa a true appena il flash è pronto per ricevere i tracciamenti
var _trackingADADone = false; // messa a true dopo il primo tracciamento effettuato (per essere sicuri che llo SharedObject sia aggiornato)
var _trackingADAQueue = []; // coda dei tracciamenti in attesa che il flash sia caricato e pronto

swfobject.registerObject("trackingADASWF", "8.0.35.0", false);

function TrackingReady()
{
	_trackingADAReady = true;
	
	if(!_trackingADADone)
	{
		if(_trackingADAQueue.length > 0)
		{
			var tmpTrackObj = _trackingADAQueue.shift();
			swfobject.getObjectById("trackingADASWF").TrackingSezione(tmpTrackObj.pSez, tmpTrackObj.isAutoOpen, tmpTrackObj.isSezioneOpen);
		}
		else
			_trackingADADone = true;
	}
	else
	{	
		//se ci sono eventi già scatenati prima del ready della pagina li mando dopo
		for(var i=0; i<_trackingADAQueue.length; i++)
		{
			var tmpTrackObj = _trackingADAQueue[i];
			swfobject.getObjectById("trackingADASWF").TrackingSezione(tmpTrackObj.pSez, tmpTrackObj.isAutoOpen, tmpTrackObj.isSezioneOpen);
		}
		_trackingADAQueue = [];
	}

}

function TrackingDone()
{
	if(!_trackingADADone)
	{
		_trackingADADone = true;
		TrackingReady(); // la richiamo per svuotare la coda eventualmente presente
	}
	
}

function TrackingSezione(pSez, isAutoOpen, isSezioneOpen)
{
	if(_trackingADADone)
	{
		// posso chiamare direttamente la funzione nel flash in quanto _trackingADAReady è true e _trackingADADone è true
		swfobject.getObjectById("trackingADASWF").TrackingSezione(pSez, isAutoOpen, isSezioneOpen);
	}
	else
	{
		_trackingADAQueue.push({ pSez: pSez, isAutoOpen: isAutoOpen, isSezioneOpen:isSezioneOpen });
	}
}

function TrackingSezioneAndGoToUrl(pSez, isAutoOpen, isSezioneOpen, urlToGo)
{
	// posso chiamare direttamente la funzione nel flash in quanto _trackingADAReady è true e _trackingADADone è true
	swfobject.getObjectById("trackingADASWF").TrackingSezioneAndGoToUrl(pSez, isAutoOpen, isSezioneOpen, urlToGo);
}


function GetCFID()
{
	return swfobject.getObjectById("trackingADASWF").GetCFID();
}

function GetSID()
{
	return swfobject.getObjectById("trackingADASWF").GetSID();
}
