// =========================================================
// ==                                                     ==
// ==    ROUTINE DE GESTION DU SCROLL DU SITE 4GMOBILE    ==
// ==                                                     ==
// =========================================================
// ==                                                     ==
// == CODE SOURCE VERSION : 0.0.1                         ==
// == CODE DEVELOPPER     : LERICQUE Jean-Yves            ==
// ==                                                     ==
// =========================================================

// =========================================================
// =========================================================
// =========================================================

var DOM 	= (document.getElementById ? true : false);
var IE  	= (document.all && !DOM ? true : false);
var NS4 	= (document.layers ? true : false);
var NETSCAPE 	= (navigator.appName == "Netscape");

var DelayDefil 	= 50;      	// Delai pour défilement Msg
var DelayPause 	= 4000;    	// Delai pour pause sur le Msg
var IncY 	= 2;		// Pas Incrémentation du Msg
var bFirst 	= false;
var MsgTimer 	= null;
var OfsY;
var DeltaY;
var PosX;
var PosY;
var MsgClip;
var MsgEnCours;
var MsgNbr;
var MsgZone;
var MsgLarg;
var MsgHaut;
var MsgOK   	= false;
var Clip    	= new RECT();
var Zone    	= new RECT();
var Message 	= new Array();

// =========================================================
// =========================================================
// =========================================================

function RECT(l_,t_,r_,b_){
  var Arg = arguments;
  this.Left    = (Arg[0] ? l_: 0);
  this.Top     = (Arg[1] ? t_: 0);
  this.Right   = (Arg[2] ? r_: 0);
  this.Bottom  = (Arg[3] ? b_: 0);
}

// =========================================================
// =========================================================
// =========================================================

function GetObjet(div_){
  if(DOM) return document.getElementById(div_);
  if(IE)  return document.all[div_];
  if(NS4) return document.layers[div_];
}

// =========================================================
// =========================================================
// =========================================================

function GetStyle(div_){
  return (NS4 ? GetObjet(div_) : GetObjet(div_).style);
}

// =========================================================
// =========================================================
// =========================================================

function ObjGetLargeur(div_){
  var Obj  = null;
  var Larg = 0;
  Obj = GetObjet(div_);
  if( Obj){
    if( NETSCAPE)
      Larg = Obj.offsetWidth;
    else
      Larg = Obj.scrollWidth;
  }
  return( Larg);
}

// =========================================================
// =========================================================
// =========================================================

function ObjGetHauteur(div_){
  var Obj  = null;
  var Haut = 0;
  Obj = GetObjet(div_);
  if( Obj){
    if( NETSCAPE)
      Haut= Obj.offsetHeight;
    else
      Haut= Obj.scrollHeight;
  }
  return( Haut);
}

// =========================================================
// =========================================================
// =========================================================

function ObjGetPosX(div_){
  var Obj = null;
  Obj = GetObjet(div_);
  if( Obj){
    return( Obj.offsetLeft);
  }
  return( null);
}

// =========================================================
// =========================================================
// =========================================================

function ObjGetPosY(div_){
  var Obj = null;
  Obj = GetObjet(div_);
  if( Obj){
    return( Obj.offsetTop);
  }
  return( null);
}

// =========================================================
// =========================================================
// =========================================================

function ObjWrite(div_,html_){
  var Obj;
  Obj = GetObjet(div_);
  if( Obj)
    Obj.innerHTML = html_;
}

// =========================================================
// =========================================================
// =========================================================

function ObjShow(div_,z_){
  var Obj = null;
  Obj = GetStyle(div_);
  if( Obj){
    Obj.visibility = "visible";
    if( arguments[1] != null)
      Obj.zIndex = z_;
  }
  return(true);
}

// =========================================================
// =========================================================
// =========================================================

function ObjMoveTo(div_,x_,y_){
  var Obj = null;
  var Arg = arguments;
  Obj = GetStyle(div_);
  if( Obj){
    if( NETSCAPE){
      if( Arg[1] != null) Obj.left = x_;
      if( Arg[2] != null) Obj.top  = y_;
    }
    else{
      if( Arg[1] != null) Obj.pixelLeft = x_;
      if( Arg[2] != null) Obj.pixelTop  = y_;
    }
  }
}

// =========================================================
// =========================================================
// =========================================================

function ObjSetClipping(div_,t_,r_,b_,l_){
  var Obj = null;
  var Clipping = "rect(";
  var Arg = arguments;
  if(div_){
    Obj = GetStyle(div_);
    if( Obj){
      for( i=1; i< Arg.length; i++){
        if( Arg[i] != null)
          Clipping += " "+Arg[i]+"px";
        else
          Clipping += " auto";
      }
      Clipping += ")";
      Obj.clip = Clipping;
    }
  }
}

// =========================================================
// =========================================================
// =========================================================

function Add_Div(div_){
  var Html ="";
  var NewDiv;
  Html  = '<DIV ID="MSG" style="position:absolute;left:0px;top:0px;width:auto;height:auto;visibility:hidden;"';
  Html += ' OnMouseOver="Msg_Stop();" OnMouseOut="Msg_Replay(\'MSG\');"></DIV>';
  if( IE){
    document.body.insertAdjacentHTML('beforeEnd',Html);
  }else if(DOM){
    NewDiv = document.createElement('DIV');
    document.body.appendChild(NewDiv);
    NewDiv.innerHTML = Html;
  }
}

// =========================================================
// =========================================================
// =========================================================

function GetZone(){
  with( Zone){
    Left   = ObjGetPosX(MsgZone);
    Top    = ObjGetPosY(MsgZone);
    Right  = ObjGetLargeur(MsgZone);
    Bottom = ObjGetHauteur(MsgZone);
  }
}

// =========================================================
// =========================================================
// =========================================================

function Add_Message(m_){
  var i = Message.length;
  Message[i] = '<strong>'+m_+'</strong>';
}

// =========================================================
// =========================================================
// =========================================================

function Msg_Creer(div_){
  var Html = "";
  var szTR = "";
  var Largeur = Zone.Right;
  var Hauteur = Zone.Bottom;
  Hauteur = parseInt(Hauteur /IncY) * IncY;
  MsgNbr = Message.length +1;
  szTR = '<tr><td height="' +Hauteur +'" width="' +Largeur +'" NOWRAP class="MSG" valign="center">';
  Html = '<table border="0" cellspacing="0" cellpadding="0">';
  for(i in Message)
    Html += szTR+Message[i]+'</td></tr>';
    Html += szTR+Message[0]+'</td></tr>';
    Html += '</table>';
    ObjWrite(div_,Html);
}

// =========================================================
// =========================================================
// =========================================================

function Msg_Stop(){
  if( MsgTimer)
    clearTimeout( MsgTimer);
}

// =========================================================
// =========================================================
// =========================================================

function Msg_Replay(div_){
  if( MsgOK ){
    Msg_Stop();
    MsgTimer = setTimeout("DefilHAUT('" +div_ +"')", DelayDefil);
  }
}

// =========================================================
// =========================================================
// =========================================================

function Msg_Begin(div_){
  OfsY   = 0;
  DeltaY = 0;
  MsgEnCours = 1;
  GetZone();
  PosX = Zone.Left;
  PosY = Zone.Top - OfsY;
  Clip.Top    = Zone.Top - PosY;
  Clip.Bottom = Clip.Top + MsgClip;
  ObjSetClipping(div_,Clip.Top,MsgLarg,Clip.Bottom,0);
  ObjMoveTo(div_,PosX,PosY);
  ObjShow(div_,100);
  MsgTimer = setTimeout("DefilHAUT('" +div_ +"')", DelayPause);
}

// =========================================================
// =========================================================
// =========================================================

function Msg_Start(div_){
  var Obj = null;
  var Html= "";
  Msg_Stop();
  Obj = GetObjet(div_);
  if( Obj){
    bFirst = true;
    GetZone();
    Msg_Creer(div_);
    MsgLarg = ObjGetLargeur(div_);
    MsgHaut = ObjGetHauteur(div_);
    MsgClip = MsgHaut / MsgNbr;
    Msg_Begin(div_);
  }
}

// =========================================================
// =========================================================
// =========================================================

function DefilHAUT(div_){
  OfsY   += IncY;
  DeltaY += IncY;
  GetZone();
  PosX = Zone.Left;
  PosY = Zone.Top -OfsY;
  Clip.Top    = Zone.Top - PosY;
  Clip.Bottom = Clip.Top + MsgClip;
  ObjSetClipping(div_,Clip.Top,MsgLarg,Clip.Bottom,0);
  ObjMoveTo(div_,PosX,PosY);
  if(bFirst){
    ObjShow(div_, 100);
    bFirst = false;
  }
  if(DeltaY<MsgClip){
    MsgTimer = setTimeout("DefilHAUT('" +div_ +"')", DelayDefil);
  }
  else{
    DeltaY = 0;
    MsgEnCours ++;
    if( MsgEnCours == MsgNbr){
      Msg_Begin(div_);
    }
    else{
      MsgTimer = setTimeout("DefilHAUT('" +div_ +"')", DelayPause);
    }
  }
}

// =========================================================
// =========================================================
// =========================================================

function Msg_Init( where_){
  MsgZone = where_;
  Add_Div  ('MSG');
  GetZone();
  Msg_Start('MSG');
  MsgOK = true;
}
