/**
 * Contact Script
 * The project requirement is to pop
 * open a dialog box when one of the contacts is clicked.  The dialog
 * should display a contact form.  We're going to place an iframe in 
 * the dialog box, and the iframe will display the contact form, a 
 * dagon design formmailer.  Automatically selected will be the recipient 
 * the user intended to email.
 *
 * So this script does a few things:
 * 1) listen for clicks starting with mailto: ... whenever one is clicked,
 * 2) build the dialog box - only have to do this once.  Thereafter, we can 
 *    reset the location of the iframe so it reloads the form and selects the 
 *    new person that the visitor clicked
 * 9) I guess there is no '9'. :)
 *
 * Written by James Revillini <james@revillini.com>.  E-mail for support.
 **/

jQuery(function ($) {

	//register event listeners. listen for whenever visitor clicks an e-mail link
	$('a[href^=mailto]').click(function (evt) {
	
		//cancel default action
		evt.preventDefault();
	
		//capture link that was clicked, and turn it into a jqueryable object
		var $this = $(this);
		//capture e-mail
		var email = $this.attr('href');
		//strip 'mailto:'
		email = email.replace('mailto:', '');
		
		//check if we already built the contact dialog
		if (!$('#contact-dialog').length) {
			//no dialog has been built yet; build it!
			$('head').append('<link rel="stylesheet" type="text/css" href="css/contact.css">');
			$('body').append('<div id="contact-dialog" title="Contact our Team"><iframe name="contact" src="contact.php?recipient=' + email + '"></iframe></div');
			$('#contact-dialog').dialog({
				autoOpen	: true,

				width		: 600,
				height		: 600,

				modal		: true,
				zIndex		: 999999,
				buttons: {
					"Cancel": function() { 

						$(this).dialog("close"); 

					} 

				}
				
			});
		
		}
		
		
		//ok, dialog HAS been built, so just reload the iframe in there and then show it
		$('#contact-dialog').dialog('open');
		$('#contact-dialog iframe').attr('src', 'contact.php?recipient=' + email);
		
		return false;
	});

});

