$().ready(function() {
	//alinhamento();
	menu();
	login();
	link_top();
	accordion();
	galeria();
});

function alinhamento() {
	var tot;

	setInterval(function() {
		if($('#left .cont').outerHeight() > $('#right .cont').outerHeight()) {
			tot = $('#left .cont').outerHeight();
		} else {
			tot = $('#right .cont').outerHeight();
		}

		$('#left .cont').css('min-height', tot + 'px');
		$('#right .cont').css('min-height', tot + 'px');
	}, 100);
}

function menu() {
	$('#menu>li').hover(function() {
		$(this).addClass('select');

		$('>ul', this).stop(false, true).fadeIn(500);
	}, function() {
		$(this).removeClass('select');

		$('>ul', this).stop(false, true).fadeOut(250);
	});
}

function login() {
	var dl = $('#login');

	$('.aba', dl).hide();

	$('#lembrarsenha', dl).hide();

	$('>a', dl).bind('click', function() {
		$('#lembrarsenha', dl).hide();
		$('#logar', dl).show();

		if($(dl).hasClass("select")) {
			$('.aba', dl).stop(false, true).fadeOut(250).parent().removeClass('select');

			$('.aba #log_email', dl).val('');
			$('#palavra').focus();
		} else {
			$('.aba', dl).stop(false, true).fadeIn(250).parent().addClass('select');

			$('.aba #log_email', dl).val('').focus();
		}

		return false;
	});

	$('.aba .lembrarsenha', dl).bind('click', function() {
		$('#logar', dl).slideUp(250);
		$('#lembrarsenha', dl).slideDown(250);
		$('#enviar_ace', dl).val('2');
		$('#sen_email', dl).val('').focus();
	});

	$('.aba .logar', dl).bind('click', function() {
		$('#lembrarsenha', dl).slideUp(250);
		$('#logar', dl).slideDown(250);
		$('#enviar_ace', dl).val('1');
		$('#log_email', dl).val('').focus();
		$('#log_senha', dl).val('');
	});

	$('.aba .link_open', dl).bind('click', function() {
		$('#form_login', dl).attr('action', $(this).attr('href')).submit();
	});

	$('.aba>form>div>div>button', dl).bind('click', function() {
		var er;

		if($('#enviar_ace', dl).val() == 1) {
			if((!er) && ($('#log_email', dl).val() == "")) {
				er = true;
				$('#log_email', dl).focus();
			}

			if((!er) && ($('#log_senha', dl).val() == "")) {
				er = true;
				$('#log_senha', dl).focus();
			}
		}

		if($('#enviar_ace', dl).val() == 2) {
			if((!er) && ($('#sen_email', dl).val() == "")) {
				er = true;
				$('#sen_email', dl).focus();
			}
		}

		if(!er) {
			$('#form_login', dl).submit();
		}
	});

	$('.aba *', dl).bind('click', function() {
		return false;
	});

	$(document).click(function() {
		$('.aba', dl).stop(false, true).fadeOut(250).parent().removeClass('select');
	});
}

function link_top() {
	$('body').css('backgroundColor', '#3A5D93');

	$('.link_top').click(function() {
		$.scrollTo(0, 800, {queue:true});

		return false;
	});
}

function accordion() {
	$(".accordion .texto").hide();

	$(".accordion h3 a").click(function() {
		if($(this).attr("class") == "abre") {
			$(".accordion .texto").slideUp(250);
			$(".accordion h3 a").removeClass("fecha").addClass("abre");

			$(this).parent().parent().find('.texto').slideDown(250);
			$(this).removeClass("abre").addClass("fecha");
		} else if($(this).attr("class") == "fecha") {
			$(this).parent().parent().find('.texto').slideUp(250);
			$(this).removeClass("fecha").addClass("abre");
		}

		return false;
	});

	$(".accordion h3 a.fecha").parent().parent().find('.texto').show();
}

function galeria() {
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animation_speed: 'fast',
		slideshow: 5000,
		autoplay_slideshow: false,
		opacity: 0.80,
		show_title: true,
		default_width: 640,
		default_height: 480,
		counter_separator_label: ' de ',
		theme: 'facebook',
		hideflash: false,
		overlay_gallery: true,
		keyboard_shortcuts: true
	});
}

function showpresence(presence) {
	if(document.getElementById('atendimento_msn')) {
		if(presence.statusText == 'Offline') {
			$("#atendimento_msn").html("<a href=\"?menu=contato\"><span>Atendimento</span><br />OFF-LINE</a>");
		} else {
			$("#atendimento_msn").html("<a href=\"?menu=contato&sub=atendimento_msn\"><span>Atendimento</span><br />ON-LINE</a>");
		}
	}
}

