var arrTags = 
[
 	{google:"/IndexFlash", predicta:"", addInteligence:""},
	{google:"/IndexFlash/high_version", predicta:"", addInteligence:""},
	{google:"/IndexFlash/low_version", predicta:"", addInteligence:""},
	{google:"/IndexFlash/video_intro", predicta:"", addInteligence:""},
	{google:"/IndexFlash/skip_intro", predicta:"", addInteligence:""},
	
	{google:"/IndexFlash/liga_som", predicta:"", addInteligence:""},
	{google:"/IndexFlash/desliga_som", predicta:"", addInteligence:""},
	{google:"/IndexFlash/link_home", predicta:"", addInteligence:""},
	
	{google:"/IndexFlash/secao/home", predicta:"", addInteligence:""},
	{google:"/IndexFlash/secao/home/lancamentos", predicta:"", addInteligence:""},
	{google:"/IndexFlash/secao/home/produtos", predicta:"", addInteligence:""},
	{google:"/IndexFlash/secao/home/destaques", predicta:"", addInteligence:""},
	
	{google:"/IndexFlash/secao/produtos", predicta:"", addInteligence:""},
	{google:"/IndexFlash/secao/destaques", predicta:"", addInteligence:""},
	{google:"/IndexFlash/secao/faleconosco", predicta:"", addInteligence:""},
	{google:"/IndexFlash/secao/historia", predicta:"", addInteligence:""},
	{google:"/IndexFlash/secao/lancamentos", predicta:"", addInteligence:""},
	{google:"/IndexFlash/secao/receitas", predicta:"", addInteligence:""},
	
	{google:"/IndexFlash/popup/bauducco", predicta:"", addInteligence:""},
	{google:"/IndexFlash/popup/comercial", predicta:"", addInteligence:""},
	{google:"/IndexFlash/popup/trabalhe", predicta:"", addInteligence:""},
	{google:"/IndexFlash/popup/sac", predicta:"", addInteligence:""},
	{google:"/IndexFlash/popup/politica", predicta:"", addInteligence:""},
	{google:"/IndexFlash/popup/mapa", predicta:"", addInteligence:""}
];

// Quando aplicar no site, utilizar trackDebug = false;
var trackDebug = false;

// Dimensões padrões para abrir pop-up quando não espeficiada na função.
var nPopDefaultWidth = 400;
var nPopDefaultHeight = 400;
// Quando as popups forem abertas sem nome, utilizamos este contador para o nome
var nWindowCount = 0;
var objOpener = null;

function getTag ( strGoogleTag, strReturnTag )
{
	for( var i=0; i<arrTags.length; i++ ) 
	{
		if (arrTags[i].google == strGoogleTag)
		{
			return arrTags[i][strReturnTag];
		}
	}
	return "";
}


function track( arParams )
{
	strTag = arParams[0];
	strURL = arParams[1];
	strWindow = arParams[2];
	nWidth = arParams[3];
	nHeight = arParams[4];
	booFocus = arParams[5];	
	
	if(strTag == "null" || strTag == "undefined") strTag = "";
	if(strURL == "null" || strURL == "undefined") strURL = "";
	if(strWindow == "null" || strWindow == "undefined") strWindow = "";
	if(nWidth == "null" || nWidth == "undefined") nWidth = "";
	if(nHeight == "null" || nHeight == "undefined") nHeight = "";
	if(booFocus == "null" || booFocus == "undefined") booFocus = null;
	booFocus = Boolean( booFocus );
	
	// Predicta
	var strPredictaTag = getTag(strTag, "predicta");
	if (strPredictaTag!="")
	{
		void( atmCLL(strPredictaTag) );
		if ( trackDebug ) alert( strPredictaTag );
	}

	// addInteligence
	var strAddInteligenceTag = getTag(strTag, "addInteligence");
	if (strAddInteligenceTag!="")
	{
		// verificar se existe imagem com id de "image_tracker".
		if(document.getElementById("image_tracker") == null){
			alert("Image tracker missing.\n AddInteligence won't work");
		}else{
			void( document.getElementById("image_tracker").src = strAddInteligenceTag );
			if ( trackDebug ) alert( strAddInteligenceTag );
		}
	}
	
	// google analytics (new)
	void( pageTracker._trackPageview(strTag) );
	if ( trackDebug ) alert( strTag );

	if ( strURL )
	{
		switch ( strWindow )
		{
			case "pop_full_resizable":
				var objWindow = openPopupWindow(strURL, null, null, null, null, true);
				if (booFocus) objWindow.focus();
				break;
				
			case "pop_full":
				var objWindow = openPopupWindow(strURL);
				if (booFocus) objWindow.focus();
				break;
			
			case "pop":
				if ( !nWidth ) nWidth = nPopDefaultWidth;
				if ( !nHeight ) nHeight = nPopDefaultHeight;
				var objWindow = openPopupWindow(strURL, null, nWidth, nHeight);
				if (booFocus) objWindow.focus();
				break;
			
			case "_blank":
				var objWindow = window.open( strURL );
				if (booFocus) objWindow.focus();
				break;
				
			case "opener":
				try
				{
					window.opener.location.href = strURL;
					if (booFocus)
					{
						window.opener.focus();						
					}
				}
				catch(e)
				{
					try
					{
						objOpener.location.href = strURL;
						if (booFocus)
						{
							objOpener.focus();						
						}
					}
					catch(e)
					{
						objOpener = window.open(strURL, "_blank");
						if (booFocus)
						{
							objOpener.focus();						
						}
					}					
				}
				break;
		
			default:
				window.location = strURL;
		}				
	}
}



function openPopupWindow( strURL, strWindowName, nWidth, nHeight, booScrollBars, booResizable )
{
	
	if (!strWindowName)
	{
		strWindowName = "window_" + nWindowCount;
		nWindowCount++;
	}
	
	if (!nWidth && !nHeight) booFull = true;

	nWidth = (nWidth) ? nWidth : screen.availWidth - 7;
	nHeight = (nHeight) ? nHeight : screen.availHeight - 8;	

	strScrollBars = (booScrollBars) ? "yes" : "no";
	strResizable = (booResizable) ? "yes" : "no";

	var nLeft = (booFull) ? 0 : ( (window.screen.width  - nWidth) / 2 );
	var nTop =  (booFull) ? 0 : ( (window.screen.height - nHeight) / 2 );
	
	var strWindowsFeatures = 'leftmargin=0, topmargin=0, marginheight=0, marginwidth=0, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars='+strScrollBars+', resizable='+strResizable+', top='+nTop+', left='+nLeft+', screenX='+nLeft+', screenY='+nTop+', copyhistory=no, width='+nWidth+', height='+nHeight;
	
	var objWindow = window.open( strURL, strWindowName, strWindowsFeatures);
	return objWindow;
}
