function insertAd(text) {
	var ad = document.createElement('div');
	ad.innerHTML=text;
	ad.setAttribute('id','impMsg');
	ad.setAttribute('class','adPop');
	ad.style.position='absolute';
	ad.style.top=0;
	ad.style.right=0;
	ad.style.marginTop=20;
	ad.style.zIndex=99999;
	ad.style.width=30;
	ad.style.textAlign='center';

	y = document.getElementById('header');

	y.parentNode.insertBefore(ad, y);
	return ad;
}
function anim(o) {
	setTimeout(function() {slideIn(o,0);}, 50);
//	setTimeout(function() {slideOut(o);}, 5000);
}
function addHandler(obj) {
	$(obj).hover(function() {
		slideIn(this);
	}, function() {
		 slideOut(this);
	});
}
function slideIn(o, teaser) {
	if($(o).is(':animated'))
		return 0;
	var wsize = window.innerWidth ? window.innerWidth : document.documentElement.offsetWidth;
	wsize -= 100;
	if(teaser) {
		$(o).animate({
			'width':'10%'
		});
	} else {
		$(o).animate({
			'width':wsize
		});
	}
}
function slideOut(o) {
	if($(o).is(':animated'))
		return 0;
	$(o).animate({
		'width':30
	});
}
window.onload=function() {
	var xhr = new XMLHttpRequest();
	xhr.open('post', '/ad.php');
	xhr.send(null);
	xhr.onreadystatechange=function(e) {
		if(xhr.status==200 && xhr.readyState==4) {
			var obj = insertAd(xhr.responseText);
			anim(obj);
			addHandler(obj);
		}
	}
}

