/*
 * SimpleModal Contact Form
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2009 Eric Martin - http://ericmmartin.com
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Revision: $Id: contact.js 185 2009-02-09 21:51:12Z emartin24 $
 *
 */

$(document).ready(function () {
	$('.lightbox-image').click(function (e) {
		e.preventDefault();
		// load the contact form using ajax
		var data = '<div style="display:none"><div class="contact-content" style="display:none"><div align="center">';
		data += '<table cellpadding="0" cellspacing="0" border="0"><tr><td colspan="3">';
		data += '<img src="/themes/chain/data/' + $(this).attr('alt') + '" />';
		data += '</td></tr><tr><td class="lightbox-bottom-left" width="1%">&nbsp;</td><td align="right" style="background-color:#8d181f">';
		data += '<a href="#" title="Close" class="simplemodal-close" style="color:#ffffff;text-decoration:none">CLOSE</a>';
		data += '</td><td class="lightbox-bottom-right" width="1%">&nbsp;</td></tr></table>';
		data += '</div></div></div>';
		$(data).modal({
			close: false,
			opacity:80,
			position: ["15%",],
			overlayId: 'contact-overlay',
			containerId: 'lightbox-container',
			onOpen: lightbox.open,
			onClose: lightbox.close
		});
	});

	// preload images
	var img = ['cancel.png', 'form_bottom.gif', 'form_top.gif', 'loading.gif', 'send.png'];
	$(img).each(function () {
		var i = new Image();
		i.src = 'img/contact/' + this;
	});
});

var lightbox = {
	message: null,
	open: function (dialog) {
		//specify height	
		h=450;

		var title = $('#lightbox-container .article-title').html();
		$('#lightbox-container .article-title').html('Loading...');
		dialog.overlay.fadeIn(200, function () {
			dialog.container.fadeIn(200, function () {
				dialog.data.fadeIn(200, function () {
					$('#lightbox-container .contact-content').animate({
						height: h
					}, function () {
						$('#lightbox-container .article-title').html(title);
						$('#lightbox-container form').fadeIn(200);
					});
				});
			});
		});
	},
	close: function (dialog) {
		$('#lightbox-container .contact-message').fadeOut();
		$('#lightbox-container ').fadeOut(200);
		$('#lightbox-container .contact-content').animate({
			height: 40
		}, function () {
			dialog.data.fadeOut(200, function () {
				dialog.container.fadeOut(200, function () {
					dialog.overlay.fadeOut(200, function () {
						$.modal.close();
					});
				});
			});
		});
	}
};