jQuery(document).ready(function () {
	jQuery('.ContactPopUp').click(function (e) {
		e.preventDefault();
		// load the contact .form using ajax
		jQuery.get("/data/contact1.html", function(data){
			// create a modal dialog with the data
			jQuery(data).modal({
				closeHTML: "<a href='#' title='Close' class='modalCloseX simplemodal-close'>x</a>",
				position: ["15%",],
				overlayId: 'contact-overlay',
				containerId: 'contact-container',
				onOpen: contact.open,
				onShow: contact.show,
				onClose: contact.close
			});
		});
	});

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

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

		// dynamically determine height
		
		var title = jQuery('#contact-container .contact-title').html();
		jQuery('#contact-container .contact-title').html('Loading...');
		jQuery(".TableFeed").addClass("TableFeedBg");
		dialog.overlay.fadeIn(200, function () {
			dialog.container.fadeIn(200, function () {
				dialog.data.fadeIn(200, function () {
					jQuery('#contact-container .contact-content').animate({
						height: 484
					}, function () {
						jQuery('#contact-container .contact-title').html(title);
						jQuery('#contact-container .form').fadeIn(200, function () {
							jQuery('#contact-container #contact-name').focus();

							
							// fix png's for IE 6
							if (jQuery.browser.msie && jQuery.browser.version < 7) {
								jQuery('#contact-container .contact-button').each(function () {
									if (jQuery(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+jQuery/i)) {
										var src = RegExp.jQuery1;
										jQuery(this).css({
											backgroundImage: 'none',
											filter: 'progid:DXImageTrans.form.Microsoft.AlphaImageLoader(src="' +  src + '", sizingMethod="crop")'
										});
									}
								});
							}
						});
					});
				});
			});
		});
	},
	close: function (dialog) {
	
		jQuery('#contact-container .contact-message').fadeOut();
		jQuery('#contact-container .contact-title').html('Goodbye...');
		jQuery('#contact-container .form').fadeOut(200);
		jQuery('#contact-container .contact-content').animate({
			height: 40
		}, function () {
			dialog.data.fadeOut(200, function () {
				dialog.container.fadeOut(200, function () {
					dialog.overlay.fadeOut(200, function () {
						jQuery.modal.close();
					});
				});
			});
		});
	},
	show: function (dialog) {
	


	}
};