/*
script desenvolvido por Luis Carlos de Brito - luis@pevermelho.art.br

caso venha adquirir este script por outro meio senao atraves do autor, favor manter o credito do criadore
este script pode ser utilizado, modificado, publicado, utilizado sem restricoes desde que mantido os credidos dos criadores

##########------- tive muito trabalho para fazer este funcionar, respeite meu trabalho e conhecimento -------##########
*/
var ie=ie6=ie7=ie8=false;
var obj_flash;

function init() {	
	if(window.navigator.appVersion.indexOf('MSIE 6.')!=-1) ie6=true;
	if(window.navigator.appVersion.indexOf('MSIE 7.')!=-1) ie7=true;
	if(window.navigator.appVersion.indexOf('MSIE 8.')!=-1) ie8=true;
	window.navigator.appName=='Microsoft Internet Explorer' ? ie=true : ie=false;
	$('#contato').click(function(){ showModalDiv('dv_contato')});
	
	$('#dv_menu a').hover(
		function(){ $(this).addClass('ui-state-focus ui-corner-all'); },
		function(){ $(this).removeClass('ui-state-focus ui-corner-all'); }
	);
	res=window.screen.width+'x'+window.screen.height;	
	if(!getCookie('resolucao')) {
		 setCookie('resolucao',res);
		 loadURL('none','','registrarResolucao&resolucao='+res);
	}
	obj_flash=insertSWF('imagens/loading.swf', 60, 60, '');
	$('.botao').button();
	manageProjeto();
	startdate = new Date()
	worldPopulation(startdate.getYear(),startdate.getMonth(),startdate.getDate(),startdate.getHours(),startdate.getMinutes(),startdate.getSeconds());
	productiveLands();
	doFeed();
	$('#ss_ecogal').cycle({fx:'scrollHorz', next:'#next_ecogal', prev:'#prev_ecogal', timeout:4000});
	$('#ss_evento').cycle({fx:'scrollHorz', next:'#next_ev', prev:'#prev_ev', timeout:5000});
	$('#ss_topo').cycle({fx:'fade'});
}

function printAttrs(obj) {
	str='';
	for(i in obj) str+='key -> '+i+'\r\nvalue -> '+obj[i];
	alert(str);
}

function setCookie(nome, valor) { document.cookie=nome+'='+valor; }

function getCookie(nome) {
	var start=document.cookie.lastIndexOf(nome+'=');
	if(start==-1) return false;
    var end=document.cookie.indexOf(';',start);
    if(end!=-1) 
    	return document.cookie.substring(start + nome.length+1, end);
    else 
    	return document.cookie.substring(start + nome.length+1, document.cookie.length);
}

function loadData(form) {
  form = get(form);
  var n_fields = form.length;
  var dados = '';
  var types1 = 'text hidden select-one textarea password';
  var types2 = 'checkbox radio';
  var types3 = 'button submit';
  
  for(var n=0; n < n_fields; n++) {
     if(types3.indexOf(form.elements[n].type)==-1) {
     	if(form.elements[n].getAttribute('obrigatorio')=='sim' && form.elements[n].value=='') {
     		$.growlUI('',form.elements[n].getAttribute('msg'));
     		form.elements[n].focus();
     		return false;
     	}
	  	else {
		  	if(types1.indexOf(form.elements[n].type)!=-1)
		     	dados+=form.elements[n].name+'='+ encodeURIComponent(form.elements[n].value) +'&';
		  	else{
		  		if(types2.indexOf(form.elements[n].type)!=-1) {
		  			if(form.elements[n].checked)
		  				dados+= form.elements[n].name+'='+ encodeURIComponent(form.elements[n].value)+'&';
		  		}
	  		}
	  	}
   	}
  } 
  dados = dados.substr(0, dados.length-1);
  return dados;
}

function showModalDiv(id) { 
	$.blockUI({ message: $('#'+id) }); 	
	$('.blockOverlay').click($.unblockUI); 
	$('.blockUI.blockPage').css('position','absolute'); 
}

function showModalContent(content, _w) {
	var msg='<a herf="" class="_fr" onclick="$.unblockUI()"><img src="imagens/x.png"></a><div class="dv100 _ac">'+content+'</div>';
	$.blockUI({ message: content, css: { width: _w, border:'5px solid #666', left: ((screen.width - parseInt(_w.replace('px','')) )/2)+'px', top:$('html').scrollTop() } });
	$('.blockOverlay').click($.unblockUI); 
	$('.blockUI.blockPage').css({'position':'absolute'});
}

function block() {
	 $.blockUI({ css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: '#000', 
            '-webkit-border-radius': '10px', 
            '-moz-border-radius': '10px', 
            opacity: .5, 
            color: '#fff' 
        } });
}

function votarEnquete(resposta) { loadURL('dv_enquete','','votarEnquete&voto='+resposta); }

function insertSWF(file, w, h, params) {
	insert = new Flash(file, '', w, h,'');
	insert.addParameter('wmode', 'transparent'); 
	insert.addParameter('showMenu', 'false'); 
	
	if(params.length>2) {
		tmp=params.split(',');
		for(i in tmp) {
			param_value = tmp[i].split('=');
			insert.addVariable(param_value[0]+'', param_value[1]+'');
		}
	}
	return insert.toString();
}

function addListener(el, event, func) {
	try { el.addEventListener(event, func, false); } 
	catch (e) {
		try {
			el.detachEvent('on'+ event, func);
			el.attachEvent('on'+ event, func);
		} catch (e) {}
	}
}

function showImgUploaded(msg, campo) {get('retorno'+campo).innerHTML=''+msg;}

function manageProjeto(dir) {
	var width=$('#ss_projetos a').size()*110;
	max=-(width-550);
	
	if($('#wrapParceiro').html()==null) 
		$('#ss_projetos a').wrapAll('<div id="wrapParceiro" style="float:left;width:'+width+';position:relative;" />');
	if(dir=='e')
		if(parseFloat($('#wrapParceiro').css('marginLeft').replace('px',''))<0) {
			$('#wrapParceiro').animate({marginLeft:'+=100'},1500);}
	if(dir=='d')
		if(parseFloat($('#wrapParceiro').css('marginLeft').replace('px',''))>max) {
			$('#wrapParceiro').animate({marginLeft:'-=110'},1500);}
}

/*--------world population----------*/
function ChangeValue(number,pv){
	numberstring =""
	var j=0 
	var i=0
	while (number > 1)	 {
	    numberstring = (Math.round(number-0.5) % 10) + numberstring
	    number= number / 10
	    j++
	    if (number > 1 && j==3) { 
			numberstring = "." + numberstring 
			j=0;
	    }
	    i++
	 }
	 numberstring=numberstring;
	if (pv==1)  $('#world_population').html(numberstring); 
}

	

function worldPopulation(year,month,date,hours,minutes,seconds) {       
	startdatum = new Date(year,month,date,hours,minutes,seconds)

	var now = 6070581000;//5600000000.0
	var now2 = 6453628000;//5690000000.0
	var groeipercentage = (now2 - now) / now *100
	var groeiperseconde = (now * (groeipercentage/100))/1826/24.0/60.0/60.0 
	nu = new Date ()                
	schuldstartdatum = new Date (2000,1,1)                            
	secondenoppagina = (nu.getTime() - startdatum.getTime())/1000
	totaleschuld= (nu.getTime() - schuldstartdatum.getTime())/1000*groeiperseconde + now
	ChangeValue(totaleschuld,1);

	timerID = setTimeout("worldPopulation(startdatum.getYear(),startdatum.getMonth(),startdatum.getDate(),startdatum.getHours(),startdatum.getMinutes(),startdatum.getSeconds())",3000)
}
/*---------------------------------*/

/*-------productive lands----------*/
function productiveLands() {
   startland = 8592867929;
   today = new Date()
   
   startdate = new Date("January 1, 2000")
   diff = (today.getTime() - startdate.getTime()) / 1000;

   newland = Math.ceil(startland - (diff * 0.13035))+'';
   var tmp=tmp2='';
   var size=newland.length-1;
   
   for(i=0;i<=size;i++) {
   	tmp+=newland.charAt(size-i);
   	if((i+1)%3==0 && i>0)  tmp+='.';
   }
   
   if(tmp.charAt(tmp.length-1)=='.')
   	tmp=tmp.substr(0,tmp.length-1);
   	
   for(i=0;i<=tmp.length;i++)
   	tmp2+=tmp.charAt(tmp.length-i);
   $('#productive_lands').html(tmp2);
   
   setTimeout('productiveLands()',5000);
}
/*---------------------------------*/

function doFeed() {
	$.jGFeed('http://www.unmultimedia.org/radio/portuguese/rss/23.xml',
	function(feeds){
	  if(!feeds){
	    return false;
	  }
	  for(var i=0; i<8; i++){
	    entry = feeds.entries[i];
	    if(entry!=null && entry!='undefined')
	   		$('#news_from_onu').append('<a class="dv100 _mt10" href="'+entry.link+'" target="_blank">[ '+(i+1)+' ] - <b>'+entry.title+'</b></a>');
	  }
	  $('#news_from_onu').append('<div class="dv100 _mt20 _brb _mb20"><b>Fonte: <a class="_cb" href="http://www.unmultimedia.org/radio/portuguese/detail/195912.html" target="_blank">Rádio das Nações Unidas</a></b></div>');
	}, 10);	
}

function loadVideo(idVideo, content, w, h){
	var params = { allowScriptAccess: "always", wmode:"transparent" };
	swfobject.embedSWF("http://www.youtube.com/v/" + idVideo + "&enablejsapi=1&playerapiid=player1",""+content, w, h, "8", null, null, params);
}

function loginAreaRestrita() {
	var data=$('#pass').val();
	if(data!='') {
		$.ajax({type:'POST',url:'conteudo.php',data:'&acao=login&pass='+data,success:function(resp){ if(resp==0) alert('A senha não confere.'); else window.location.href='?pg=ar'; }});
	}
}

addListener(window, 'load', init); 546099604
