// JavaScript Document
var IndyImplants = {

	ExternalLinks: new Class({
			initialize: function () {
			$$('a').each( function (item) {
				if (item.getProperty('rel') == "external") item.setProperty('target', '_blank');
			});
		}
	}),
	
   ImgProtector: new Class({
		initialize: function() {
			$$('.protect').each ( function (item) {
				item.addEvent('contextmenu', function(e){ e.stop(); } );		
				item.addEvent('mousedown', function(e) {
					if (e.event.button == '2') {
						alert('Images are copyright Dr. Michael Edwards.');	
						return false;
					}
				} );
			});
		}
	}),

	RSFSP: new Class({
		form: null,
		action: null,
		initialize: function (form_id, action) {
			var submit;

			if ($(form_id)) {
				this.form = $(form_id);
				this.action = action;
				submit = this.form.getElement('.submit');
				if (submit) submit.addEvent('click', this.handler_click.bind(this));
			}
		},

		handler_click: function (e) {
			this.form.setProperty('action', this.action);
		}

	}),

	Pages: new Class({
		initialize: function () {
			this.global();
			$(document.body).getProperty('class').split(' ').each( function (item) {
				if (this[item]) this[item]();
			}.bind(this));

		},

		global: function () {
			new IndyImplants.ExternalLinks();
			new IndyImplants.ImgProtector();

		},

		patients: function () {
			new IndyImplants.RSFSP('form_schedule', '/patients/schedule/');
			new IndyImplants.RSFSP('form_suggest', '/patients/');
		},

		doctors: function () {
			new IndyImplants.RSFSP('form_referral', '/doctors/');
		}
	})
}

window.addEvent('domready', function(){
	new IndyImplants.Pages();
});