window.addEvent('domready', function() {
	//Terms and Conditions link
	$$('.terms-link').addEvent('click', function() {
		window.open('terms-and-conditions?tmpl=component', 'win2', 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no');
		return false;
	});

	//Recruitment
	var buttons = $$('.recruitment').getElements('.read-more');
	var options = {display:-1};
	new Fx.Accordion(buttons, $$('.recruitment').getElements('.details'), options);
	
	//Add highlight to selected area
	buttons = $$(buttons);
	buttons.addEvent('click', function() {
		buttons.getParent().removeClass('highlight');
		this.getParent().addClass('highlight');
	});
});

var videoPlayer = {
	container: null,
	player: null,
	init: function(video_id) {
		this.player = document.getElementById("video");
		this.player.cueVideoById(video_id);

		this.container = $('video-container');
		//The container loads off-screen but visible, as onYouTubePlayerReady() is not triggered in IE if video is not visible.
		this.container.setStyle('left', '0');

		this.toggle();
		this.addControls();
		
		//Add open/close
		$$('.open-video, #close-video').addEvent('click', function() {
			this.toggle();
		}.bind(this));
	},
	toggle: function() {
		var state = this.container.getStyle('visibility');
		if(state == 'hidden') {
			this.container.setStyles({visibility: 'visible', zIndex:1});
			this.player.playVideo();
		}
		else {
			this.player.pauseVideo();
			this.container.setStyles({visibility: 'hidden', zIndex:-1});
		}
	},
	addControls: function() {
		//Play
		$('play-video').addEvent('click', function() {
			this.player.playVideo();
		}.bind(this));
		//Pause
		$('pause-video').addEvent('click', function() {
			this.player.pauseVideo();
		}.bind(this));
		//Rewind
		$('rewind-video').addEvent('click', function() {
			this.player.seekTo(0, true);
		}.bind(this));
	}
};
