jQuery(document).ready(function() {
	$.ajaxSetup({
		cache: false
	});


	// comment paging
	/*$('div#paging a').live('click', function(event) {
		if (event.type == 'click' && event.button != 0)
			return true;	// workaround for Firefox Bug

		$('#comments').load( baseUrl+'comment/show.php', {page: $(this).text()}, function() {
			$(window).scrollTo($("#comments"), 'fast');
		});

		return false;
	});*/

	// comment show fulltext
	$('div#comments a.showmore').live('click', function(event) {
		if (event.type == 'click' && event.button != 0)
			return true;	// workaround for Firefox Bug

		var parent = $(this).parent();
		parent.slideUp(100);
		parent.next().slideDown('fast');

		return false;
	});


	// submit a bet
	$("div#tippbox input[type=submit]").click(function(event) {
		if (event.type == 'click' && event.button != 0)
			return true;	// workaround for Firefox Bug

		$(this).hide();		// hide submit button and show loading gif
		$("div#tippbox img.loading").fadeIn(function() {
			$.post(baseUrl+'tipp/post.php', $("div#tippbox form").serializeArray(), function(data, textStatus, XMLHttpRequest) {
				if(data.error) {
					// error! display messages
					$.each(data.error, function(index, value) {
						$("input#"+value).attr("value", "0");
						$("input#"+value).addClass("error");
					});
					$("div#tippbox img.loading").fadeOut('fast', function() {
						$("div#tippbox input[type=submit]").blur().show();
					});
				}
				else {
					$("div#tippbox").html(data);
				}
			});
		});
		
		return false;
	});


	// invite a friend overlay
	$("#tipppage #leftText a[rel]").overlay({
		mask: 'white',
		onBeforeLoad: function() {
			var wrap = this.getOverlay().find(".contentWrap");
			wrap.load(this.getTrigger().attr("href"));
		}
	});

	// invite a friend submit form
	$("#overlay input[type=submit]").live('click', function(event) {
		if (event.type == 'click' && event.button != 0)
			return true;	// workaround for Firefox Bug

		$(this).hide();		// hide submit button and show loading gif
		$("div#overlay img.loading").fadeIn(function() {
			$.post(baseUrl+'invite/post.php', $("div#inviteFriends form").serializeArray(), function(data, textStatus, XMLHttpRequest) {
				if(data.error) {
					// error! display messages
					$.each(data.error, function(index, value) {
						$("input#"+value).addClass("error");
					});

					$("div#overlay img.loading").fadeOut('fast', function() {
						$("div#overlay input[type=submit]").blur().show();
					});
				}
				else
					$("div#overlay .contentWrap").load(baseUrl+'invite/', function() {
						$("div#overlay input.error").removeClass("error");
						$("div#overlay input[type=submit]").hide();
					});
			});
		});

		return false;
	});


	// send next email
	$("#overlay span.success a").live('click', function(event) {
		if (event.type == 'click' && event.button != 0)
			return true;	// workaround for Firefox Bug

		$("div#overlay input#his").attr("value", "");
		$("div#overlay span.success").hide();
		$("div#overlay input[type=submit]").show();

		return false;
	});




	// ergebniss page show details
	$("#ergebnisse_mid div.details a").toggle(function(event) {
		if (event.type == 'click' && event.button != 0)
			return true;	// workaround for Firefox Bug

		$(this).parent().next().next().slideDown();
		return false;
	}, function(event) {
		if (event.type == 'click' && event.button != 0)
			return true;	// workaround for Firefox Bug

		$(this).parent().next().next().slideUp();
		return false;
	});
});
