﻿if (!window.edu) window.edu = {};
if (!window.edu.dts) window.edu.dts = {};

edu.dts.VideoPopup = {
	
	initialized: false,
	pageCover: null,	
	visibleArea: null,
	player:null,
	swfUrl: '/flash/admissions/videoplayer.swf',

	init:function() {

		this.pageCover = new Element('div', { id:'video-background'});
		this.visibleArea = new Element('div', { id:'visible-area'});
		this.player = new Element('div', { id:'popup-player'}).update('This content requires Flash 9 or better');

		this.pageCover.setStyle({'position': 'absolute',
								'zIndex':'1000',
								'backgroundColor': '#000000'});								
		this.pageCover.setOpacity(0.5);

		this.visibleArea.setStyle({'position': 'absolute',
								'zIndex':'1001',
								'backgroundColor': 'transparent',
								'padding': '20px',
								'backgroundImage': 'url(/flash/admissions/playerbg.png)'
								});								


		$$('body').first().appendChild(this.pageCover);
		$$('body').first().appendChild(this.visibleArea);
		this.visibleArea.appendChild(this.player);

		this.pageCover.hide();
		this.visibleArea.hide();

		this.initialized = true;
	},
	
	coverClick: function(e) {
		// hide
		this.pageCover.hide();
		this.visibleArea.hide();
		
		// remove the player
		while (this.player.childNodes.length)
			this.player.removeChild(this.player.childNodes[0]);
	},

	play:function(videoUrl, options) {
		
		if (!this.initialized);
			this.init();

		var view = document.viewport.getDimensions();
		var scroll = document.viewport.getScrollOffsets();
		
		// position background		
		this.pageCover.setStyle({'top': scroll.top + 'px',
								'left': scroll.left + 'px',
								'width': view.width + 'px',
								'height':  view.height + 'px'});										
		this.pageCover.show();
		
		Event.observe(this.pageCover, 'click', this.coverClick.bindAsEventListener(this));
		
		
		// position player
		var playerWidth = 598;
		var playerHeight = 374;
		
		this.visibleArea.setStyle({'top': (scroll.top + view.height/2-playerHeight/2 - 20) + 'px',
								'left': (scroll.left + view.width/2-playerWidth/2 - 20) + 'px',
								'width': playerWidth + 'px',
								'height':  playerHeight + 'px'});										
		this.visibleArea.show();
		
		swfobject.embedSWF('/flash/admissions/admissionsplayer.swf', 'popup-player', playerWidth, playerHeight, '9.0.0', {'videoUrl': videoUrl}, null);			
	}
};
VideoPopup = edu.dts.VideoPopup;