function popup(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;

	win = window.open(mypage, myname, 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no,status=no')
	win.window.focus();
}

function sendNewsletter() {
	var a = new Ajax();
	
	a.onLoad = function () {
		this.runJS(this.html);
	}
	
	if (f.send('form_newsletter', true)) {
		a.sendForm('form_newsletter');
	}
	
	return false;
}

function homeAgenda(tmp_id) {
	document.location = 'agenda.php#item' + tmp_id;
}

//Vídeos
function loadVideo(tmp_i) {				
	var o = videos[tmp_i];
	
	$('td_video_titulo').innerHTML = '<strong>' + o.titulo + '</strong>';
	$('td_video').innerHTML = '<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/' + o.tag + '&hl=pt-br&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + o.tag + '&hl=pt-br&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>';
}

function loadVideosPag(tmp_i) {
	videos_pag = tmp_i;

	var html = '<table width="277" border="0" cellpadding="0" cellspacing="0"><tr>';
	var col = 0;
	var o;
	var i = tmp_i * 9;
	var i_map = i;
	var max = Math.min(videos.length, (tmp_i + 1) * 9);
	var max_map = Math.min(videos.length, i_map + 12);
	
	var empty_map = [2, 6, 11];
	
	for (; ((i < max) || (i_map < max_map)); ) {
		o = videos[i];
		
		if (empty_map.indexOf(i_map) == -1) {
			html += '<td width="90" height="90" valign=><img title="' + o.titulo + '" onclick="javascript: loadVideo(' + i + ');" style="cursor: pointer;" src="../upload/videos_thumbs/' + o.id + '.jpg" width="90" height="90"></td>';			
			
			i++;
		} else {
			html += '<td width="90">&nbsp;</td>';	
		}
		i_map++;
		
		col++;
		if (col >= 3) {
			col = 0;
			
			html += '</tr><tr>';
		}
	}
			
	html += '</tr></table>';
	
	$('div_videos').innerHTML = html;
	
	if (videos_pag > 0) {
		$('img_videos_anteriores').style.display = '';
	} else {
		$('img_videos_anteriores').style.display = 'none';
	}
	
	if (videos_pag < (Math.ceil(videos.length / 12) - 1)) {
		$('img_videos_proximas').style.display = '';
	} else {
		$('img_videos_proximas').style.display = 'none';
	}
}	


//Fotos
function loadAlbum(tmp_i) {
	albuns_i = tmp_i;
	
	//Todo: 1st photo
	var o = albuns[albuns_i];
	
	$('td_fotos_titulo').innerHTML = '<strong>' + o.titulo + '</strong>';
	$('td_fotos_autor').innerHTML = 'Fotos por ' + o.autor + '</strong>';
	
	var html = '<table cellspacing="0" cellpadding="0"><tr>';
	var i = 0;
	
	o.fotos.each(function (k, v) {
		html += '<td width="90"><img onclick="javascript: loadAlbumFoto(' + i + ')" style="cursor: pointer;" src="../upload/fotos/' + o.id + '/' + v + '" width="90" height="90"></td><td width="2"><img src="../img/estrutura/pixel.gif" width="2"></td>';
		i++;
	});
	
	html += '</tr></table>';
	
	$('div_fotos_thumbs').innerHTML = html;
	
	loadAlbumFoto(0);
	goThumbsPage(0, true);
}

function loadAlbumFoto(tmp_i) {
	var foto = (new String(albuns[albuns_i].fotos[tmp_i])).replace("_p", "");
	$('div_fotos_grande').innerHTML = '<img src="../upload/fotos/' + albuns[albuns_i].id + '/' + foto + '">';
}

function loadAlbunsPag(tmp_i) {
	albuns_pag = tmp_i;
	
	var html = '<table width="270" border="0" cellspacing="0" cellpadding="0"><tr><td height="54" colspan="3"><img src="../img/fotos_videos/textos/outras_galerias.gif" width="210" height="30"></td></tr>';
	var o;
	var i = tmp_i * 10;
	var max = Math.min(albuns.length, (tmp_i + 1) * 10);
	var bg = true;
	for (; i < max; i++) {
		o = albuns[i];
		
		html += '<tr title="' + o.titulo + '" onclick="javascript: loadAlbum(' + i + ')" style="cursor: pointer; ';
		if (bg) {
			html += 'background:url(../img/fotos_videos/bg_outrasfotos.jpg) top center no-repeat;">';		
		} else {
			html += '">';
		}
		bg = !bg;
		
		html += '<td width="91" align="center" class="agenda_data" >' + o.data + '</td><td width="179" height="28" colspan="2" class="texto_descricao">' + o.titulo + '</td></tr>';
	}
			
	html += '</tr></table>';
	
	$('div_albuns').innerHTML = html;
	
	if (albuns_pag > 0) {
		$('img_fotos_anteriores').style.display = '';
	} else {
		$('img_fotos_anteriores').style.display = 'none';
	}
	
	if (albuns_pag < (Math.ceil(albuns.length / 12) - 1)) {
		$('img_fotos_proximas').style.display = '';
	} else {
		$('img_fotos_proximas').style.display = 'none';
	}
}

function goThumbsPage(tmp_p, tmp_now) {
	tmp_now = (tmp_now != "undefined") ? tmp_now : false;
	
	thumbs_page = tmp_p;
	
	var x = -(tmp_p * 6 * 92);
	
	if (tmp_now) {
		$('div_fotos_thumbs').style.left = x + 'px';
	} else {
		Tween.addTween($('div_fotos_thumbs'), 1, {_x: x, type: "expoOut"});
	}
	
	if (tmp_p > 0) {
		$('img_thumbs_anterior').style.display = '';
	} else {
		$('img_thumbs_anterior').style.display = 'none';
	}
	
	if (tmp_p < (Math.ceil(albuns[albuns_i].fotos.length / 6) - 1)) {
		$('img_thumbs_proxima').style.display = '';
	} else {
		$('img_thumbs_proxima').style.display = 'none';
	} 
}