
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }


function findPosY(obj)
  {               
    var curtop = 0;
    
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
                     
    return curtop;
  }
     
function getWindowHeight() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  /*window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );*/
  return myHeight;
}

function init_scroll(div,pos_haut)
{   
    var v = 0;                             
    var $scrollingDiv = jQuery("#"+div);

    if(!$scrollingDiv)
        return 0;
    //var pos_haut = findPosY(document.getElementById("div_haut")); 
    
    /*POS DEPART*/
    /*POS BAS MAX*/
    //var pos_extrem_bas = 2000;
    var pos_extrem_bas = findPosY(document.getElementById("pos_bas"));

    /**/    
    var hauteur = getWindowHeight()-300;    
    
    $(window).scroll(function()
    {                                            
        var pos_scroll = $(window).scrollTop();              

        if(pos_scroll <= (pos_extrem_bas-hauteur) && pos_scroll >= pos_haut)
        {
            $scrollingDiv.stop().animate({"marginTop": (pos_scroll)-pos_haut + "px"}, "fast" );
        }       
        else if(pos_scroll < pos_haut)                             
        {                                                                  
            
            $scrollingDiv.stop().animate({"marginTop": "35px"}, "fast" );                                                  
        }
    });
}
