/*
 * SimpleModal Contact Form
 * 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: contact.js 254 2010-07-23 05:14:44Z emartin24 $
 */

jQuery(function ($) {
	var contact = {
		init: function () {
			$('a.popup_terms').click(function (e) {
				e.preventDefault();

				// load the login form using ajax
				$.get("terms_popup.php", function(data){
					// create a modal dialog with the data
					$(data).modal({
						closeHTML: "<a href='#' title='Close' class='modal-close'>x</a>",
						position: ["5%",],
						overlayId: 'contact-overlay',
						containerId: 'wide-container',
						onOpen: contact.open,
						onClose: contact.close
					});
				});
			});


		},
		open: function (dialog) {
			// set width of lightbox - override what is in stylesheet
				$('#wide-container').css({
					'width': '750px'
				});

			// height of box
			var h = 570;

			var title = $('#wide-container .contact-title').html();
			$('#wide-container .contact-title').html('Loading...');
			dialog.overlay.fadeIn(200, function () {
				dialog.container.fadeIn(200, function () {
					dialog.data.fadeIn(200, function () {
						$('#wide-container .contact-content').animate({
							height: h
						}, function () {
							$('#wide-container .contact-title').html(title);
							$('#wide-container form').fadeIn(200, function () {
								$('#wide-container #contact-name').focus();
								
								/* when enter email_address, put focus on password input field */
								$('#email_address').change(function() {  $('#password').focus();});

								$('#wide-container .contact-cc').click(function () {
									var cc = $('#wide-container #contact-cc');
									cc.is(':checked') ? cc.attr('checked', '') : cc.attr('checked', 'checked');
								});

								// fix png's for IE 6
								if ($.browser.msie && $.browser.version < 7) {
									$('#wide-container .contact-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) {
			$('#wide-container .contact-content').animate({
//				height: 40
			}, function () {
				dialog.data.fadeOut(200, function () {
					dialog.container.fadeOut(200, function () {
						dialog.overlay.fadeOut(200, function () {
							$.modal.close();
						});
					});
				});
			});
		}
	};

	contact.init();

});
