window.addEvent('domready', function() {

	// a couple of calendar popups
	if ( $defined( $('calendar1') ) ) {
		new vlaDatePicker('calendar1', { style: 'adobe_cs3', format: 'y/m/d', separator: '-', ieTransitionColor: '', prefillDate: 'false' }); 
	}
	if ( $defined( $('calendar2') ) ) {
		new vlaDatePicker('calendar2', { style: 'adobe_cs3', format: 'y/m/d', separator: '-', ieTransitionColor: '', prefillDate: 'false' }); 
	}



	if ( $('industry_select_1') ) {
		
		$$('#industry_sectors_1 .industry-sectors').each(function(el,i){
//			el.setStyle('display', 'none');
		});
		
		$('industry_select_1').addEvent('change', function(e) {
			$$('#industry_sectors_1 .industry-sectors').each(function(el,i){
				el.setStyle('display', 'none');
			});
			$$('#industry_sectors_1 .industry-sectors input[type=checkbox]').each(function(el,i){
				el.set('checked', false);
			});
			
			var id = this.get('value');
			$('panel1_ind'+id).setStyle('display','block');
		});
	
		
		$$('#industry_sectors_2 .industry-sectors').each(function(el,i){
//			el.setStyle('display', 'none');
		});
		
		$('industry_select_2').addEvent('change', function(e) {
			$$('#industry_sectors_2 .industry-sectors').each(function(el,i){
				el.setStyle('display', 'none');
			});
			$$('#industry_sectors_2 .industry-sectors input[type=checkbox]').each(function(el,i){
				el.set('checked', false);
			});
			
			var id = this.get('value');
			$('panel2_ind'+id).setStyle('display','block');
		});
	
		
		$$('#industry_sectors_3 .industry-sectors').each(function(el,i){
//			el.setStyle('display', 'none');
		});
		
		$('industry_select_3').addEvent('change', function(e) {
			$$('#industry_sectors_3 .industry-sectors').each(function(el,i){
				el.setStyle('display', 'none');
			});
			$$('#industry_sectors_3 .industry-sectors input[type=checkbox]').each(function(el,i){
				el.set('checked', false);
			});
			
			var id = this.get('value');
			$('panel3_ind'+id).setStyle('display','block');
		});
	
	}



	if ( $('profile-photo') ) {
		$$('.photo-toggler').addEvent('click', function(e) {
			e.stop();
			$('profile-photo').set('src', this.get('href'));
		});
	}


	$$('a.disabled').addEvent('click', function(e) {
		e.stop();
	});
	
	var myMenu = new MenuMatic({ id:'nav', opacity: '100', hideDelay: '500', duration: '800', effect: 'fade' });

	/*
	http://davidwalsh.name/mootools-form-field-default-plugin
	*/
	var dwTextareaDefaults = new Class({
		//implements
		Implements: [Options],
	
		//options
		options: {
			collection: $$('input[type=text]')
		},
		
		//initialization
		initialize: function(options) {
			//set options
			this.setOptions(options);
			this.defaults();
		},
		
		//a method that does whatever you want
		defaults: function() {
			this.options.collection.each(function(el) {
				el.set('html',el.get('alt'));
				el.addEvent('focus', function() { if(el.get('html') == el.get('alt')) { el.set('html',''); } });
				el.addEvent('blur', function() { if(el.get('html') == '') { el.set('html',el.get('alt')); } });
			});
		}
		
	});

	var dwInputDefaults = new Class({
		//implements
		Implements: [Options],
	
		//options
		options: {
			collection: $$('input[type=text]')
		},
		
		//initialization
		initialize: function(options) {
			//set options
			this.setOptions(options);
			this.defaults();
		},
		
		//a method that does whatever you want
		defaults: function() {
			this.options.collection.each(function(el) {
				el.set('value',el.get('alt'));
				el.addEvent('focus', function() {
					if (el.get('value') == el.get('alt')) {
						if ( el.hasClass('password') ) {
							el.set('type', 'password');
						}
						el.set('value','');
					}
				});
				el.addEvent('blur', function() {
					if (el.get('value') == '') {
						if ( el.hasClass('password') ) {
							el.set('type', 'text');
						}
						el.set('value',el.get('alt'));
					}
				});
			});
		}
		
	});

	
	var textareaDefaults = new dwInputDefaults({
		collection: $$('#shoutbox textarea')
	});

	var inputDefaults = new dwInputDefaults({
		collection: $$('#shoutbox input[type=text]')
	});
	
	$$('input[type=text],input[type=password]').addEvents({
		'focus' : function() {
			this.addClass('focused');
		},
		'blur' : function() {
			this.removeClass('focused');
		}
	});

});

