var menu = [
	['/index.php?page/saibamais', 'Saiba Mais', 127, null],
	['/index.php?page/localize', 'Localize sua árvore', 204, null],
	['/index.php?page/aovivo', 'Menos CO2 ao Vivo', 196, null],
	['/index.php?page/divulgue', 'Divulgue o Menos Carbono', 262, null],
	['/index.php?page/contato', 'Contato', 111, null]
];

function mountMenu()
{
	var lenX = 53;
	var lenY, hRef, iSrc, trgt, iOpt, iALt;
	document.write('<ul>');
	for(i = 0; i < menu.length; i++)
	{
		hRef = menu[i][0];
		iAlt = menu[i][1];
		lenY = menu[i][2];
		trgt = menu[i][3] != null ? ' target="' + menu[i][3] + '"' : '';
		iSrc = mainMenu != i ? 'mnu.' + parseInt(i + 1) + '.off.gif' : 'mnu.' + parseInt(i + 1) + '.on.gif';
		document.write('<li><a href="' + hRef + '" onmouseover="javascript:swapImage(\'mnu' + i + '\');" onmouseout="javascript:swapImage(\'mnu' + i + '\');"><img src="/data/themes/menoscarbono/img/' + iSrc + '" width="' + lenY + '" height="' + lenX + '" alt="' + iAlt + '" id="mnu' + i + '" /></a></li>');
	}
	document.write('</ul>');
	void(0);
}

function swapImage(id)
{
	var imagem = document.getElementById(id);
	var iarray = imagem.src.split('.');
	iarray[iarray.length - 2] = iarray[iarray.length - 2] != 'on' ? 'on' : 'off';
	imagem.src = iarray.join('.');
	void(0);
}

function swapState(node, element)
{
	var nodes = 5;
	var node, cls;
	for(i = 1; i <= nodes; i++)
	{
		inode = document.getElementById('drop_' + i);
		cls = i != node ? 'invisible' : 'visible';
		//alert(i +':::'+ node.className);
		inode.className = cls;
		if(i == node)
		{
//			setImage(element);
		}
	}
}

function setImage(element)
{
	var el = document.getElementById('elemento');
	el.innerHTML  = '<img src="/data/themes/menoscarbono/img/' + element + '.gif" />';
	void(0);
}

function loadElement(url)
{
	document.getElementById('download').href = url;
	void(0);
}

function updateContador() {
	var c=document.getElementById('contadorco2');
	if (! c) {
		return;
	}
	var data_inicio=1214841507; // unixtime 01/07/2008
	var qtde_inicio=4666666; // Qtde Carbono calulada em 01/07/2008
	var qtde_arvores=70000;
	var now =(new Date()).getTime()/1000;
	if (now < data_inicio) {
		c.innerHTML = qtde_inicio;
		return;
	}
	var qtde=qtde_inicio+(now-data_inicio)*0.87671*qtde_arvores/(24*3600);
	c.innerHTML = format(qtde);
	setTimeout(updateContador, 1000); 
}
function format(num) { 
	var PAD = ',00'; 
	num=Number(num.toFixed(PAD.length-1));
	var str = String(num);
	var strlocal=num.toLocaleString();
	num=Math.ceil
	var dot = str.indexOf('.');
	if ( navigator.appName.indexOf("Microsoft") == -1) {
		if (dot < 0) { 
			return strlocal + PAD; 
		} if (PAD.length > (str.length - dot)) {
			return strlocal + PAD.substring(str.length - dot);
		}
	}
	return strlocal;
}

function get_param(name) {
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null ){
        return "";
    }else{
        return results[1];
    }
}

//if(document.cookie.indexOf("samba=true") < 1){
//	window.open('/downloads/widget/samba.html','samba','width=180,height=225,scrollbars=0;');
//	document.cookie='samba=true;path=/';
//}
 
