// <script>

// Copyright (C) 2005 Ilya S. Lyubinskiy. All rights reserved.
// Technical support: http://www.php-development.ru/
//
// YOU MAY NOT
// (1) Remove or modify this copyright notice.
// (2) Distribute this code, any part or any modified version of it.
//     Instead, you can link to the homepage of this code:
//     http://www.php-development.ru/javascripts/dropdown.php.
//
// YOU MAY
// (1) Use this code on your website.
// (2) Use this code as a part of another product provided that
//     this code will be a small part of this product.
//
// NO WARRANTY
// This code is provided "as is" without warranty of any kind, either
// expressed or implied, including, but not limited to, the implied warranties
// of merchantability and fitness for a particular purpose. You expressly
// acknowledge and agree that use of this code is at your own risk.


// USAGE
//
// function popup_show(id, drag_id, exit_id, position, x, y, position_id)
//
// id          - id of a popup window;
// drag_id     - id of an element within popup window intended for dragging it
// exit_id     - id of an element within popup window intended for hiding it
// position    - positioning type:
//               "screen-corner", "screen-center"
//               "mouse-corner" , "mouse-center"
//               "element-right", "element-bottom"
// x, y        - offset
// position_id - for the last two types of positioning popup window will be
//               positioned relative to this element


// ----- Variables -------------------------------------------------------------

var popup_dragging = false;
var popup_target;
var popup_mouseX;
var popup_mouseY;
var popup_mouseposX;
var popup_mouseposY;
var popup_oldfunction;

function popup_display(x)
{
  var win = window.open();
  for (var i in x) win.document.write(i+' = '+x[i]+'<br>');
}

// ----- popup_mousedown -------------------------------------------------------

function popup_mousedown(e)
{
  var ie = navigator.appName == "Microsoft Internet Explorer";

  if ( ie && window.event.button != 1) return;
  if (!ie && e.button            != 0) return;

  popup_dragging = true;
  popup_target   = this['target'];
  popup_mouseX   = ie ? window.event.clientX : e.clientX;
  popup_mouseY   = ie ? window.event.clientY : e.clientY;

  if (ie)
       popup_oldfunction      = document.onselectstart;
  else popup_oldfunction      = document.onmousedown;

  if (ie)
       document.onselectstart = new Function("return false;");
  else document.onmousedown   = new Function("return false;");
}

// ----- popup_mousemove -------------------------------------------------------

function popup_mousemove(e)
{
  if (!popup_dragging) return;

  var ie      = navigator.appName == "Microsoft Internet Explorer";
  var element = document.getElementById(popup_target);

  var mouseX = ie ? window.event.clientX : e.clientX;
  var mouseY = ie ? window.event.clientY : e.clientY;

  element.style.left = (element.offsetLeft+mouseX-popup_mouseX)+'px';
  element.style.top  = (element.offsetTop +mouseY-popup_mouseY)+'px';

  popup_mouseX = ie ? window.event.clientX : e.clientX;
  popup_mouseY = ie ? window.event.clientY : e.clientY;
}

// ----- popup_mouseup ---------------------------------------------------------

function popup_mouseup(e)
{
  if (!popup_dragging) return;
  popup_dragging = false;

  var ie      = navigator.appName == "Microsoft Internet Explorer";
  var element = document.getElementById(popup_target);

  if (ie)
       document.onselectstart = popup_oldfunction;
  else document.onmousedown   = popup_oldfunction;
}

// ----- popup_exit ------------------------------------------------------------

function popup_exit(e)
{
  var ie      = navigator.appName == "Microsoft Internet Explorer";
  var element = document.getElementById(popup_target);

  popup_mouseup(e);
  //element.style.visibility = 'hidden';
  element.style.display    = 'none';
  DechargeFondPopup();
  //document.getElementById("blocopacity").style.display='none';
   //document.getElementById("blocopacity").style.visibility='hidden';
}

function popup_close(id){
	element      = document.getElementById(id);
	//element.style.visibility = "none";
    element.style.display    = "none";
    //document.getElementById("blocopacity").style.visibility='hidden';
    DechargeFondPopup();
}

// ----- popup_show ------------------------------------------------------------
/*
		var hPositionElement;
		// on voile la page avec un fond noir
		if(document.all)
		{
			//alert(document.getElementById("vodeobody").offsetHeight);
			var intElemOffsetHeight = document.getElementById("vodeobody");
			var hPositionElement = intElemOffsetHeight.offsetHeight;
		}
		if(!document.all) {
			//alert(document.getElementById("vodeobody").offsetHeight);
			var intElemOffsetHeight = document.getElementById("vodeobody");
			var hPositionElement = eval(intElemOffsetHeight.offsetHeight+1);
		}

		document.getElementById("blocopacity").style.height=document.getElementById("vodeobody").offsetHeight+'px';
		//alert(document.getElementById("vodeobody").offsetHeight);
		document.getElementById("blocopacity").style.visibility='visible';


		document.getElementById("blocopacity").style.filter= 'alpha(opacity=80)';
		document.getElementById("blocopacity").style.opacity= '.80';

		// on rend visible l'encadr� avec la vid�o
		document.getElementById("blocgratuit").style.visibility= 'visible';
		document.getElementById("blocgratuit").style.opacity= '1';

		//document.getElementById("blocpub").style.visibility= 'hidden';
		document.getElementById("flash_prog").style.visibility = 'hidden';
*/

function popup_show(id, drag_id, exit_id, position, x, y, position_id){
	popup_show_with_option(id, drag_id, exit_id, position, x, y, position_id, null);
}


function popup_show_big(id, drag_id, exit_id, position, x, y, position_id){
	popup_show_with_option(id, drag_id, exit_id, position, x, y, position_id, 'big_popup');
}

function popup_show_with_option(id, drag_id, exit_id, position, x, y, position_id, class_name)
{
  element      = document.getElementById(id);
  drag_element = document.getElementById(drag_id);
  
  if(class_name != null){
  	element.className = class_name;
  }
  exit_element = document.getElementById(exit_id);

  element.style.position   = "absolute";
  element.style.visibility = "visible";
  element.style.display    = "block";

  scrollLeft = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft;
  scrollTop = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
  
  if (position == "screen-corner")
  {
    element.style.left = (scrollLeft+x)+'px';
    element.style.top  = (scrollTop +y)+'px';
  }

  if (position == "screen-center")
  {
  	var arrayPageSize = getPageSize();
		
  	
    element.style.left = intval(scrollLeft+(document.body.clientWidth -element.clientWidth )/2+x)+'px';
    
    element.style.top  = intval(scrollTop +(arrayPageSize[1]-element.clientHeight)/2+y)+'px';

  }

   if (position == "display-center")
  {
  	var arrayPageSize = getPageSize();
  	
    element.style.left = intval(scrollLeft+(document.body.clientWidth -element.clientWidth )/2+(x))+'px';
    element.style.top  = intval(scrollTop/2 +(arrayPageSize[1]-element.clientHeight)/2+(y))+'px';

    var my_width  = 0;
 var my_height = 0;

 if ( typeof( window.innerWidth ) == 'number' ){
  my_width  = window.innerWidth;
  my_height = window.innerHeight;
 }else if ( document.documentElement &&
    ( document.documentElement.clientWidth ||
      document.documentElement.clientHeight ) ){
  my_width  = document.documentElement.clientWidth;
  my_height = document.documentElement.clientHeight;
 }
 else if ( document.body &&
   ( document.body.clientWidth || document.body.clientHeight ) ){
  my_width  = document.body.clientWidth;
  my_height = document.body.clientHeight;
 }



 var scrollY = 0;

 if ( document.documentElement && document.documentElement.scrollTop ){
  scrollY = document.documentElement.scrollTop;
 }else if ( document.body && document.body.scrollTop ){
  scrollY = document.body.scrollTop;
 }else if ( window.pageYOffset ){
  scrollY = window.pageYOffset;
 }else if ( window.scrollY ){
  scrollY = window.scrollY;
 }

 var elementDimensions = Element.getDimensions(this.element);

 var setX = ( my_width  - elementDimensions.width  ) / 2;
 var setY = ( my_height - elementDimensions.height ) / 2 + scrollY;

 setX = ( setX < 0 ) ? 0 : setX;
 setY = ( setY < 0 ) ? 0 : setY;

 this.element.style.left = setX + "px";
 this.element.style.top  = setY + "px";


    
  }
  
  if (position == "mouse-corner")
  {
    element.style.left = (scrollLeft+popup_mouseposX+x)+'px';
    element.style.top  = (scrollTop +popup_mouseposY+y)+'px';
  }

  if (position == "mouse-center")
  {
    element.style.left = (scrollLeft+popup_mouseposX-element.clientWidth /2+x)+'px';
    element.style.top  = (scrollTop +popup_mouseposY-element.clientHeight/2+y)+'px';
  }

  if (position == "element-right" || position == "element-on" || position == "element-bottom")
  {
    var position_element = document.getElementById(position_id);

    for (var p = position_element; p; p = p.offsetParent)
      if (p.style.position != 'absolute')
      {
        x += p.offsetLeft;
        y += p.offsetTop ;
      }

    if (position == "element-on" ) x += (position_element.clientWidth/2)-element.clientWidth;
    if (position == "element-right" ) x += position_element.clientWidth;
    if (position == "element-bottom") y += position_element.clientHeight;

    element.style.left = x+'px';
    element.style.top  = y+'px';
  }

  drag_element['target']   = id;
  drag_element.onmousedown = popup_mousedown;

  exit_element.onclick     = popup_exit;
  
  /*var hPositionElement;
		// on voile la page avec un fond noir
		if(document.all)
		{
			//alert(document.getElementById("vodeobody").offsetHeight);
			var intElemOffsetHeight = document.getElementById("conteneur");
			var hPositionElement = intElemOffsetHeight.offsetHeight;
		}
		if(!document.all) {
			//alert(document.getElementById("vodeobody").offsetHeight);
			var intElemOffsetHeight = document.getElementById("conteneur");
			var hPositionElement = eval(intElemOffsetHeight.offsetHeight+1);
		}*/
		/*document.getElementById("blocopacity").style.visibility='visible';


		document.getElementById("blocopacity").style.filter= 'alpha(opacity=80)';
		document.getElementById("blocopacity").style.opacity= '.80';

		document.body.style.filter= 'alpha(opacity=80)';
		document.body.style.opacity= '.80';*/
		
		// on rend visible l'encadr� avec la vid�o
		var arrayPageSize = getPageSize();
		getById('blocopacity').style.width=arrayPageSize[0] + 'px';
		getById('blocopacity').style.height=arrayPageSize[1] + 'px';
		//$('monfilmo_fond_popup').setStyle({ width: '100%', height: '100%' });
		getById("blocopacity").style.filter= 'alpha(opacity=80)';
		getById("blocopacity").style.opacity= '.80';
		getById("blocopacity").style.display="block";
		
		ChargeFondPopup();

}

// ----- popup_mousepos --------------------------------------------------------

function popup_mousepos(e)
{
  var ie = navigator.appName == "Microsoft Internet Explorer";

  popup_mouseposX = ie ? window.event.clientX : e.clientX;
  popup_mouseposY = ie ? window.event.clientY : e.clientY;
}

// ----- Attach Events ---------------------------------------------------------

if (navigator.appName == "Microsoft Internet Explorer")
     document.attachEvent('onmousedown', popup_mousepos);
else document.addEventListener('mousedown', popup_mousepos, false);

if (navigator.appName == "Microsoft Internet Explorer")
     document.attachEvent('onmousemove', popup_mousemove);
else document.addEventListener('mousemove', popup_mousemove, false);

if (navigator.appName == "Microsoft Internet Explorer")
     document.attachEvent('onmouseup', popup_mouseup);
else document.addEventListener('mouseup', popup_mouseup, false);

function ouvrir_popup(){
  		var hPositionElement;
  		var scrollTop = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
		/*getById("monfilmo_fond_popup").style.height='100%';
		getById("monfilmo_fond_popup").style.width='100%';
		getById("monfilmo_fond_popup").style.visibility='visible';

		getById("monfilmo_fond_popup").style.filter= 'alpha(opacity=80)';
		getById("monfilmo_fond_popup").style.opacity= '.80';*/

		// on rend visible l'encadré avec la vidéo
		//getById("monfilmo_popup").style.top= (popup_mouseposY-300)+'px';
		getById("popup").style.left= (50)+'px';
		if(popup_mouseposY-300 > 10){
			getById("popup").style.top= (popup_mouseposY-50+scrollTop)+'px';
		}else{
			getById("popup").style.top= (popup_mouseposY-50+scrollTop)+'px';
		}
		getById("popup").style.display= 'block';
		getById("popup").style.visibility= 'visible';
		getById("popup").style.opacity= '1';
		
		
		var arrayPageSize = getPageSize();
		getById('blocopacity').style.width=arrayPageSize[0] + 'px';
		getById('blocopacity').style.height=arrayPageSize[1] + 'px';
		//$('monfilmo_fond_popup').setStyle({ width: '100%', height: '100%' });
		getById("blocopacity").style.filter= 'alpha(opacity=80)';
		getById("blocopacity").style.opacity= '.80';
		getById("blocopacity").style.display="block";
}

function ChargeFondPopup(){
		var arrayPageSize = getPageSize();
		getById('blocopacity').style.width=arrayPageSize[0] + 'px';
		getById('blocopacity').style.height=arrayPageSize[1] + 'px';
		//$('monfilmo_fond_popup').setStyle({ width: '100%', height: '100%' });
		getById("blocopacity").style.filter= 'alpha(opacity=80)';
		getById("blocopacity").style.opacity= '.80';
		getById("blocopacity").style.display="block";
		//getById("blocopacity").style.visibility="visible";
}

function DechargeFondPopup(){
	getById("blocopacity").style.display="none";
	//getById("blocopacity").style.visibility="hidden";
}

  function ferme_popup(){
  	getById("blocopacity").style.height='1px';
	getById("blocopacity").style.width='1px';
  	getById("blocopacity").style.display='none';
  	
  	element = getById("popup");
  	//element.style.visibility = 'hidden';
  	element.style.display    = 'none';
  	//popup_close('monfilmo_popup');
  }
  
  function ChargeAttente(){
	  ChargeFondPopup();
	  getById("waitDiv").style.display="block";
  }
  function DechargeAttente(){
	  DechargeFondPopup();
	  getById("waitDiv").style.display="none";
  }
  
 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;
		}

		return [pageWidth,pageHeight];
	}

