var popH=30 // Setup the height of the popup
var MyDelay=5000;  //Setup the delay of the popup in miliseconds
var speed = 1; //1 is  the slowest


var myWidth = 0, myHeight = 0;

function Size() {

  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;
  }
}

function getScroll() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}

var ScrollW=0;
function getScrollBarWidth () {
  if (navigator.appName=="Microsoft Internet Explorer"){
  scrollW=0;
  return 0;}
  else{
	var inner = document.createElement('p');
	inner.style.width = "100%";
	inner.style.height = "200px";
	
	var outer = document.createElement('div');
	outer.style.position = "absolute";
	outer.style.top = "0px";
	outer.style.left = "0px";
	outer.style.visibility = "hidden";
	outer.style.width = "200px";
	outer.style.height = "150px";
	outer.style.overflow = "hidden";
	outer.appendChild (inner);
	
	document.body.appendChild (outer);
	var w1 = inner.offsetWidth;
	outer.style.overflow = "scroll";
	var w2 = inner.offsetWidth;
	if (w1 == w2) w2 = outer.clientWidth;
	
	document.body.removeChild (outer);
	ScrollW=(w1 - w2);
	return (w1 - w2);
  }
};

var timer = null;
var timer2 = null;
var endTop = 0;

function getEl(id)
{
	var el = document.getElementById(id);
	return el;
}
function showEl(id)
{
	getEl(id).style.display ="";
}
function hideEl(id)
{
	getEl(id).style.display ="none";
}

var i=0;

function moveEl(id)
{
	var popup = getEl(id);
	var currentTop = parseInt(popup.style.top);
	var keepMoving = false;
	var offs=0;

	if (i < popH)
	{
		popup.style.top =(currentTop + speed) + "px";//myHeight+offs-i+"px"; // (currentTop - speed) + "px";
		keepMoving = true;
		Move=true;
		i=i+speed;
	}
	if (keepMoving)
	{
		startMove(id);
	}
	else
	{
		Move=false;
                endMove();

	}
}


function startMove(id)
{
	timer = setTimeout("moveEl('"+id+"')", 1);
}
function endMove()
{
	clearTimeout(timer2);clearTimeout(timer);
}

function StartPopUp(id){
var popup = getEl(id);
	timer2=setTimeout("Move=true;var popup = getEl('"+id+"');popup.style.display ='block';startMove('"+id+"')", MyDelay);
}

var Move=false;

function resizepop(id,restart){
  if (restart==true){
	if(Move==true){
        endMove();
        i=0;
        SetParam(id);
        StartPopUp(id);
        }else{
         i=0;
         endMove();
        SetParam(id);
        StartPopUp(id);
        }
 }else{
  if(Move==true){
        endMove();
        i=0;
        SetParam(id);
        StartPopUp(id);
        }else{
         var popup = getEl(id);
        SetParam2(id);
        }
 }
        return true;
}
function SetParam2(id){
Size(id);
getScrollBarWidth();
var popup = getEl(id);
popup.style.top =myHeight-popH;
popup.style.left =0;
popup.style.width =myWidth-2-ScrollW;
popup.style.height =popH;
popup.style.display ="block";
}


function SetParam(id){
Size(id);
getScrollBarWidth();

var popup = getEl(id);
//popup.style.top =myHeight;
popup.style.top =-popH;
popup.style.left =0;
popup.style.width =myWidth-2-ScrollW;
popup.style.display ="block";
popup.style.height =popH; //-<<<<<<<<<
endTop=popH;
}

function fixPos(id,k){

var popup = getEl(id);
var curH=parseInt(popup.style.top);
var offs=getScroll();
var newtop=offs+curH;
if (k==1){popup.style.top=offs+myHeight;}
else{popup.style.top=offs+myHeight-popH;}
}

function setSqueeze(){
	var left = Math.round((myWidth/2)-300);
	document.getElementById('squeeze').style.left = left;
	document.getElementById('squeeze').style.top = 0;
	document.getElementById('overlay').style.width = myWidth;
	document.getElementById('overlay').style.height = myHeight;	
}

function showSqueeze(){
	document.getElementById('squeeze').style.display="block";	
	document.getElementById('overlay').style.display="block";	
	hideEl('popup');	
}

function closePopup(){
	document.getElementById('squeeze').style.display="none";	
	document.getElementById('overlay').style.display="none";
}