
/*********************************************************************/
/** Please make sure this page encoding matches the site encoding                       **/
/** (ISO-8859-1 at the time of writing)                                                                    **/
/*********************************************************************/

window.addEvent('domready', function () {
	//eligibility form
	if ($('frmEligibility')) {
		$('frmEligibility').addEvent('submit', function(evt) {
			if ($('jsChecked')) {
				$('jsChecked').value = 1;
			}
			var isEligible = $('fldE1Yes').checked && $('fldE2Yes').checked && $('fldE3Yes').checked && $('fldE4No').checked;
			if (!isEligible) {
				$ans = confirm("Unfortunately you are not eligible to enter the protégé competition - however you will still be considered for our graduate/intern and summer placement schemes, but you will not have the chance to enter the final stages of the protégé competition. If you still wish to proceed with an application, please click the 'OK' button. If you do not wish to proceed with an application, please click the 'Cancel' button.");
				if (!$ans) {
					new Event(evt).stop();
					window.location = 'rlb_not_for_me.php';
				}
			}
			else {
				alert("Congratulations, you have confirmed that you are eligible to enter the protégé scheme. Please click the 'OK' button below to continue with your application (Please note that all responses on this application will be verified so please complete accurately.)");
			}
		});
	}
	
	//"reveal more" text blocks
	var triggers = $$('a.revealMore');
	var blocks = $$('div.revealMore');
	var nbOfTriggers = triggers.length;
	var nbOfBlocks = blocks.length;
	for (var i = 0; i < nbOfTriggers; i++) {
		if (i < nbOfBlocks) {
			new RevealMore(triggers[i], blocks[i]);
		}
	}
});

var RevealMore = new Class({
	trigger: null,
	block: null,
	triggerCopy: null,
	blockBottomMargin: 0,
	originalHeight: 0,
	options: {
		duration: 250
	},
	hFx: null,
	oFx: null,
	revealing: false,
	initialize: function(trigger, block, options) {
		this.setOptions(options);
		
		this.trigger = $(trigger);
		this.block = $(block);
		
		this.triggerCopy = this.trigger.get('html');
		this.blockBottomMargin = this.block.getStyle('margin-bottom');
		this.originalHeight = this.block.getSize().y;
		
		
		this.trigger.setStyles({
			outline: 'none'
		});
		this.block.setStyles({
			height: '0px',
			overflow: 'hidden',
			'margin-bottom': '0'
		});
		if (!/MSIE\s6/.test(navigator.userAgent)) {
			this.block.setStyle('opacity', 0);
		}
		
		this.trigger.addEvent('click', this.toggle.bindWithEvent(this));
	},
	toggle: function(evt) {
		evt.stop();
		
		if (this.hFx) this.hFx.cancel();
		if (this.oFx) this.oFx.cancel();
		
		var currentHeigth = parseInt(this.block.getStyle('height'));
		var currentOpacity = this.block.getStyle('opacity');
		if (!this.revealing) { //reveal
			this.revealing = true;
			if (!/MSIE\s6/.test(navigator.userAgent)) {
				//this.oFx = new Fx.Style(this.block, 'opacity', this.options).start(currentOpacity, 1);
				var options = this.options;
				options.property = 'opacity';
				this.oFx = new Fx.Tween(this.block, options).start(currentOpacity, 1);
			}
			//this.hFx = new Fx.Style(this.block, 'height', this.options).start(currentHeigth, this.originalHeight);
			var options = this.options;
			options.property = 'height';
			this.hFx = new Fx.Tween(this.block, options).start(currentHeigth, this.originalHeight);
			
			this.trigger.set('html', 'Hide');
			this.trigger.addClass('revealMoreActive');
			this.block.setStyle('margin-bottom', this.blockBottomMargin);
		}
		else { //hide
			this.revealing = false;
			if (!/MSIE\s6/.test(navigator.userAgent)) {
				//this.oFx = new Fx.Style(this.block, 'opacity', this.options).start(currentOpacity, 0);
				var options = this.options;
				options.property = 'opacity';
				this.oFx = new Fx.Tween(this.block, options).start(currentOpacity, 0);
			}
			//this.hFx = new Fx.Style(this.block, 'height', this.options).start(currentHeigth, 0);
			var options = this.options;
			options.property = 'height';
			this.hFx = new Fx.Tween(this.block, options).start(currentHeigth, 0);
			
			this.trigger.set('html', this.triggerCopy);
			this.trigger.removeClass('revealMoreActive');
			this.block.setStyle('margin-bottom', 0);
		}
	}
});
RevealMore.implement(new Options);
