var ie5 = (document.all) ? true : false;

var openSpeed       = 20;
var closeSpeed      = -20;
var delaySpeed      = 20;
var intervalHandler = null;
var hecpopup        = null;
var essayezmoi		= null;
var hecHeight       = null;
var hecCurHeight    = null;
var hecUrl          = null;

var EN				= "/cme/english/popup/";
var FR				= "/cme/francais/popup/";
var ES				= "/cme/espanol/popup/";
var LEAD			= "http://www.hec.ca/cme/js/popup.js";

do_pop = true;

function essayezMoi(x, y, w, h, id, lng){
   var screenWidth = document.body.offsetWidth;
   x = (screenWidth / 3) * 2;
   
   essayezmoi = document.createElement("div");
   essayezmoi.setAttribute("id", id);
//   essayezmoi.style.display    = "none";
   essayezmoi.style.position   = "absolute";
   essayezmoi.style.left       = x + "px";
   essayezmoi.style.top        = y + "px";
   essayezmoi.style.width      = w + "px";
   essayezmoi.style.height     = h + "px";
   essayezmoi.style.padding    = "0px";
   essayezmoi.style.overflow   = "hidden";
   essayezmoi.style.zIndex     = 3;
   
   switch(lng) {
      case "EN": essayezmoi.innerHTML = '<span class="normal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try me <br><img src="/cme/images/popup/fleche_rouge.gif" width="20" height="20" align="top"></span>';
		         break;
	  case "FR": essayezmoi.innerHTML = '<span class="normal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; essayez moi <br><img src="/cme/images/popup/fleche_rouge.gif" width="20" height="20" align="top"></span>';
		         break;
	  case "ES": essayezmoi.innerHTML = '<span class="normal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Explore este vínculo<br><img src="/cme/images/popup/fleche_rouge.gif" width="20" height="20" align="top"></span>';
		         break;
	  case "LEAD": essayezmoi.innerHTML = '<span class="normal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try me <br><img src="/cme/images/popup/fleche_rouge.gif" width="20" height="20" align="top"></span>';
		         break;
   }
   
   document.body.appendChild(essayezmoi);
}

function pop() {
   new hecPopup(250, 62, 450, 400, "hec_div");
}

function showURL(url, lng) {
   if (do_pop) {
	   pop();
	   do_pop = !do_pop;
   }
   
   //url="dalai_lama.htm";
   
   if (url != " ") {
      set_URL(url, lng);
      showPopup("hec_div");
   }
}

function hecPopup(x, y, w, h, id) {
   var screenWidth = document.body.offsetWidth;
   x = (screenWidth / 2) - 385;
   

   hecpopup = document.createElement("div");
   hecpopup.setAttribute("id", id);
   hecpopup.height = h;
   hecpopup.style.display    = "none";
   hecpopup.style.position   = "absolute";
   hecpopup.style.left       = x + "px";
   hecpopup.style.top        = y + "px";
   hecpopup.style.width      = w + "px";
   hecpopup.style.height     = "1px";
   hecpopup.style.padding    = "0px";
   hecpopup.style.overflow   = "hidden";
   hecpopup.style.zIndex     = 2;

   if (!ie5)
      hecpopup.height = h + 40;
   
   hecpopup.innerHTML = '<iframe id="iframe_src" width="100%" height="100%" frameborder="0"></iframe>';
   
   hecsound = document.createElement("bgsound");
   hecsound.id = "sound";

   document.body.appendChild(hecsound);
   document.body.appendChild(hecpopup);
   
   hecUrl = document.getElementById("iframe_src");
}


function set_URL(url, lng) {
   switch(lng) {
      case "EN": hecUrl.src = EN + url;
		         break;
	  case "FR": hecUrl.src = FR + url;
		         break;
	  case "ES": hecUrl.src = ES + url;
		         break;
	  case "LEAD": hecUrl.src = LEAD + url;
		         break;
   }
}

function playSound(url) {
  document.all.sound.src = url;
}


function showPopup(id) {
   hecCurHeight = 1;
   hecpopup.style.height = 1;
   hecpopup.style.display = "block";
   intervalHandler = setInterval("doAction('" + id + "', " + openSpeed + ")", delaySpeed);
   playSound("/cme/images/popup/wind.wav");
}


function hidePopup(id) {
   if (hecpopup == null) {
      hecpopup = parent.document.getElementById(id);
   }
      
   hecCurHeight = hecpopup.height;
   hecpopup.style.display='block';
   intervalHandler = setInterval("doAction('" + id + "', " + closeSpeed + ")", delaySpeed);
}


function doAction(id, speed) {
   hecCurHeight += speed;
   hecpopup.style.height = hecCurHeight + "px";
   
   if (speed > 0) {
      if (hecCurHeight >= hecpopup.height) {
         hecpopup.style.display = "block";
         clearInterval(intervalHandler);
         intervalHandler = null;
      }
   }
   else {
      if (hecCurHeight <= 0) {
         clearInterval(intervalHandler);
         intervalHandler = null;
         hecpopup.style.display = "none";
      }
   }
}
/* Fonction Stop & Play Bandeau defilant
function getFlashMovieObject()
{
   if (navigator.appName.indexOf("Microsoft Internet")!=-1)
   {
     return window.flips;
   }
   else
   {
     return window.document.flips; 
	}     
}

function StopFlashMovie()
{
	var flashMovie=getFlashMovieObject();
	flashMovie.StopPlay();
}

function PlayFlashMovie()
{
	var flashMovie=getFlashMovieObject();
	flashMovie.Play();
}*/