var HOST         = 'http://chu.com.br/payment/';
var TIME_SLIDE   = 5000;

var TEMPO_EXIBICAO  = 5000;
var TEMPO_TRANSICAO = 400;

var PHOTOS = [{imagem : 'cidade1.jpg', texto : 'Maceió/AL'},
			  {imagem : 'cidade2.jpg', texto : 'Natal/RN'},
			  {imagem : 'cidade3.jpg', texto : 'Porto Alegre/RS'},
			  {imagem : 'cidade4.jpg', texto : 'Florianópolis/SC'},
			  {imagem : 'cidade5.jpg', texto : 'Fortaleza/CE'},
			  {imagem : 'cidade6.jpg', texto : 'Goiânia/GO'},
			  {imagem : 'cidade7.jpg', texto : 'Manaus/AM'},
			  {imagem : 'cidade8.jpg', texto : 'Rio de Janeiro/RJ'}];

function animation()
{
	$('#animation ul li').click(
		function() {

			// retira classe 'selected' do elemento selecionado
			$('.selected', '#animation ul').removeClass('selected');
		
			// adiciona classe ao elemento informado
			$(this).addClass('selected');
						
			// aplica animação
			/*
			$('#animation').animate(
				{'backgroundColor' : $('a', this).attr('rel')},
				{easing  :'swing',
				 duration:600}
			);
			*/
		}
	);

	slidesAnimation();
	setInterval("slidesAnimation()", TIME_SLIDE * PHOTOS.length);
}

function slidesAnimation() {
	for (x=0; x<PHOTOS.length; x++) {
		setTimeout("createSlide("+(x+1)+")", TIME_SLIDE*x);
	}	
}

function createSlide(id) {
	div = document.createElement('div');
	$(div).css({'background':'url('+HOST+'img/animation/'+PHOTOS[id-1].imagem+')', display:'none'}).addClass('waiting');
	$('#container #animation').append(div);
	/*
	$('#container #animation .slides').fadeOut('', 
		function(){
			$(this).remove();
			$('#container #animation .waiting').addClass('slides').removeClass('waiting').fadeIn();
		}
	);
	*/
	$('#animation .description-photo').animate(
		{bottom:-40},
		{easing  :'swing',
		 duration:200,
		 complete:
		 	function() {
				$(this).html(PHOTOS[id-1].texto);
			}
		}
	);
	$('#container #animation .slides').fadeOut('slow', 
		function() {
			$(this).remove();
		}
	);
	$('#container #animation .waiting').
		addClass('slides').
		fadeIn('slow',
			function() {
				$(this).removeClass('waiting');
			}
		);
	$('#animation .description-photo').animate(
		  {bottom:0},
		  {easing  :'swing',
		   duration:300}
	  );		
}

function showMessage() {
	showMessageIn();
	setTimeout("showMessageOut(); showMessage();", 10000);
}

function showMessageIn() {
	$('#animation .message').animate(
		  {right:10},
		  {easing  :'swing',
		   duration:500}
	);	
}

function showMessageOut() {
	$('#animation .message').animate(
		  {right:-340},
		  {easing  :'swing',
		   duration:300}
	);	
}


function executaSliderClientes(tipo) {
	if (tipo == 'show') {
		$('.clients-list li').not('.hide').each(
			function(i) {
				setTimeout("ocultaCliente('"+$(this).attr('rel')+"')", i*TEMPO_TRANSICAO);
			}
		);
	} else {
		$('ul li.hide').each(
			function(i) {
				setTimeout("exibeCliente('"+$(this).attr('rel')+"')", i*TEMPO_TRANSICAO);
			}
		);
	}
}

function ocultaCliente(obj) {
	console.log(obj);
	$('#client'+(2 - Number(obj))).fadeOut(
		'normal',
		function() {
			$('#client'+(Number(obj) + 5)).
				removeClass('hide')
				.fadeIn();
			$(this).addClass('hide');
			if (obj == 2) setTimeout("executaSliderClientes('hide');", TEMPO_EXIBICAO);
		}
	);
}

function exibeCliente(obj) {
	console.log(obj);
	$('#client'+(Number(obj)+5)).addClass('hide').fadeOut(
		'normal',
		function() {
			$('#client'+obj).removeClass('hide').fadeIn(
				'normal',
				function() {}
			);
		}
	);
	
	if (obj == 2) setTimeout("executaSliderClientes('show');", TEMPO_EXIBICAO);
}



function adjustFooter() {
	//$('#internal').css('height', $('#internal').height());
	
	altContainer = $('#container .border').height();
	$('#container .border-alpha').height(Number(altContainer + 20));
	posFooter = $('#footer').position().top - 124;
	$('#footerBg').width('100%').height(258).css({left:0, top:posFooter});	
}

function bloquearTela() {
	alt = ($('body').height() > document.documentElement.clientHeight)?$('body').height():document.documentElement.clientHeight;
	var configModal = {
		id      : 'divWaiting',
		width   : $('body').width(),
		height  : alt,
		classe  : 'modal-waiting'
	}
	$('body').loading(configModal);
}


function closeModal(modal) {
	closeWaiting = true;
	numModal     = 0;

	$('body .modal').each(
		function() {
			if ($(this).css('display') != 'none') {
				numModal++;
			}
		});
	if (numModal > 1) {
		closeWaiting = false;
	}

	/* se modal = lastModal, fecha modal */
	if ((modal == lastModal) || (lastModal == null) || ($('#'+lastModal).css('display') == 'none'))	{
		$('#' + modal).fadeOut('fast');
		lastModal = null;
	}

	if (closeWaiting == true) {
		$('#divWaiting').fadeOut('fast');
	} else {
		if ((jQuery.browser.msie === true) && (jQuery.browser.version < 7)) {
			$('#'+lastModal).stop().effect('highlight', {}, 1000);
		} else {
			$('#'+lastModal).stop().effect('bounce', {}, 50);
		}
	}
}

function popup(pagina,janela,w,h,rolagem,maxi) {
	
	lar = screen.width;
	alt = screen.height;
	
	if (maxi == '') maxi = 'no';
	if (rolagem == '') rolagem = 'no';
	
	var winDt = window.open(pagina,janela,'width='+w+',height='+h+',scrollbars='+rolagem+',toolbar=no,location=no,status=no,menubar=no,resizable='+maxi+',left='+((lar-w)/2)+',top='+((alt-h)/2)+'');
	
	winDt.focus();
	
}
