﻿Form = {
	submit: function() {
		$("#aspnetForm").submit();
	}
}

Flash = {
	getMovie: function(movieName) {
		if (window.document[movieName]) {
			return window.document[movieName];
		}
		if (navigator.appName.indexOf("Microsoft Internet") == -1) {
			if (document.embeds && document.embeds[movieName])

				return document.embeds[movieName];
		}
		else
		{
			return document.getElementById(movieName);
		}
	}
}

Modal = {
    open: function(elem) {
        $('body')
			.append($('<div></div>')
				.attr('id','overlay')
			);
		
		$(elem)
			.css({
				top: ($(window).height()/2 + $(window).scrollTop())
			})
			.slideDown(function() {
			$('.fechar a',$(this)).unbind("click").click(function(e) {
				e.preventDefault();
				Modal.close(elem)
			});
		});
		$("form").unbind("submit");
    },
    close: function(elem) {
		$('div#overlay').remove();
    	$(elem).slideUp();
		return false;
    }
}

Comentario = {
	currentPage : 1,
	moreQtde: 10,
	initialize : function() {
		this.clear();
		this.currentPage = 1;
	},
	list: function(comentarios) {
		if(null != comentarios) {
			var lista = $('<ul></ul>');
			$.each(comentarios, function() {
				lista
					.append($('<li></li>')
						.append($('<h3></h3>')
							.text(this.NomeVisitante + " - " + this.Data))
						.append($('<p></p>')
							.text(this.Conteudo)));
			});
			$('.divScrollMural').html("").append(lista);
			this.applyScroll('.divScrollMural');
		}
		else {
			$('.divScrollMural').html('<p>Nenhum coment&#225;rio aprovado</p>');
		}
		$(".comentarios-loading", '#divConteudoMural').hide();
		
	},
	clear : function() {
		$('.divScrollMural').html("");
	},
	applyScroll: function(elem) {
		$(elem).jScrollPane({
			scrollbarWidth: 15,
			scrollbarMargin: 0,
			showArrows: true,
			dragMinHeight: 46,
			dragMaxHeight: 46,
			percentLoadMore: 0.95,
			onContentEnd : function(scroll, container) {

				$(".comentarios-loading").show();
				Comentario.currentPage++;
				
				var service = new ServiceUsers();
				var ret = service.paginar("APROVADO", Comentario.currentPage, Comentario.moreQtde);

				if(null != ret) {
					Comentario.list(ret);
				} else { Comentario.currentPage--; }
				
				$(".comentarios-loading").hide();
				
				setTimeout(function() {
					scroll.data('loadingMore',false);
				},1000);
			}
		});
	}
}

Analytics = {
	trackClick: function(elem) {
		pageTracker._trackPageview('/' + this.getCategory(elem) + '/' + elem.attr("href"));
	},
	getCategory: function(elem) {
		return elem.closest(".widget").attr("id")
	}
}