var g_oImgDiv = null;
var g_oFlashDiv = null;
var g_oImgDivSdw = null;
var g_bImgDrag = false;
var g_iMPX = 0;
var g_iMPY = 0;
function GetElements() {
	if (document.getElementById) {
		g_oImgDiv = document.getElementById("imgDiv");
		g_oImgDivSdw = document.getElementById("imgDivSdw");
		g_oFlashDiv = document.getElementById("flashDiv");
	} else if (document.all) {
		g_oImgDiv = document.all["imgDiv"];
		g_oImgDivSdw = document.all["imgDivSdw"];
		g_oFlashDiv = document.all["flashDiv"];
	}
}
function PositionFlash() {
	if (g_oFlashDiv) {
		var iWindowWidth = -1;
		var iTop = 60;
		if (window.outerWidth)
			iWindowWidth = window.outerWidth;
		else
			iWindowWidth = document.body.clientWidth;
		if (document.body && (document.body.scrollLeft || document.body.scrollTop))
			iTop += document.body.scrollTop;
		else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
			iTop += document.documentElement.scrollTop;
		g_oFlashDiv.style.display = "block";
		g_oFlashDiv.style.top = iTop + "px";
		g_oFlashDiv.style.left = Math.round((iWindowWidth / 2) - (640 / 2)) + "px";
	}
}
function PositionImage(o) {
	if (g_oImgDiv) {
		var iWindowWidth = -1;
		var iTop = 60;
		if (window.outerWidth)
			iWindowWidth = window.outerWidth;
		else
			iWindowWidth = document.body.clientWidth;
		if (document.body && (document.body.scrollLeft || document.body.scrollTop))
			iTop += document.body.scrollTop;
		else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
			iTop += document.documentElement.scrollTop;
		g_oImgDiv.style.display = "block";
		g_oImgDiv.style.top = iTop + "px";
		g_oImgDiv.style.left = Math.round((iWindowWidth / 2) - (o.width / 2)) + "px";
		PositionShadow();
	}
	g_bImgDrag = false;
}
function PositionShadow() {
	if (g_oImgDiv && g_oImgDivSdw) {
		var iTop = parseInt(g_oImgDiv.style.top) + 5;
		var iLeft = parseInt(g_oImgDiv.style.left) + 5;
		var iWidth = g_oImgDiv.offsetWidth;
		var iHeight = g_oImgDiv.offsetHeight;
		if (iWidth > 0 && iHeight > 0) {
			g_oImgDivSdw.style.display = "block";
			g_oImgDivSdw.style.top = iTop + "px";
			g_oImgDivSdw.style.left = iLeft + "px";
			g_oImgDivSdw.style.width = iWidth + "px";
			g_oImgDivSdw.style.height = iHeight + "px";
		}
	}
}
function StartImageDrag() {
	g_iMPX = 0;
	g_iMPY = 0;
	g_bImgDrag = true;
}
function DragImage(e) {
	if (g_oImgDiv && g_bImgDrag) {
		var iX = parseInt(g_oImgDiv.style.left);
		var iY = parseInt(g_oImgDiv.style.top);
		var iMX = (e) ? e.clientX : event.clientX;
		var iMY = (e) ? e.clientY : event.clientY;
		if (g_iMPX > 0 || g_iMPY > 0) {
			g_oImgDiv.style.left = (iX + (iMX - g_iMPX)) + "px";
			g_oImgDiv.style.top = (iY + (iMY - g_iMPY)) + "px";
			PositionShadow();
		}
		g_iMPX = iMX;
		g_iMPY = iMY;
		return false;
	}
}
function ShowImage(sImgUrl, sAlt) {
	GetElements();
	if (g_oImgDiv) {
		g_oImgDiv.style.display = "none";
		g_oFlashDiv.style.display = "none";
		g_oImgDiv.innerHTML = "<div class=\"title\" onmousedown=\"StartImageDrag();\" onmouseup=\"g_bImgDrag=false;\"><div class=\"titleCnt\">" + sAlt + "</div><div onClick=\"HideImage();\" class=\"close\" title=\"Sulje kuva\"></div></div><div class=\"image\"><img src=\"" + sImgUrl + "\" onload=\"if(PositionImage) PositionImage(this)\" onClick=\"return HideImage();\" alt=\"" + sAlt + "\"/></div>";
	}
	return false;
}
function HideImage() {
	GetElements();
	if (g_oImgDiv)
		g_oImgDiv.style.display = "none";
	if (g_oImgDivSdw)
		g_oImgDivSdw.style.display = "none";
	g_bImgDrag = false;
	return false;
}
function ShowFlashGallery(sUrl, sAlt, sArgs) {
	GetElements();
	if (g_oFlashDiv) {
		sArgs = sArgs.replace("&", "%26");
		g_oImgDiv.style.display = "none";
		g_oFlashDiv.style.display = "block";
		var so = new SWFObject("/flash/kohdekuvatfulldynamic.swf", "flashgallery", "640", "640", "9", "#FFFFFF");
		so.addParam("menu", "false");
		so.addParam("allowScriptAccess", "sameDomain");
		so.addParam("wmode", "transparent");
		so.addParam("FlashVars", "SourceUrl=" + sUrl + "&Args=" + sArgs);
		so.write(g_oFlashDiv.id);
		PositionFlash();
	}
}
function HideFlashGallery() {
	GetElements();
	if (g_oFlashDiv)
		g_oFlashDiv.style.display = "none";
}
document.onmousemove = DragImage;
document.onmouseup = new Function("g_bImgDrag=false");
