/* ------------------------------------------------------------------------------------------ */
/* jQuery */
$(document).ready(function() {
	
	/* jQuery - Scrolling do Álbum de Fotos */
	jQuery.easing.easeOutQuart = function(x, t, b, c, d) {
		return -c * ((t = t / d - 1) * t * t * t - 1) + b;
	};

	jQuery(function($) {

		/* Banners maiores */
		$("#slider").easySlider({
			auto: true
		});

		// Álbum de Fotos
		$('#screen').serialScroll({
			target: '#sections',
			items: 'li', // Selector to the items ( relative to the matched elements, '#sections' in this case )
			prev: 'img.prev', // Selector to the 'prev' button (absolute!, meaning it's relative to the document)
			next: 'img.next', // Selector to the 'next' button (absolute too)
			axis: 'x', // The default is 'y' scroll on both ways
			navigation: '#navigation li a',
			duration: 700, // Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
			force: true, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)

			//queue:false,// We scroll on both axes, scroll both at the same time.
			//event:'click',// On which event to react (click is the default, you probably won't need to specify it)
			//stop:false,// Each click will stop any previous animations of the target. (false by default)
			//lock:true, // Ignore events if already animating (true by default)		
			//start: 0, // On which element (index) to begin ( 0 is the default, redundant in this case )		
			//cycle:true,// Cycle endlessly ( constant velocity, true is the default )
			//step:1, // How many items to scroll each time ( 1 is the default, no need to specify )
			//jump:false, // If true, items become clickable (or w/e 'event' is, and when activated, the pane scrolls to them)
			//lazy:false,// (default) if true, the plugin looks for the items on each event(allows AJAX or JS content, or reordering)
			//interval:1000, // It's the number of milliseconds to automatically go to the next
			//constant:true, // constant speed

			onBefore: function(e, elem, $pane, $items, pos) {
				/**
				* 'this' is the triggered element 
				* e is the event object
				
				
				* elem is the element we'll be scrolling to
				* $pane is the element being scrolled
				* $items is the items collection at this moment
				* pos is the position of elem in the collection
				* if it returns false, the event will be ignored
				*/
				//those arguments with a $ are jqueryfied, elem isn't.
				e.preventDefault();
				if (this.blur)
					this.blur();
			},
			onAfter: function(elem) {
				//'this' is the element being scrolled ($pane) not jqueryfied
			}
		});

		// Fotos Notícias
		$('#screenInicialNoticias').serialScroll({
		target: '#sectionsInicialNoticias',
			items: 'li', // Selector to the items ( relative to the matched elements, '#sections' in this case )
			prev: 'img.prev', // Selector to the 'prev' button (absolute!, meaning it's relative to the document)
			next: 'img.next', // Selector to the 'next' button (absolute too)
			axis: 'x', // The default is 'y' scroll on both ways
			navigation: '#navigation li a',
			duration: 700, // Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
			force: true, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)

			//queue:false,// We scroll on both axes, scroll both at the same time.
			//event:'click',// On which event to react (click is the default, you probably won't need to specify it)
			//stop:false,// Each click will stop any previous animations of the target. (false by default)
			//lock:true, // Ignore events if already animating (true by default)		
			//start: 0, // On which element (index) to begin ( 0 is the default, redundant in this case )		
			//cycle:true,// Cycle endlessly ( constant velocity, true is the default )
			//step:1, // How many items to scroll each time ( 1 is the default, no need to specify )
			//jump:false, // If true, items become clickable (or w/e 'event' is, and when activated, the pane scrolls to them)
			//lazy:false,// (default) if true, the plugin looks for the items on each event(allows AJAX or JS content, or reordering)
			interval:7000, // It's the number of milliseconds to automatically go to the next
			//constant:true, // constant speed

			onBefore: function(e, elem, $pane, $items, pos) {
				/**
				* 'this' is the triggered element 
				* e is the event object
				
				
				* elem is the element we'll be scrolling to
				* $pane is the element being scrolled
				* $items is the items collection at this moment
				* pos is the position of elem in the collection
				* if it returns false, the event will be ignored
				*/
				//those arguments with a $ are jqueryfied, elem isn't.
				e.preventDefault();
				if (this.blur)
					this.blur();
			},
			onAfter: function(elem) {
				//'this' is the element being scrolled ($pane) not jqueryfied
			}
		});
	});
});



/* ------------------------------------------------------------------------------------------ */
/* Função para exibir fotos do álbum */
var fotoAtual = 1;
var idSrc = "";
var idDesc = "";
var imgSrc = "";
var imgDesc = "";

function vizualizaFoto(direcao) {
	if (direcao == "proxima") {
		if (fotoAtual < qtdeFotos)
			fotoAtual++;
		else {
			fotoAtual = 1;
			alert("Você será redirecionado ao início do álbum!");
		}
	}
	else {
		if (fotoAtual >= 2)
			fotoAtual--;
		else {
			fotoAtual = qtdeFotos;
			alert("Você será redirecionado ao final do álbum!");
		}
	}

	idSrc = "imgSrc_" + fotoAtual;
	idDesc = "imgDesc_" + fotoAtual;
	imgSrc = "<img id='imgPrimeiraFoto' class='imgPrimeiraFoto' src='" + document.getElementById(idSrc).value + "' style='border-width:1px;border-style:Solid;' />";
	imgDesc = "<input name='lblTextoFoto' type='text' value='" + document.getElementById(idDesc).value + "' id='lblTextoFoto' style='width:100%;text-align:center;border:0;background-color:#f0f0f0' />";

	document.getElementById("exibeFoto").innerHTML = imgSrc;
	document.getElementById("exibeDescricao").innerHTML = imgDesc;
}

function exibeFoto(url, texto, numFotoAtual) {
	document.getElementById('imgPrimeiraFoto').src = url;
	document.getElementById('lblTextoFoto').value = texto;
	fotoAtual = parseInt(numFotoAtual);
}

/* ------------------------------------------------------------------------------------------ */
/* Função para esconder/exibir links do menu principal */
function abreMenu(id) {
   /* document.getElementById('menu_itens_1').style.display = "none";
    document.getElementById('menu_itens_1_mais').style.display = "block";

    document.getElementById('menu_itens_2').style.display = "none";
    document.getElementById('menu_itens_2_mais').style.display = "block";

	document.getElementById(id).style.display = "";
	document.getElementById(id + '_mais').style.display = "none";
	*/
}


/* ------------------------------------------------------------------------------------------ */
/* Função para esconder/exibir elementos*/
function showHide(id) {
	var obj;
	obj = new Object();
	obj = document.getElementById(id);
	if(obj.style.display == "none")
		obj.style.display = "";
	else
		obj.style.display = "none";
}

/* ------------------------------------------------------------------------------------------ */
/* Função para Abris Janelas pop-up centralizadas */
function AbreJanela(url, altura, largura, top, left) {
    top = ((top / 2) - (altura / 2));
    left = ((left / 2) - (largura / 2));
    window.open(url, altura, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, menubar=no, top=' + top + ', left=' + left + ', width=' + largura + ', height=' + altura);
}


/* ------------------------------------------------------------------------------------------ */
/* Função Exibir Div's */
function show(id) {
	document.getElementById(id).style.display = "block";
}

/* ------------------------------------------------------------------------------------------ */
/* Função Esconder Div's */
function hide(id) {
	document.getElementById(id).style.display = "none";
}
/* ------------------------------------------------------------------------------------------ */
/* Função Exibir e Esconder Div's */
function ExibirEsconder(nAtual, total, nome) {
    for (i = 1; i <= total; i++) {
        if (nAtual == i) {
            objeto = document.getElementById(nome + i).style.display = "block";
        }
        else {
            document.getElementById(nome + i).style.display = "none";
        }
    }
}

/* ------------------------------------------------------------------------------------------ */
/* Mascara para Data */
function mascara_data(e, data) {
	if (window.event) {
		_TXT = e.keyCode;
	}
	else
		if (e.which) {
		_TXT = e.which;
	}
	if (_TXT > 47 && _TXT < 58) {
		var mydata = '';
		mydata = mydata + data.value;
		if (mydata.length == 2) {
			mydata = mydata + '/';
			data.value = mydata;
		}
		if (mydata.length == 5) {
			mydata = mydata + '/';
			data.value = mydata;
		}
		return true;
	}
	else {
		if ((_TXT != 8) && (_TXT != 13) && (_TXT != 14) && (_TXT != undefined)) {
			return false;
		}
		else {
			return true;
		}
	}
}

/* ------------------------------------------------------------------------------------------ */
/* Mensagem de confirmação */
function confirma(msg, url) {
	if (confirm(msg) == true) {
		document.location = url;
	}
	return false;
}