
FLVLightBox = new Class ({
	
	initialize: function() {
		
		this.overlay = new Element('div');
		this.overlay.setProperty('id', 'overlay');
		this.overlay.setStyles({display: 'none',
							   	position: "absolute",
								top: 0,
								left: 0,
								zIndex: 90,
								height: "100%",
								width: "100%",
								opacity: 0});
		this.overlay.injectInside(document.body);
		
		this.flvlightbox = new Element('div');
		this.flvlightbox.setProperty('id', 'flvlightbox');
		this.flvlightbox.injectInside(document.body);
		
		this.overlay.addEvent('click', this.hide.bind(this));
	},
	
	start: function(flv_source) {
		
		flv_path = flv_source;
		this.overlay.setStyles({display: 'block'});
		this.position();
		this.show();
	},
	
	end: function() {
		this.flvlightbox.setStyles({display: 'none', opacity: 1});
		this.overlay.setStyles({display: 'none'});
	},
	
	show: function() {		
		new Fx.Styles(this.overlay, {duration: 100, transition: Fx.Transitions.Quad.easeOut, onComplete: this.resize.bind(this)}).start({'opacity': 0.8});
		
	},
	
	resize: function() {
		
		if(window.ie6){
			var arrayPageScroll = getPageScroll();
			var arrayPageSize = getPageSize();
			
			var scrollTop = arrayPageScroll[1];
			var scrollLeft = arrayPageScroll[0];
			var width = arrayPageSize[1];
			var height = arrayPageSize[3];
		}else{
			var scrollTop = window.getScrollTop();
			var scrollLeft = window.getScrollLeft();
			var width = window.getWidth();
			var height = window.getHeight();
		}
		
		
		this.flvlightbox.setStyles({	display: 'block',
								   		top: scrollTop + (height - 282) / 2 + 141, 
										left: scrollLeft + (width - 320) / 2 + 160});
		
		new Fx.Styles(	this.flvlightbox, {	duration: 200, 
					  						transition: Fx.Transitions.Cubic.easeOut, 
											onComplete: this.resizeComplete.bind(this)}).start({
						'width': 320, 'height': 282, 
						'top': scrollTop + (height - 282) / 2, 
						'left': scrollLeft + (width - 320) / 2});
	},
	
	resizeComplete: function() {
		
		var fo = new FlashObject("swf/flv-playback.swf", null, 320, 282, 8, "#ffffff");
		fo.addVariable("skin_path", "swf/SteelExternalAll.swf");
		fo.addVariable("flv_path", flv_path);
		fo.write("flvlightbox");
	
		this.setup(true);
	},
	
	hide: function() {
		
		this.setup(false);
		this.flvlightbox.setHTML("");
		new Fx.Styles(this.overlay, {	duration: 100, 
					  					transition: Fx.Transitions.Quad.easeOut}).start({'opacity': 0});
		
		if(window.ie6){
			var arrayPageScroll = getPageScroll();
			var arrayPageSize = getPageSize();
			
			var scrollTop = arrayPageScroll[1];
			var scrollLeft = arrayPageScroll[0];
			var width = arrayPageSize[1];
			var height = arrayPageSize[3];
		}else{
			var scrollTop = window.getScrollTop();
			var scrollLeft = window.getScrollLeft();
			var width = window.getWidth();
			var height = window.getHeight();
		}


		new Fx.Styles(	this.flvlightbox, {	duration: 650, 
					  						transition: Fx.Transitions.Cubic.easeOut,
											onComplete: this.end.bind(this)}).start({
						'width': 0, 'height': 0, 'opacity': 0,
						'top': scrollTop + (height - 282) / 2 + 141, 
						'left': scrollLeft + (width - 320) / 2 + 160});
	}, 
	
	position: function() {
		
		if(window.ie6){
			var arrayPageScroll = getPageScroll();
			var arrayPageSize = getPageSize();
			
			var scrollTop = arrayPageScroll[1];
			var scrollLeft = arrayPageScroll[0];
			var width = arrayPageSize[1];
			var height = arrayPageSize[3];
		}else{
			var scrollTop = window.getScrollTop();
			var scrollLeft = window.getScrollLeft();
			var width = window.getWidth();
			var height = window.getHeight();
		}


		this.flvlightbox.setStyles({top: scrollTop + (height - 282) / 2, 
					  				left: scrollLeft + (width - 320) / 2});
		this.overlay.setStyles({top: scrollTop, left: scrollLeft});
	}, 
	
	setup: function(open) {
		var fn = open ? 'addEvent' : 'removeEvent';
		window[fn]('scroll', this.position.bind(this))[fn]('resize', this.position.bind(this));
	}
	
})


		
		

var flv_path;
var myFlvLightBox;

function initFLVLightBox()
{
	myFlvLightBox = new FLVLightBox();
	
	$$('table.tableproduits td div.flash_video a').each(function(item){
		item.onclick = function () {myFlvLightBox.start(this); return false;}
	});
	
	$$('table.tableproduits td div.wmv a, table.tableproduits td div.mov a').each(function(item){
		item.onclick = function () {window.open(this.href); return false;}
	});

}


// -----------------------------------------------------------------------------------

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

// -----------------------------------------------------------------------------------




//----------------------------------------------------------
//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
//
function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

};


addLoadEvent(initFLVLightBox);