$(function(){
	
	// Marca a cidade principal gravada no cookie
	/*var cidadePrincipal = $.cookie('emercorCidade');
	$("#box-" + cidadePrincipal).show();
	$("#city-selector select [value='"+ cidadePrincipal +"']").attr("selected","selected");*/
	
	// Seletor de cidades
	/*$("#city-selector select").change(function(){
		var cidade = $(this).attr("value");
		$(".box-city").hide();
		$.cookie('emercorCidade', cidade);
		$("#box-" + cidade).show();
	});*/
	
	// faz o box de noticias clicavel por inteiro
	$("div.news").click(function(e){
		location.href = $(this).find("a").attr("href");
	})
	
	// seletor de eventos
	$("#calendar a").hover(
		function(){
			var box = $(this).attr("href");
			var offset = $(this).offset()
			var height = $(box).height()
			$(box).css({
				"top": offset.top - (height / 2),
				"left": offset.left + 25
			})
			$(box).fadeIn(150);
		},
		function(){
			var self = this
			setTimeout(function() {
				var box = $(self).attr("href");
				$(box).fadeOut(150);
			}, 1000)
		}
	);
	
	$("h3.plano").click(function() {
		$(this).next().toggle(150)
	})
	
	$("h3.plano + div").hide()
	
	$(".servico p").hide()
	$(".servico h2").click(function(){
		$(this).next("p").slideToggle("slow");
		if($(this).css("marginTop") == "40px"){
			$(this).animate({"marginTop": "0px"}, "slow")
		} else {
			$(this).animate({"marginTop": "40px"}, "slow")
		}
	});
    
    $("textarea[name=title]").NobleCount(".noblecount", {
	    max_chars: 500,
	    block_negative: true
	});
	
	$("input[name=event_city_other]").parent().hide();
	$("select[name=event_city]").change(function(){
	    if($(this).val() == "other") {
	        $("input[name=event_city_other]").parent().fadeIn();
	    } else {
	        $("input[name=event_city_other]").parent().fadeOut();
	    }
	});
	
	$("input[name=event_structure_other]").parent().hide();
	$("select[name=event_structure]").change(function(){
	    if($(this).val() == "other") {
	        $("input[name=event_structure_other]").parent().fadeIn();
	    } else {
	        $("input[name=event_structure_other]").parent().fadeOut();
	    }
	});
	
	var dependent_count = 1;
	$(".dependents").show();
	$("a.add-dependent").click(function(e){
	    var template = $(".dependenttemplate");
	    var newDependent = template.clone().removeClass("dependenttemplate").addClass("dependent");
	    dependent_count++;
	    $("h4", newDependent).text("Dados do dependente " + dependent_count);
	    $(".dependents").append(newDependent);
	    e.preventDefault();
	});
	
});
