/**
 * VIDEOS
 */

var initVideo = function() {
	$$('.videos .button').each(function(el) {
		el.addEvent('click', displayVideo.bind(el));
	});
	$$('.videos .mini_button').each(function(el) {
		el.addEvent('click', displayVideo.bind(el));
	});
}

var displayVideo = function() {
	var full = new Element('div', {'id': 'full_video',
							   'styles': {
									'position':'absolute',
									'height': $(document.body).getScrollSize().y,
									'z-index':10000,
									'top':0,
									'bottom':0,
									'left':0,
									'right':0
							   }
						   }).inject(document.body);

	var video = this.id;
	var myRequest = new Request({
		url: "/video/include_video.php",
		method: "post",
		data:"",
		onComplete: function(response) {
			full.set('html', response);
			full.getFirst('.bg').setStyles({
					   	'position':'absolute',
						'background':'#000000',
						'opacity': 0.8,
					   	'top':0,
						'bottom':0,
						'left':0,
						'right':0,
						'z-index':0
					   });
			$('video_cont').setStyles({
				'position':'relative',
				'z-index':10001
			});
			full.addEvent('mousewheel', wheelEvent);
			loadSWFObject(video);
			resizeVideo();
			window.addEvent('resize', resizeVideo);
		}
	}).send();
						
}

var wheelEvent = function(e) {
	e.stop();	
}

var responseVideo = function(response) {
	this.set('html', response);
	loadSWFObject();
	resizeVideo();
	window.addEvent('resize', resizeVideo);
}

var resizeVideo = function() {
	var inc = $('include_video');
	$('video_cont').setStyles({
		//'width': '85%',
		'width': 800,
		'height': 500
		//'height': document.body.getSize().y * 70 / 100
	});
	
	$('full_video').setStyles({
		'padding-top': window.getScroll().y + (document.body.getSize().y - $('video_cont').getSize().y) / 2,
		'padding-left': (document.body.getSize().x - $('video_cont').getSize().x) / 2 /*,
		'height': $('diapo_embed').getSize().y - window.getScroll().y - document.body.getSize().y * (1 - 70 / 100) / 2,
		'width': window.getSize().x*/
	});
}

var loadSWFObject = function(video) {
	var flashvars = {};
	flashvars.url = "/videos/"+video+".flv";
	flashvars.closeFct = 'closeVideo';
	flashvars.lang = lang;
	var params = {};
	params.allowScriptAccess = "always";
	params.allowFullscreen = "true";
	var attributes = {};
	swfobject.embedSWF("/swf/video.swf", "include_video", "100%", "100%", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
}

var closeVideo = function() {
	$('full_video').removeEvent('mousewheel', wheelEvent);
	$('full_video').destroy();
}

window.addEvent('domready', function() {
	if($$('.videos').length > 0) {
		initVideo();
	}
});
