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

$(document).ready(function () {
	$('#infoForm input.info, #infoForm a.info').click(function (e) {
		e.preventDefault();
		// load the info form using ajax
		$.get("data/info.php", function(data){
			// create a modal dialog with the data
			$(data).modal({
				close: false,
				position: ["15%",],
				overlayId: 'info-overlay',
				containerId: 'info-container',
				onOpen: info.open,
				onClose: info.close
			});
		});
	});

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

var info = {
	message: null,
	open: function (dialog) {
		// add padding to the buttons in firefox/mozilla
		if ($.browser.mozilla) {
			$('#info-container .info-button').css({
				'padding-bottom': '2px'
			});
		}
		// input field font size
		if ($.browser.safari) {
			$('#info-container .info-input').css({
				'font-size': '.9em'
			});
		}

		// dynamically determine height
		var h = 250;
		if ($('#info-subject').length) {
			h += 26;
		}
		if ($('#info-cc').length) {
			h += 22;
		}

		var title = $('#info-container .info-title').html();
		$('#info-container .info-title').html('Loading...');
		dialog.overlay.fadeIn(200, function () {
			dialog.container.fadeIn(200, function () {
				dialog.data.fadeIn(200, function () {
					$('#info-container .info-content').animate({
						height: h
					}, function () {
						$('#info-container .info-title').html(title);
						$('#info-container form').fadeIn(200, function () {				
							// fix png's for IE 6
							if ($.browser.msie && $.browser.version < 7) {
								$('#info-container .info-button').each(function () {
									if ($(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+$/i)) {
										var src = RegExp.$1;
										$(this).css({
											backgroundImage: 'none',
											filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' +  src + '", sizingMethod="crop")'
										});
									}
								});
							}
						});
					});
				});
			});
		});
	},
	close: function (dialog) {
		$('#info-container .info-message').fadeOut();
		$('#info-container .info-title').html('Closing...');
		$('#info-container form').fadeOut(200);
		$('#info-container .info-content').animate({
			height: 40
		}, function () {
			dialog.data.fadeOut(200, function () {
				dialog.container.fadeOut(200, function () {
					dialog.overlay.fadeOut(200, function () {
						$.modal.close();
					});
				});
			});
		});
	},
	error: function (xhr) {
		alert(xhr.statusText);
	}
};