/*	
	Regency Eventos
	www.regency.com.br

	por: M2BRNET (http://www.m2brnet.com)
\* ......................................................................................................................................... */

/*
	Namespace
\* ......................................................................................................................................... */

var M2 = {
	
	tabsAgenda : function ()
	{
		var tabContainers = $('.abas-conteudo .abas'),
			tabNav        = $('.abas-nav a');

		$(tabNav).click(function()
		{
		
		// Ocultar eventos anteriores
		$('#aba-proximos .eventos').hide();
		$('#aba-proximos .eventos:first').show();
		
		$('#aba-anteriores .eventos').hide();
		$('#aba-anteriores .eventos:first').show();			
		
			tabContainers.hide().filter(this.hash).show();
			$(tabNav).removeClass('active');
			$(this).addClass('active');
			return false;
		}).filter(':first').click();
	},
	
	setAnchors : function ()
	{
		$("a[href*=#]").click(function()
		{
			var target = $(this).attr("href");
			if (target == "#")
			{
				return false;
			} 
			else
			{
				var targetOffset = $(target).offset().top;
				$("html,body").animate({ scrollTop: targetOffset }, 400);
				return false;
			}
		});
	},
	
	validaEmail : function (s)
	{
		var regexpEmail = /\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
		return regexpEmail.test(s);
	},

	bannerHome : function ()
	{
		$("#banner-nav a:first").addClass("active");

		var imageWidth     = $("#banner-window").width(),
			imageSum       = $("#banner-images img").size() + $('#banner-images div').size(),
			imageReelWidth = imageWidth * imageSum;

		$("#banner-images").css({ 'width' : imageReelWidth });

		rotate = function()
		{
			var triggerID = $active.attr("rel") - 1;
			var image_reelPosition = triggerID * imageWidth;
	
			$("#banner-nav a").removeClass('active');
			$active.addClass('active');
			
			$("#banner-images").animate({ 
				left: -image_reelPosition
			}, 500 );
		}; 

		rotateSwitch = function()
		{
			play = setInterval(function(){
				$active = $('#banner-nav a.active').parent().next().children('a');
				if ( $active.length === 0) {
					$active = $('#banner-nav a:first');
				}
				rotate();
			}, 5000);
		};
		rotateSwitch();

		$("#banner-images img").hover(function() {
			clearInterval(play);
		}, function() {
			rotateSwitch();
		});	
	
		$("#banner-nav a").click(function() {	
			$active = $(this);
			clearInterval(play);
			rotate();
			rotateSwitch();
			return false;
		});
		
		// Ocultar eventos anteriores
		$('#aba-proximos .eventos').hide();
		$('#aba-proximos .eventos:first').show();
		
		$('#aba-anteriores .eventos').hide();
		$('#aba-anteriores .eventos:first').show();		
		
		$('.abas-conteudo .control li a').click(function(){		
			$('.abas-conteudo .eventos').hide();
			var ano = $(this).attr('href').replace('#','');							
			$('.' + ano ).show();
			return false;
		});

		
	},

	init : function () 
	{
		this.bannerHome();
		this.tabsAgenda();
		this.setAnchors();
	}	
}

/*
	DOM Loaded
\* ......................................................................................................................................... */

$(function(){

	

	M2.init();
	
	//$(".colorbox").colorbox();
	
	var urlFotos = 'lista_fotos.php';
	
	$("#ano_evento").change(function(){
		
		listaEventos( $( this ).val() );
	
	});
	
	listaEventos( $("#ano_evento:first").val() );
	
	function listaEventos( aid ){
	
		$.post( urlFotos, { act: 'eventos', data: aid }, function(d){
				
				$("#nome_evento").empty().append( d );
			
				var opt = $("#nome_evento").find('option:first');
			
				listaImagens( opt.val() );
			
		} );
	
	}
	
	
	function listaImagens( eid ){
	
		$.post( urlFotos, { eid: eid }, function(d){
		
			$('.listagem_galeria').empty().html( d );
			
			$(".colorbox").colorbox();
		
		});
	
	}
	
	$("#nome_evento").change(function(){
	
		listaImagens( $(this).val() );
	
	});
	
});

