/*
 * 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-article').click(function (e) {
		e.preventDefault();
		// load the contact form using ajax
		$.get("/sites/chain/themes/chain/data/" + $(this).attr('href'), function(data){
			// create a modal dialog with the data
			$(data).modal({
				close: false,
				opacity:80,
				position: ["5%",],
				overlayId: 'contact-overlay',
				containerId: 'article-container',
				onOpen: article.open,
				onClose: article.close
			});
		});
	});
	
	$('.lightbox-article-image').click(function (e) {
		e.preventDefault();
		// load the contact form using ajax
		$.get("/sites/chain/themes/chain/data/" + $(this).attr('alt'), function(data){
			// create a modal dialog with the data
			$(data).modal({
				close: false,
				opacity:80,
				position: ["5%",],
				overlayId: 'contact-overlay',
				containerId: 'article-container',
				onOpen: article.open,
				onClose: article.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 article = {
	message: null,
	open: function (dialog) {
		//specify height	
		h=450;

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