var meses = Array('','Janeiro','Fevereiro','Mar�o','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro');

$(document).ready(function(){
	/*
	$('#box_fotos ul li a').colorbox();
	$('#box_videos ul li a').colorbox({
		iframe: true,
		width: 900,
		height: 520
	});
	
	box_tweets();
	
	$('#carousel_banners').jcarousel({
		vertical: true,
		scroll: 1,
		auto: 6,
		wrap: 'both'
	});
	
	galerias();
	*/
	box_agenda();
	box_twitter();
	box_fotos();
	box_destaques();
});

function box_agenda()
{
	$('#box_agenda ul li a .seta_on').css('opacity',0);
	$('#box_agenda ul li a').mouseover(function(){$(this).find('.seta_on').stop().animate({'opacity': 1},300);});
	$('#box_agenda ul li a').mouseleave(function(){$(this).find('.seta_on').stop().animate({'opacity': 0},300);});
}

function box_twitter()
{
	$.ajax({
		type: 'GET',
		url: 'http://search.twitter.com/search.json?q=joyfornations&rpp=8&page=1',
		contentType: 'application/json; charset=utf-8',
		dataType: 'jsonp',
		success: function(r){
			var t = r.results;
			var i = 0;
			while(t[i])
			{
				var nome = t[i].from_user;
				var img = t[i].profile_image_url;
				var texto = t[i].text;
				$('#carousel_tweets').append('<li><span class="img"><img src="'+img+'" alt="'+nome+'" width="50" height="50"></span><span class="texto"><strong>'+nome+'</strong><br>'+texto+'</span></li>');
				i++;
			}
			$('#carousel_tweets').jcarousel({
				vertical: true,
				scroll: 1,
				auto: 5,
				wrap: 'both'
			});
		}
	});
	
	//http://search.twitter.com/search.json?q=@davsilvaoficial&rpp=8&page=1
}

function box_fotos()
{
	$('#carousel_galerias').jcarousel({
		vertical: false,
		scroll: 1,
		wrap: false
	});
	
	$('#carousel_galerias a').colorbox({opacity: 0.5});
}

function galerias()
{
	$('#box_fotos ul').html('');
	
	$.ajax({
		type: 'GET',
		url: '/ws/fotos.php',
		contentType: 'application/json; charset=UTF-8',
		dataType: 'json',
		data: {'qtde': 8},
		success: function(r){
			if(r.length > 0)
			{
				var i = 0;
				while(i < r.length)
				{
					var g_id = r[i].id;
					var g_nome = r[i].nome;
					var g_data = r[i].data.substr(8,2) + '|' + meses[Math.ceil(r[i].data.substr(5,2))].substr(0,3) + '|' + r[i].data.substr(0,4);
					var g_cidade = r[i].cidade + ' - ' + r[i].uf;
					var g_capa = r[i].capa;
					$('#box_fotos ul').append('<li><a class="galeria" href="javascript:" gal_id="'+g_id+'" gal_nome="'+g_nome+'" gal_cidade="'+g_cidade+'" gal_data="'+g_data+'"><img src="/uploads/fotos/'+g_id+'/'+g_capa+'?w=50&h=50&c=1" alt=""></a></li>');
					i++;
				}
				$('#box_fotos ul li a').unbind('click').bind('click',function(){ box_fotos($(this).attr('gal_id'),$(this).attr('gal_nome'),$(this).attr('gal_cidade'),$(this).attr('gal_data')); });
			}
		}
	});
}

function box_destaques()
{
	$('#carousel_dest1').jcarousel({
		vertical: true,
		scroll: 1,
		auto: 5,
		wrap: 'both'
	});
	$('#carousel_dest2').jcarousel({
		vertical: true,
		scroll: 1,
		auto: 5,
		wrap: 'both'
	});
}

/*
function box_fotos(gal_id,gal_nome,gal_cidade,gal_data)
{
	var idoverlay = 'ovelay_fotos_'+gal_id;
	
	$('body').append('<div id="'+idoverlay+'" class="overlay"></div>');
	
	$.ajax({
		type: 'GET',
		url: '/ws/fotos.php',
		contentType: 'application/json; charset=UTF-8',
		dataType: 'json',
		data: {id: gal_id},
		success: function(r){
			if(r.length > 0)
			{
				$('#'+idoverlay).overlay({
					mask: {
						color: '#000',
						loadSpeed: 200,
						opacity: 0.9
					},
					expose: {
						color: '#000',
						loadSpeed: 200,
						opacity: 0.9
					},
					top: 'center',
					fixed: false,
					api: true,
					oneInstance: false,
					onBeforeLoad: function(){
						$('#'+idoverlay).append('<div class="overlay_content"></div>');
						$('#'+idoverlay+' .overlay_content').html('<div class="galeria_titulo"></div><div class="foto_atual"></div><ul id="carousel_fotos" class="jcarousel-skin-fotos"></ul>');
						$('#'+idoverlay+' .overlay_content .galeria_titulo').append('<span class="gal_nome">'+gal_nome+'</span><span class="gal_cidade">'+gal_cidade+'</span><span class="gal_data">'+gal_data+'</span>');
					},
					onLoad: function(){
						var i = 0;
						while(i < r.length)
						{
							var f = r[i].foto;
							$('#carousel_fotos').append('<li><img src="/uploads/fotos/'+gal_id+'/'+f+'?w=120&h=90&c=2&cor=000&q=90" alt="/uploads/fotos/'+gal_id+'/'+f+'?w=617&h=460&c=2&cor=000&q=90"></li>');
							i++;
						}
						$('#carousel_fotos').jcarousel({
							vertical: true,
							scroll: 1,
							auto: 0,
							wrap: false
						});
						mostra_foto($('#carousel_fotos li:first-child img'));
						$('#carousel_fotos li img').click(function(){
							mostra_foto($(this));
						});
					},
					onClose: function(){
						$('#'+idoverlay).remove();
					}
				}).load();
			}
		}
	});
	
	var mostra_foto = function(elem)
	{
		$('#carousel_fotos li.atual').animate({opacity: 0.4},400);
		$('#carousel_fotos li').removeClass('atual');
		elem.parent().animate({opacity: 1},400);
		elem.parent().addClass('atual');
		$('.foto_atual').html('<img src="'+elem.attr('alt')+'" alt="">');
	}
}
*/
