function $ (id) {return document.getElementById(id);}

isWinOpen = false;
htmlBuf = "";

widthCur = 0;
heightCur = 0;
widthBegin = 46;
heightBegin = 46;
widthEnd = 520;
heightEnd = 600;

stepsNum = 5;
stepTime = 100;

widthStep = (widthEnd - widthBegin) / stepsNum;
heightStep = (heightEnd - heightBegin) / stepsNum;

isIE=(navigator.appName.indexOf("Microsoft")>-1 && navigator.userAgent.indexOf("Opera")<0);
isIEold=isIE && (navigator.userAgent.indexOf("MSIE 5")>0 || navigator.userAgent.indexOf("MSIE 6")>0);

var imgs = ["underline", "award", "price", "leftBracket", "lb", "lt", "rb", "rt", "close", "shadow", "rShadow", "arrowleft", "arrowright", "listpoint", "loader"];
for (var i = 0; i < imgs.length; i++) {
	var src = "i/" + imgs[i] + ".gif";
	imgs[i] = new Image();
	imgs[i].src = src;
}

sTop = 0;

function openWin () {
	if (isWinOpen) return;
	if (isIEold) sTop = document.documentElement.scrollTop;
	widthCur = widthBegin;
	heightCur = heightBegin;
	setWinSize();
	var i = setInterval(function () {
		widthCur += widthStep;
		heightCur += heightStep;
		if (widthCur >= widthEnd || heightCur >= heightEnd) {
			widthCur = widthEnd;
			heightCur = heightEnd;
			clearInterval(i);
			isWinOpen = true;
			setWinSize();
			$("loader").style.display = "";
			if (htmlBuf.length) {
				showContent(htmlBuf);
				$("infoDivClose").style.display = "";
			}
		} else {
			setWinSize();
		}
	}, stepTime);
}

function setWinSize () {
	var divStyle = $("windowX").style;
	$("infoDiv").style.display = "";
	$("hAll").style.display = "";
	divStyle.width = widthCur + "px";
	$("lt").style.width = widthCur + 21 +"px";
	$("lb").style.width = widthCur + 21 +"px";
	divStyle.height = heightCur + "px";
}

function setContentOpacity (opacity) {
	var els = $("infoDivText").style;
	if (isIE) {
		els.filter = "alpha(opacity=" + opacity + ")";
	} else {
		els.opacity = opacity / 100;
	}
}

function showContent (html) {
	htmlBuf = "";
	$("infoDivClose").style.display = "";
	$("loader").style.display = "none";
	var opacity = 0;
	setContentOpacity(opacity);
	$("infoDivText").innerHTML = html;
	var i = setInterval(function () {
		opacity += 20;
		setContentOpacity(opacity);
		if (opacity == 100) {
			clearInterval(i);
		}
	}, 100);
}

function AJAXReq (url, callBack) {
	var x;
	try {
		x = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			x = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
			x = null;
		}
	}
	if (!x && typeof XMLHttpRequest != "undefined") {
		x = new XMLHttpRequest();
	}
	if (!x) return;
	x.open("GET", url, true);
	x.onreadystatechange = function () {
		if ((x.readyState == 4) && callBack) {
			callBack(x.responseText);
		}
	}
	x.send(null);
}

function openLink (a, img) {
	if (img) {
		var i = new Image;
		i.src = "pics/portfolio/big/" + img;
	}
	openWin();
	var link = a.href + "?ajax=true";
	AJAXReq(link, function (html) {
		if (isWinOpen) {
			showContent(html);
		} else {
			htmlBuf = html;
		}
	});
	if (isWinOpen) {
	  $("loader").style.display = "";
	}
	return false;
}

function closeWindow () {
	$("infoDivText").innerHTML = "";
	$("infoDivClose").style.display = "none";
	$("infoDiv").style.display = "none";
	$("hAll").style.display="none";
	isWinOpen = false;
	sTop = 0;
}
function noScroll () {
	if (sTop) document.documentElement.scrollTop = sTop;
}