﻿$(function() { // - on document-ready:

	// - i hate tables:
	$("table").attr({ cellpadding: 0, cellspacing: 0, border: 0 });

	document.fancybox = $.fancybox;
	document.jquery = $;

	$(".lightbox-link").each(function() {

		var boxheight = $(this).attr('boxheight');
		var boxwidth = $(this).attr('boxwidth');
		if (boxheight != undefined) {

			$(this).fancybox({

				overlayShow: true,
				titleShow: false,
				enableEscapeButton: true,
				hideOnOverlayClick: true,
				transitionIn: 'fade', speedIn: 600,
				transitionOut: 'fade', speedOut: 600,
				height: parseInt(boxheight),
				width: parseInt(boxwidth),
				type: 'iframe',

				onStart: function() {
					document.lightboxHeight = 0;
					document.lightboxComplete = false;
					document.lightboxReady = false;
				},

				onComplete: function() {

					if (document.lightboxComplete) return;

					document.lightboxComplete = true;
					document.lightboxAdjustHeight();
				}

			});
		}
	});

	document.lightboxAdjustHeight = function() {
		if (document.lightboxComplete && document.lightboxReady) {
			var h = document.lightboxHeight;
			$('#fancybox-inner').height(h);
			$('#fancybox-outer').animate({ height: h + 20 });
		}
	}

	$("#login-link").fancybox({
		href: '/Member/LoginForm',
		overlayShow: true,
		enableEscapeButton: true,
		hideOnOverlayClick: true,
		transitionIn: 'elastic', speedIn: 600,
		transitionOut: 'fade', speedOut: 600,
		type: 'iframe', height: 210, width: 540
	});

	$('#login-link').delay(100).fadeIn();
});

function clickLogout() {

	$.post("/Member/Logout", { logout: true },
		function(data, status) {
			if (data.success) {
				location.reload(true);
			} else {
				alert("error logging out");
			}
		},
	"json");
	return false;
}
//function lightboxMessage(text) {
//	$(".lightbox-message").html(text);
//}