/*
 * SimpleBoxModal OSX Style BoxModal Dialog
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2010 Eric Martin - http://ericmmartin.com
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Revision: $Id: osx.js 238 2010-03-11 05:56:57Z emartin24 $
 */

jQuery(function ($) {
	var BoxModal = {
		container: null,
		init: function () {
			$("input.boxmodal, a.boxmodal").click(function (e) {
				e.preventDefault();	

				$("#box-modal-content").modal({
					overlayId: 'modal-overlay',
					containerId: 'modal-container',
					closeHTML: null,
					minHeight: 80,
					opacity: 65, 
					position: ['0',],
					overlayClose: true,
					onOpen: BoxModal.open,
					onClose: BoxModal.close
				});
			});
		},
		open: function (d) {
			var self = this;
			self.container = d.container[0];
			d.overlay.fadeIn('fast', function () {
				$("#box-modal-content", self.container).show();
				var title = $("#box-modal-title", self.container);
				title.show();
				d.container.slideDown('fast', function () {
					setTimeout(function () {
						var h = $("#box-modal-data", self.container).height()
							+ title.height()
							+ 20; // padding
						d.container.animate(
							{height: h}, 
							200,
							function () {
								$("div.close", self.container).show();
								$("#box-modal-data", self.container).show();
							}
						);
					}, 300);
				});
			})
		},
		close: function (d) {
			var self = this; // this = SimpleBoxModal object
			d.container.animate(
				{top:"-" + (d.container.height() + 20)},
				500,
				function () {
					self.close(); // or $.modal.close();
				}
			);
		}
	};
	var ConsultModal = {
			container: null,
			init: function () {
				$("input.consultmodal, a.consultmodal").click(function (e) {
					e.preventDefault();	

					$("#consult-modal-content").modal({
						overlayId: 'modal-overlay',
						containerId: 'modal-container',
						closeHTML: null,
						minHeight: 80,
						opacity: 65, 
						position: ['0',],
						overlayClose: true,
						onOpen: ConsultModal.open,
						onClose: ConsultModal.close
					});
				});
			},
			open: function (d) {
				var self = this;
				self.container = d.container[0];
				d.overlay.fadeIn('fast', function () {
					$("#consult-modal-content", self.container).show();
					var title = $("#consult-modal-title", self.container);
					title.show();
					d.container.slideDown('fast', function () {
						setTimeout(function () {
							var h = $("#consult-modal-data", self.container).height()
								+ title.height()
								+ 20; // padding
							d.container.animate(
								{height: h}, 
								200,
								function () {
									$("div.close", self.container).show();
									$("#consult-modal-data", self.container).show();
								}
							);
						}, 300);
					});
				})
			},
			close: function (d) {
				var self = this; // this = SimpleConsultModal object
				d.container.animate(
					{top:"-" + (d.container.height() + 20)},
					500,
					function () {
						self.close(); // or $.modal.close();
					}
				);
			}
		};
	var MapModal = {
			container: null,
			init: function () {
				$("input.mapmodal, a.mapmodal").click(function (e) {
					e.preventDefault();	

					$("#map-modal-content").modal({
						overlayId: 'modal-overlay',
						containerId: 'modal-container',
						closeHTML: null,
						minHeight: 80,
						opacity: 65, 
						position: ['0',],
						overlayClose: true,
						onOpen: MapModal.open,
						onClose: MapModal.close
					});
				});
			},
			open: function (d) {
				var self = this;
				self.container = d.container[0];
				d.overlay.fadeIn('fast', function () {
					$("#map-modal-content", self.container).show();
					var title = $("#map-modal-title", self.container);
					title.show();
					d.container.slideDown('fast', function () {
						setTimeout(function () {
							var h = $("#map-modal-data", self.container).height()
								+ title.height()
								+ 20; // padding
							d.container.animate(
								{height: h}, 
								200,
								function () {
									$("div.close", self.container).show();
									$("#map-modal-data", self.container).show();
								}
							);
						}, 300);
					});
				})
			},
			close: function (d) {
				var self = this; // this = MapModal object
				d.container.animate(
					{top:"-" + (d.container.height() + 20)},
					500,
					function () {
						self.close(); // or $.modal.close();
					}
				);
			}
		};
	
	
	MapModal.init();
	BoxModal.init();
	ConsultModal.init();

});
