var dyn = 0;
   
window.onload = function () {
    
  var hg = document.getElementById("of_offerdiv").offsetHeight;
  setTimeout("setBottomBanner(1)", 500);
  setTimeout("drawBottomBanner("+hg+")", 1500);
}

function movediv(pos) {
  document.getElementById("of_offerdiv").style.bottom = "-"+pos+"px";
}

function drawBottomBanner(hg) {

  document.getElementById("of_offerdiv").style.bottom = "-"+hg+"px";
  document.getElementById("of_offerdiv").style.display = "block";
  
  if (dyn == 1) {
    for (var i = hg; i >= 1; i--) {
 
      setTimeout("movediv("+i+")",((hg-i)*6)); // 10
    }
  } else {
    document.getElementById("of_offerdiv").style.bottom = "0px";
  }

}

function setBottomBanner(run) {
  
   var myWidth = 0, myHeight = 0;
   if (run != 1) run = 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;
  }
  
  if (myWidth > 1024) {
    
    dyn = 1;
    document.getElementById("of_offerdiv").className  = "fixed";
    if (run == 1) { document.getElementById("of_offerdiv").style.display = "none"; }
    
  }  else {

    dyn = 0;
    document.getElementById("of_offerdiv").className  = "";
    if (run == 1) { document.getElementById("of_offerdiv").style.display = "none"; } 
    
  }
  
}

function closeBottomBanner(oId) {                           
 
  var hg = document.getElementById("of_offerdiv").offsetHeight;
  
  if (dyn == 1) {
    for (var i = hg; i >= 1; i--) {
      setTimeout("movediv("+i+")",(i*3));
    }
  } else {
    document.getElementById("of_offerdiv").style.display = "none";
  }
  
  of_deleteSession(oId);
  
}

function getHTTPObject(){
  if (window.ActiveXObject) 
    return new ActiveXObject("Microsoft.XMLHTTP");
  else if (window.XMLHttpRequest) 
    return new XMLHttpRequest();
  else {
    return null;
  }
}

function of_deleteSession(oId) {
  httpObject = getHTTPObject();
  if (httpObject != null) {
    httpObject.open("GET", "/mod/offer/deleteSession.php?activateOfferId="+oId+"&activateOffer=1", true);
    httpObject.send(null);
    //httpObject.onreadystatechange = setOutput;
  }
}

window.onresize = null;
window.onresize = setBottomBanner;
