var useragent = new defineNavigatorUserAgent();
var banner_url		= "http://avtoshina.od.ua/banner/banner.html";
var banner_width	= 480;	//pixels
var banner_height	= 200;
var banner_timeout	= 2500;	//1.5 sec

window.onload = setTimeout(function() { showWindowPopup(); }, banner_timeout);

function defineNavigatorUserAgent()
{
	this.is_MSIE = this.is_OPERA = this.is_FIREFOX = this.is_CHROME = this.is_SAFARI = false;
	var useragent = navigator.userAgent.toLowerCase();

	if (useragent.indexOf("msie") > -1) {
		this.is_MSIE = true;

	} else if (useragent.indexOf("opera") > -1) {
		this.is_OPERA = true;
    
	} else if (useragent.indexOf("firefox") > -1) {
		this.is_FIREFOX = true;

	} else if (useragent.indexOf("chrome") > -1) {
		this.is_CHROME = true;

	} else if (useragent.indexOf("safari") > -1) {
		this.is_SAFARI = true;
	}
}

function setElementOpacity(obj, opacity_level)
{
	if (useragent.is_MSIE) {
		obj.style.filter = "alpha(opacity=" + opacity_level * 100 + ")";
	} else {
		obj.style.opacity = opacity_level;
	}
}

var popupwincontainer = null;
function showWindowPopup()
{
	popupwincontainer = document.createElement("div");
	document.body.appendChild(popupwincontainer);

	popupwincontainer.innerHTML = "<div style='text-align:right;'><a href='' style='padding:5px 10px 5px 10px; font-weight:bold; color:#ffffff; background-color:#9acd32;' onclick='hideWindowPopup(); return false;'>X</a></div>";
	popupwincontainer.innerHTML += "<iframe src='" + banner_url + "' width='" + banner_width + "' height='" + banner_height + "' marginwidth='0' marginheight='0' frameborder='no' scrolling='no'></iframe>";

	popupwincontainer.style.position = "fixed";
	popupwincontainer.style.left = parseInt((document.documentElement.clientWidth - popupwincontainer.offsetWidth) / 2) + "px";
	popupwincontainer.style.top = parseInt((document.documentElement.clientHeight - popupwincontainer.offsetHeight) / 2) + "px";

	window.onkeyup = function(e) { e = e || window.event; if (e.which == 27) hideWindowPopup(); }
	lockScreen(popupwincontainer);

	return popupwincontainer;
}

function hideWindowPopup()
{
	if (popupwincontainer) {
		document.body.removeChild(popupwincontainer);
		popupwincontainer = null;
	}
	unlockScreen();
}

var lockerwindow = null;
function lockScreen()
{
	lockerwindow = document.createElement("div");
	document.body.appendChild(lockerwindow);
	
	lockerwindow.style.width = document.documentElement.scrollWidth + "px";
	lockerwindow.style.height = document.documentElement.scrollHeight + "px";
	lockerwindow.style.left = "0px";
	lockerwindow.style.top = "0px";
	lockerwindow.style.backgroundColor = "#000000";
	lockerwindow.style.position = "absolute";
	lockerwindow.style.zIndex = 50;
	if (arguments.length) arguments[0].style.zIndex = lockerwindow.style.zIndex + 1;
	lockerwindow.style.display = "none";
	setElementOpacity(lockerwindow, 0.5);
	lockerwindow.style.display = "block";
	return lockerwindow;
}

function unlockScreen()
{
	if (lockerwindow) {
		document.body.removeChild(lockerwindow);
		lockerwindow = null;
	}
}

