var intervalId = null;
var count = 0;

function showAD(n,id) {
    count++;
    var ss = setTimeout("showAD(" + n + ",'" + id + "')", 1000);
    if (count >= n) {
        clearTimeout(ss);
        count = 0;
	document.getElementById(id).style.display = "";
        slideAd(id, 6, "down", 636, 1);
    }
}

function slideAd(id,nDelayTime,sState,nMaxHeight,nMinHeight){ 
	this.delayTime=nDelayTime; 
	this.maxHeigth=nMaxHeight; 
	this.minHeigth=nMinHeight; 
	this.state=sState; 
	this.delay = function () {
		count++;
		var ss = setTimeout(delay, 1000);
		if (count >= this.delayTime) {
			clearTimeout(ss);
			count = 0;
			intervalId=window.setInterval(closeBox,1000);
		}
	}
	var obj = document.getElementById(id); 
	if (intervalId != null) {
		window.clearInterval(intervalId);
	}
	
	function openBox() { 
		var h = obj.offsetHeight; 
		if (this.state == "down") {
			h += 100;
			if (h > nMaxHeight) {
				h = nMaxHeight;
				obj.style.height = h + "px";
				window.clearInterval(intervalId);
				delay();
			}else {
				obj.style.height = h + "px";
			}
		}else {
			h -= 80;
			if (h < nMinHeight) {
				h = 0;
				obj.style.height = h + "px";
				window.clearInterval(intervalId);
				obj.style.display="none";
			}else {
				obj.style.height = h + "px";
			}
		}
	} 
	
	function closeBox() { 
		slideAd(id,this.delayTime,"up",nMaxHeight,nMinHeight); 
	} 
	intervalId = window.setInterval(openBox,10); 
} 