<!--

//
//	Configuration
//
var overlayVideoOpacity = 0.7;	 // controls transparency of shadow overlay
var animateVideo        = true; // toggles resizing animations
var resizeVideoSpeed    = 7;		 // controls the speed of the image resizing animations (1=slowest and 10=fastest)
var borderVideoSize     = 10;	   //if you adjust the padding in the CSS, you will need to update this variable

// -----------------------------------------------------------------------------------

//On trouve l'instance du lecteur flash
function getVideoBox(swf) {
/*
  if(navigator.appName.indexOf("Microsoft") != -1) {
    return window[swf];
  } else {
    return document[swf];
  }
*/
  return document.getElementById(swf);
};
 
function getVideoBoxDIV(){
  return document.getElementById("videoContainer");//gondole_video_div
}

//On envoie une commande au lecteur flash
function sendEventToVideoBox(swf, typ, prm) { 
  getVideoBox(swf).sendEvent(typ,prm); 
};

//On charge une nouvelle video dans le lecteur
function loadFileToVideoBox(swf, obj) { 
  getVideoBox(swf).loadFile(obj); 
  sendEventToVideoBox(swf,'playpause');
};

function StopVideoBox(){
    sendEventToVideoBox('dlvideo','stop');
}

function PlayVideoBox(aMovie){
  StopRollGondole();

  sendEventToVideoBox('dlvideo','playpause');
}

// -----------------------------------------------------------------------------------
//	Global Variables
if(animateVideo == true){
	overlayVideoDuration = 0.2;	// shadow fade in/out duration
	if(resizeVideoSpeed > 10){ resizeVideoSpeed = 10;}
	if(resizeVideoSpeed < 1){ resizeVideoSpeed = 1;}
	resizeVideoDuration = (11 - resizeVideoSpeed) * 0.15;
} else { 
	overlayVideoDuration = 0;
	resizeVideoDuration = 0;
}

//	VideoBox Class Declaration
//	Structuring of code inspired by Lokesh Dhakar (http://www.huddletogether.com)
//
var VideoBox = Class.create();

VideoBox.prototype = {
	
	// initialize()
	initialize: function() {	
	},


	//
	//	start()
	//	Display overlay and videobox. If image is part of a set, add siblings to imageArray.
	//
	start: function(aNameVideo) {	
    for(aMovieIdx in listMovies)  {
      if (listMovies[aMovieIdx][1] == aNameVideo) {
        currentMovie = listMovies[aMovieIdx];
        break;
      }
    }
		// stretch overlay to fill page and fade in
		var arrayPageSize = getPageSize();
		Element.setWidth('videoOverlay', arrayPageSize[0]);
		Element.setHeight('videoOverlay', arrayPageSize[1]);
		new Effect.Appear('videoOverlay', { duration: overlayVideoDuration, from: 0.0, to: overlayVideoOpacity });

		if (!document.getElementsByTagName){ return; }

		// calculate top and left offset for the videobox 
		var arrayPageScroll = getPageScroll();
		var videoboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 10);
		var videoboxLeft = arrayPageScroll[0];
		Element.setTop('videobox', videoboxTop);
		Element.setLeft('videobox', videoboxLeft);
    Element.show('videobox');
    Element.hide('dlvideo');
    Element.hide('videoDataContainer');
    myVideoBox.resizeVideoContainer(currentMovie, currentMovie[2], currentMovie[3]);
	},
	

	//
	//	resizeVideoContainer()
	//
	resizeVideoContainer: function(aMovie, imgWidth, imgHeight) {
		// get curren width and height
		this.widthCurrent = Element.getWidth('outerVideoContainer');
		this.heightCurrent = Element.getHeight('outerVideoContainer');

		// get new width and height
		var widthNew = (imgWidth  + (borderVideoSize * 2));
		var heightNew = (imgHeight  + (borderVideoSize * 2));

		// scalars based on change from old to new
		this.xScale = ( widthNew / this.widthCurrent) * 100;
		this.yScale = ( heightNew / this.heightCurrent) * 100;

		// calculate size difference between new and old image, and resize if necessary
		wDiff = this.widthCurrent - widthNew;
		hDiff = this.heightCurrent - heightNew;

		if(!( hDiff == 0)){ new Effect.Scale('outerVideoContainer', this.yScale, {scaleX: false, duration: resizeVideoDuration, queue: 'front'}); }
		if(!( wDiff == 0)){ new Effect.Scale('outerVideoContainer', this.xScale, {scaleY: false, delay: resizeVideoDuration, duration: resizeVideoDuration}); }

		// if new and old image are same size and no scaling transition is necessary, 
		// do a quick pause to prevent image flicker.
		if((hDiff == 0) && (wDiff == 0)){
			if (navigator.appVersion.indexOf("MSIE")!=-1){ pause(250); } else { pause(100);} 
		}

    Element.setWidth( 'videoContainer', widthNew);
		Element.setWidth('videoDataContainer', widthNew);

    var aVideoContainer = document.getElementById('videoContainer');
    var aVideoBox = document.getElementById('dlvideo');
    //aVideoContainer.removeChild(aVideoBox);
    
    var so = new SWFObject('/player/mediaplayer.swf', 'dlvideo', aMovie[2], aMovie[3], '8');
    so.addParam('allowscriptaccess','always');
    so.addParam('allowfullscreen','true');
    so.addVariable('width',aMovie[2]);
    so.addVariable('height',aMovie[3]);
    so.addVariable('file',aMovie[4]);
    so.addVariable('javascriptid','dlvideo');
    so.addVariable('enablejs','true');
    so.addVariable('autostart','false');
    so.addVariable('backcolor','0x000000');
    so.addVariable('frontcolor','0xEEEEEE');
    so.addVariable('lightcolor','0xFFFFFF');
    so.addVariable('screencolor','0x000000');
    so.addVariable('logo','/images/videobox_logo.png');
    //so.addVariable('callback','');
    //so.addVariable('link','');
    so.addVariable('showdigits','false');
    so.write('videoContainer');
    Element.hide('dlvideo');

		new Effect.Appear('dlvideo', { duration: resizeVideoDuration, queue: 'end', afterFinish: function(){ PlayVideoBox(aMovie); }});

		new Effect.Parallel(
			[ new Effect.SlideDown( 'videoDataContainer', { sync: true, duration: resizeVideoDuration, from: 0.0, to: 1.0 }), 
			  new Effect.Appear('videoDataContainer', { sync: true, duration: resizeVideoDuration }) ], 
			{ duration: resizeVideoDuration, afterFinish: function() {
				// update overlay size and update nav
				var arrayPageSize = getPageSize();
				Element.setHeight('videoOverlay', arrayPageSize[1]);
//				myLightbox.updateNav();
				}
			} 
		);
		
		this.enableKeyboardNav();
	},
	
	//
	//	enableKeyboardNav()
	//
	enableKeyboardNav: function() {
		document.onkeydown = this.keyboardAction; 
	},

	//
	//	disableKeyboardNav()
	//
	disableKeyboardNav: function() {
		document.onkeydown = '';
	},

	//
	//	keyboardAction()
	//
	keyboardAction: function(e) {
		if (e == null) { // ie
			keycode = event.keyCode;
			escapeKey = 27;
		} else { // mozilla
			keycode = e.keyCode;
			escapeKey = e.DOM_VK_ESCAPE;
		}

		key = String.fromCharCode(keycode).toLowerCase();
		
		if((key == 'x') || (key == 'o') || (key == 'c') || (keycode == escapeKey)){	// close videobox
			myVideoBox.end();
		}

	},

	//
	//	end()
	//
	end: function() {
    StopVideoBox();
	  if (navigator.appVersion.indexOf("MSIE")!=-1){ pause(250); } else { pause(100);} 
		this.disableKeyboardNav();
		Element.hide('videobox');
		new Effect.Fade('videoOverlay', { duration: overlayVideoDuration});
	}
}

// -----------------------------------------------------------------------------------

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
//
function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		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
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			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 = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

// -----------------------------------------------------------------------------------

//
// getKey(key)
// Gets keycode. If 'x' is pressed then it hides the videobox.
//
function getKey(e){
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	key = String.fromCharCode(keycode).toLowerCase();
	
	if(key == 'x'){
	}
}

// ---------------------------------------------------

//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Help from Ran Bar-On [ran2103@gmail.com]
//

function pause(ms){
	var date = new Date();
	curDate = null;
	do{var curDate = new Date();}
	while( curDate - date < ms);
}

// ---------------------------------------------------

function initialize_video_layer() { myVideoBox = new VideoBox(); }
Event.observe(window, 'load', initialize_video_layer, false);
// -->
