
//$(window).load(function(){			// wait to load images
$(document).ready(function() {
	//========================================================================================================================
	//========================================================================================================================


	// make sure document is at a minimum
	var docheight = $('div#wrapper').height();
	var winheight = $(window).height();
	if (docheight < winheight)
	{
		var new_contentheight = $('div#mainContentWrapper').height() + winheight - docheight;
		$('div#mainContentWrapper').height(new_contentheight);
		var new_contentheight = $('div#homeFlash_spacer').height() + winheight - docheight;
		$('div#homeFlash_spacer').height(new_contentheight);
	}


	/* classes
	 ------------------------------------------------------------ */
	var dialogs = $('.dialog');
	$.each(dialogs, function(indexInArray, valueOfElement) {

		$(valueOfElement).dialog({
									 autoOpen: false,
									 width: 500,
									 height: 500,
									 modal: true,
									 buttons: {
										 Send: function() {
											 send_comment_form($(valueOfElement).find('form'));
											 $(this).dialog('close');
										 },
										 Cancel: function() {
											 $(this).dialog('close');
											 $(valueOfElement).find('form')[0].reset();
										 }
									 },
									 close: function() {
										 // alert('closing');
									 }
								 });

	});


	open_dialog = function(dialog_selector) {
		$(dialog_selector).dialog('open');
	};


	/* send form
	 ------------------------------------------------------------ */
	send_comment_form = function(form_selector) {
		var form_data = $(form_selector).serialize();

		$.ajax({												// http://api.jquery.com/jQuery.ajax
				   type: 'POST',
				   url: '/ajax/send_comment',
				   data: form_data,
				   dataType: 'text',									// xml, html, script, json, jsonp, text
				   cache: true,
				   beforeSend: function(XMLHttpRequest, settings) {	// return false to cancel request
					   $('div.ui-dialog-buttonset').hide();
				   },
				   success: function(result) {
					   $('div.ui-dialog-buttonset').show();
					   alert(result);
				   },
				   complete: function(XMLHttpRequest, textStatus) {
					   $(form_selector)[0].reset();
				   },
				   error: function(XMLHttpRequest, textStatus, errorThrown) {
					   $('div.ui-dialog-buttonset').show();
				   }
			   });
	};


});

