// JavaScript Document
$(document).ready(function(){
	//notificações
	$(".fecha").append('<a href="#" class="fechar">fechar</a>');
	$("a.fechar").click(function () {
		$(this).fadeTo(200, 0); // This is a hack so that the close link fades out in IE
		$(this).parent().fadeTo(200, 0);
		$(this).parent().slideUp(400);
		return false;
	});
	$(".fecha").fadeIn("slow");
	$(".esconder").delay(3000).fadeOut("slow");
	//label forms
	$("#cooperativa, #conta").example(function(){
  	return $(this).attr('title');
	}, {className: 'cinza2 fonte_2'});
	$("#cooperativa,#conta").click(function(){
		$(this).val("");
	});
	$("#news_email").example(function(){
  	return $(this).attr('title');
	}, {className: 'cinza2 fonte1'});
	$("#news_email").click(function(){
		$(this).val("");
	});
	$("#login").example(function(){
  	return $(this).attr('title');
	}, {className: 'cinza2 fonte_2'});
	$("#login").click(function(){
		$(this).val("");
	});
	$("#alterar_senha").click(function(){
		$("#form_senha").toggle('fast');
	});
	//validacao acesso conta
	$("#cooperativa").keypress(function(event) {
		if(event.which == 13) {
			$("#acesso").focus();
		}
	});
	$("#conta").keypress(function(event) {
		if (event.which == 13) {
			$("#acessar").click();
		}
	});
	$("#acesso").click(function(e) {
		var value = $("#conta").val();
		var coop = $("#cooperativa").val();
		if(coop.match(/^\d{4}$/) == null) {
			alert("Cooperativa inválida.");
			$("#cooperativa").val('');
			$("#cooperativa").focus();
			return false;
		}
		if(value.match(/^[a-zA-Z]{2}\d{4}$/)) {
			$("#acesso_conta_form").attr('action', 'https://empresarial.sicoobnet.com.br/instalador/appletJRE.jsp');
			$("#acesso_conta_form").submit();
		} else if (value.match(/^\d{2,10}$/)) {
			$("#cooperativa").attr('name', 'txtNumCooperativa');
			$("#conta").attr('name', 'txtNumContaCorrente');
			$("#acesso_conta_form").attr('action', 'https://ib.sicoobnet.com.br/inetbank/login.jsp');
			$("#acesso_conta_form").submit();
		} else {
			$("#acesso").focus();
			alert("Conta corrente ou chave de acesso inválida.");
			$("#conta").val('');
			$("#conta").focus();
			return false;
		}
	});

	//eventos
	$("#slides").bxSlider({auto:true, infiniteLoop: true, speed: 500, pause: 3500, auto_hover: true });
	//novidades
	$("#novidades").nivoSlider({
		animSpeed:700,
		pauseTime:10000,
		keyboardNav:true,
		pauseOnHover:true,
		directionNav:false,
		controlNav:true
	});
	//forms validacao
	if($('form.valida').size() > 0) {
		$('form.valida').validate({meta: "validar"});
		$(".telefone").setMask({ mask: '(99) 9999 9999' });
		$("form.jqtransform").jqTransform();
	}

	//fotos agencia
	if($('#foto_agencia').size() > 0) {
		$("#foto_agencia").galleria({
			autoplay: true,
			preload: 3,
			width: 300,
			height: 300,
			showInfo: false,
			showCounter: false,
			showImagenav: false,
			transition: 'fade',
			carousel: true,
			carouselFollow: true
		});
	}

	//lightbox
	$("a[rel^='galeria']").prettyPhoto({
		animation_speed: 'normal', /* fast/slow/normal */
		slideshow: 5000, /* false OR interval time in ms */
		autoplay_slideshow: true, /* true/false */
		opacity: 0.80, /* Value between 0 and 1 */
		show_title: true, /* true/false */
		allow_resize: true, /* Resize the photos bigger than viewport. true/false */
		default_width: 500,
		default_height: 344,
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'pp_default', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
		horizontal_padding: 20, /* The padding on each side of the picture */
		hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
		autoplay: true, /* Automatically start videos: True/False */
		modal: false, /* If set to true, only the close button will close the window */
		deeplinking: true, /* Allow prettyPhoto to update the url to enable deeplinking. */
		overlay_gallery: true, /* If set to true, a gallery will overlay the fullscreen image on mouse over */
		keyboard_shortcuts: true, /* Set to false if you open forms inside prettyPhoto */
		ie6_fallback: true,
		custom_markup: ''//,
		//social_tools: '<div class="pp_social"><div class="twitter"><a href="http://twitter.com/share" class="twitter-share-button" data-count="none">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class="facebook"><iframe src="http://www.facebook.com/plugins/like.php?locale=pt_BR&href='+location.href+'&amp;layout=button_count&amp;show_faces=true&amp;width=350&amp;action=like&amp;font&amp;colorscheme=light&amp;height=23" scrolling="no" frameborder="0" style="border:none; overflow:auto; width:350px; height:23px;" allowTransparency="true"></iframe></div></div>' /* html or false to disable */
	});
	//indicacao
	$("a[rel='indique']").prettyPhoto({
		animation_speed: 'fast', /* fast/slow/normal */
		slideshow: 5000, /* false OR interval time in ms */
		autoplay_slideshow: false, /* true/false */
		opacity: 0.80, /* Value between 0 and 1 */
		show_title: false, /* true/false */
		allow_resize: false, /* Resize the photos bigger than viewport. true/false */
		theme: 'pp_default', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
		horizontal_padding: 20, /* The padding on each side of the picture */
		hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
		autoplay: false, /* Automatically start videos: True/False */
		modal: false, /* If set to true, only the close button will close the window */
		deeplinking: true, /* Allow prettyPhoto to update the url to enable deeplinking. */
		overlay_gallery: true, /* If set to true, a gallery will overlay the fullscreen image on mouse over */
		keyboard_shortcuts: true, /* Set to false if you open forms inside prettyPhoto */
		ie6_fallback: true,
		custom_markup: '',
		social_tools: false
	});

	//forms noticias
	$("#link_depoimento").click(function(){
		$("#box_depoimentos").hide();
		$("#box_amigo").hide();
		$("#status_envio").empty();
		$("#box_depoimento").toggle("fast");
	});
	$("#link_amigo").click(function(){
		$("#box_depoimentos").hide();
		$("#box_depoimento").hide();
		$("#status_envio").empty();
		$("#box_amigo").toggle("fast");
	});
	$("#link_depoimentos").click(function(){
		$("#box_amigo").hide();
		$("#box_depoimento").hide();
		$("#box_depoimentos").toggle("fast");
	});

	//Indicação
	$("form#form_indicacao").submit(function() {
		$('form#form_indicacao').validate({meta: "validar"});
		var params = $(this.elements).serialize();
		var valido = $("form#form_indicacao").valid();
		if(!valido) {
			alert('Preencha o formulário.')
			return false;
		}
		else
		{
			$.ajax({
				dataType: 'html',
				data: params,
				type: 'POST',
				url: $("form#form_indicacao").attr('action'),
				success: function(msg){
					$("#box_amigo").hide();
					$("#status_envio").empty();
					$("#status_envio").append(msg);
				}
			});
		}
	 return false;
	});

	//Depoimento
	$("form#form_depoimento").submit(function() {
		var params = $(this.elements).serialize();
		$('form#form_depoimento').validate({meta: "validar"});
		var valido = $("form#form_depoimento").valid();
		if(!valido) {
			alert('Preencha o formulário.')
			return false;
		}
		else
		{
			$.ajax({
				dataType: 'html',
				data: params,
				type: 'POST',
				url: $("form#form_depoimento").attr('action'),
				success: function(msg){
					$("#box_depoimento").hide();
					$("#status_envio").empty();
					$("#status_envio").append(msg);
				}
			});
		}
	 return false;
	});
});
