document.observe("dom:loaded", function() {
	$('load_form').observe('click', function(event) {
		  event.stop(); // prevent link form going to #
		  Lightview.show({
		    href: '/modal.php',
		    rel: 'ajax',
		    options: {
		      width: 550,
		      height: 550,
		      closeButton: 'small',
		      ajax: {
		        onComplete: function() {
		          // once the request is complete we observe the form for a submit
		          $('email').observe('submit', submitForm);
		        }
		      }
		    }
		  });
	});
});

function submitForm(event) {
	  // block default form submit
	  Event.stop(event);
	  
	  // if there's no text in the box, don't do anything
	  //var text = $('ajaxForm').down('input').value.strip();
	  //if (!text) return;
		  
	  Lightview.show({
	    href: '/send_email.php',
	    rel: 'ajax',
	    options: {
		  width: 550,
		  height: 225,
	      closeButton: 'small',
	      ajax: {
	        parameters: Form.serialize('email') // the parameters from the form
	      }
	    }
	  });
}

(function() {
	function init () {
		// initiate image rollovers
		$$("img.rollover").each(rollovers);
		$$("img.photo").each(switch_photo);
	}
	
	function preload_img (img) {
		var img = new Image();
		img.src = img;
	}
	
	function rollovers (img) {
		img.src_over = img.src.replace(/(\.[^.]+)$/, '_o$1');
		img.src_out = img.src;
		preload_img(img.src_over);
		
		img.observe("mouseover", function() {
			img.src = img.src_over;
		});
		
		img.observe("mouseout", function() {
			img.src = img.src_out;
		});
	}
	
	function switch_photo (img) {
		img.src_over = img.src.replace(/(\.[^.]+)$/, '_p$1');
		preload_img(img.src_over);
		
		img.observe("mouseover", function() {
			document.getElementById('phone').src = img.src_over;
		});
		
	}
	
	document.observe("dom:loaded", init);
	
})();