

/**
zoom imagem
*/

function imageZoom( image){
	$("body").append('<div class="image-zoom"><img src="' + image + '" alt="Image Zoom"/></div>');
	$(".image-zoom").show();
	
	
	var w = 0;
	
	//qdo acabar de carregar
	$('.image-zoom img').load(function(){
		
			w = ($('.image-zoom').width() / 2);
		
			$(".image-zoom").css({
	
			'top' : '20px',
			'left':'50%',
			'margin-left' : '-' + w + 'px'
		
	
		});
		
	
	});
	
	
	
	
	
	
	 $("body").click(function(){
     	$(".image-zoom").remove();
     });
	




}



/**
ativa animacao da home
*/
function animaGaleria(){
    $('#conteudo').css('background','black');

    $('#galeria_master').cycle({
        fx: 'fade',
        speed: 1000,
        timeout:4000
    });
}



/**
	botao compartilhar orkut
*/



/*
	cria uma paginacao de elementos

*/

function paginacao( element, pager, size , pageCurrent, openTag, closeTag){
	
	if(!size)
		return;
	
	var total = $(element + " > *").length
	
	var pages = Math.ceil(total / size);
	
	
	/*
		cria numero de paginas
	*/
	
	$(pager).empty();
	for(var i= 1; i<= pages; i++)
		$(pager).append(
			openTag + '<a href="javascript: paginacao(\'' + element +'\', \'' + pager +'\', ' + size +', ' + i +', \'' + openTag +'\', \'' + closeTag + '\');" title="Ir para página ' + i + '">' + i + '</a>' + closeTag
		);
	
	/*
		ativa página atual
	*/	
	$(pager + ' > * ').eq(pageCurrent -1).attr('id', 'current');
	
	$(element + '> *').hide();
	
	
	/*
		exibe os elementos corretos
	*/
	var start = (pageCurrent == 1)? 0 : (pageCurrent * size) - size;
	
	
	for(var i= start; i< (pageCurrent * size); i++)
		$(element + "> *").eq(i).show();
}



/*

	atualiza os dias da agenda
*/

function addZero( num ){

	num = parseInt(num);
	
	if(num <= 9)
		num = '0' + num;

	return num;


}	


function agenda( param ){
		
		
		param = param.split('-');
		
		var y = parseInt(param[0]);
		var m = parseInt(param[1]) -1;//subtraio 1 pois mes em js começa em 0
		var d= parseInt(param[2]);
		var w = Array('domingo','segunda', 'terça', 'quarta', 'quinta', 'sexta', 'sábado');
		var mD = Array('jan', 'fev', 'mar', 'abr', 'mai', 'jun', 'jul', 'ago', 'set', 'out', 'nov', 'dez');
		var date = null;
		var hoje = new Date();
		

		
			
		
		
		//remove os dias
		$("#agendaEventos #days li").not('#back, #next, #monthNext, #monthBack').remove();
		
		
		//atualiza o mês e ano inicial		
		$("#monthBack .month").text( mD[m] );
		$("#monthBack .year").text( y );
		
		//crio o link para voltar
		date = new Date(y, m, d - 7);
		
	
		
	
		
		$("#agendaEventos #days #back a").attr('href', 'javascript:agenda(\'' + date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate() + '\')');
		
		
		//percorro 1 semana
		for(var i= 0; i<7; i++){
			
			//Y-m-d
			date = new Date( y, m , (d + i));
			
			$("#agendaEventos #days #next").before('<li><a href="/agenda/evento/' + date.getFullYear() + addZero((date.getMonth() + 1)) + addZero(date.getDate()) + '" title = "Ver eventos do dia: ' + date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear() + '" >' + w[date.getDay()] + ' <strong>' + addZero(date.getDate()) + '</strong></a></li>');
								
		}
		
		
		/*
			proximos
		*/
		
		date = new Date(y, m, (d +i));
		//corrigo os links		
		$("#agendaEventos #days #next a").attr('href', 'javascript:agenda(\'' + date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + '\')');

		//atualiza o mês e ano final
		
		$("#monthNext .month").text( mD[ date.getMonth()] );
		$("#monthNext .year").text( date.getFullYear() );
		
		
		
	
	
}





/*
	troca uma imagem
*/


function trocaImagem( element, src){
	$(element).attr('src', src);

}



//orkut
google.load('orkut.share', '1');

$(document).ready(function(){

   
    //animacao nomes das paginas de ambientes
    setTimeout(function(){ $('#nome_pag h2').animate({'font-size':'14px'},1000) }, 1000);
   	
   	//animacao da agenda
   	$('#eventsTrans ul ').cycle({
        fx: 'fade',
        speed: 4000,
        timeout:1000
    });

     
     
    //paginacoes das galerias de imagens 
    paginacao('.imagem', '#pagina', 4, 1, '', ''); 
    paginacao('#albumThumbs #thumbs', '#albumThumbs #pagination', 8, 1, '<li>', '</li>');
    paginacao("#infos_center > #albumOlds", '#infos_center #paginationAlbuns ul', 3, 1, '<li>', '</li>');
     
     
     
     
  
     
 	//	troca o background dos ambientes   
    $(".imagem a").click(function(){
     	
     	$('#loading').fadeIn('fast');
     		
     	$('img').load(function(){
     			$("#loading").fadeOut('fast');
     	});
    	trocaImagem("#galeria_master img" , $(this).attr('href') );
     	
     	return false;
     
    });
     
     
    
     $("#albumThumbs #thumbs li a").click(function(){
     		
     		$("#loading").show();
     	
     		
     		
     		
     		var location = "http://www.billbar.com.br" + $(this).attr('href');
     		
  
     		
     		
     		
     		$('#albumMaster > img').load(function(){
     		
     			 //troca a url do iframe facebook
     			$(".actions .curtir iframe").attr('src', 'http://www.facebook.com/plugins/like.php?href=www.billbar.com.br' +  ($(this).attr('href'))+'&layout=button_count&show_faces=false&width=100&action=like&colorscheme=light&height=21');
     	
     			//troco o frame do twitter :D
     	
     			$(".actions .tweet iframe").attr('src', 'http://platform0.twitter.com/widgets/tweet_button.html?count=horizontal&lang=en&text=' +($('title').text()) + '&url=http://billbar.com.br' + ($(this).attr('href')) + '&via=BillBarGramado');
     			
     			//troco orkut
     			
     			$("#orkut_share").empty();
     			
     			var texto = $('.titleWithBackLarge').text() + ' - Foto no Evento';
     			var img = 'http://www.billbar.com.br' + $('#albumMaster > img').attr('src');
     			
     			
     			    			
     			
     			
     			new google.orkut.share.Button({
									
					style:'regular',
					title:'Bill Bar - Álbum de fotos',
					summary: texto ,
					thumbnail: img,
					destination: location
									
				}).draw('orkut_share');
     		
     			$("#loading").hide();
     			
     			
     		});
     		
     		
     	
     	});
   
     
     
     
    
     // gambizinha pra subtituir o target='_blank' já que a w3c depreciou-o
     $(".blank").click(function(){
     	
     	window.open($(this).attr('href'));
     	
     	return false;
     	
     });
     
    
     
     
     
     //flyer
     
     $("#flyer a").click(function(){
     
     	
     
     	imageZoom($(this).attr('href'));
     	
     	return false;
     
     });
     	

  
        
    
   
   

    
});



