//------------------------------------------------------------------------------
// Image popup
//------------------------------------------------------------------------------
// Display/hide the selected photo.
window.photoPopup = {
	noProgress: false,

	//--------------------------------------
	show: function (img) {
	//--------------------------------------
		var isIE = window.navigator.userAgent.match(/MSIE/)
		var isIE6 = window.navigator.userAgent.match(/MSIE 6/)
		var player = document.getElementById("dailiesPhotoLayer")
		var photo = document.getElementById("dailiesPhoto")
		var overlay = document.getElementById("docOverlay")
//TOSEE: if h/w not spec in element default
		var progress = document.getElementById("progressImg")

		if (player && photo && overlay) {

		photo.orgSrc = photo.src
//COMP:IE: progress img triggers layer visibility too early; disable it.
		if (this.noProgress || isIE) {
			photo.style.visibility = "hidden"
			if (isIE)
				photo.src = "";
			}
				
//COMP:IE: the onLoad img handler make the img visible which triggers the player visibility .. what a mess!
		if (!isIE || player.displayedAtLeastOnce) {
			setTimeout(function() {
				photo.src = img.src.replace(/sm/,"")
				}, (this.noProgress || isIE ? 0 : 300))
			}

		this.setSize(progress.width, progress.height)
//COMP:IE: the first time it is displayed position on screen is not ok ...
//SOL: display as invisible and call recursive.
			if (isIE) {
				player.style.visibility = player.displayedAtLeastOnce ? "visible" : "hidden"
				if (!player.displayedAtLeastOnce) {
					setTimeout(function(){
						player.displayedAtLeastOnce = true
						window.photoPopup.show(img)}, 100)
					return
					}
				}
			}
		
		return(false)
		},

	//--------------------------------------
	setSize: function (photoWidth, photoHeight) {
	//--------------------------------------
		var isIE = window.navigator.userAgent.match(/MSIE/)
		var isIE6 = window.navigator.userAgent.match(/MSIE 6/)
//		var screenHeight = window.innerHeight ? window.innerHeight : window.document.body.clientHeight 
//		var screenWidth = window.innerWidth ? window.innerWidth : window.document.body.clientWidth 
		var player = document.getElementById("dailiesPhotoLayer")
		var photo = document.getElementById("dailiesPhoto")
		var overlay = document.getElementById("docOverlay")
		var strictMode_B = window.document.compatMode == "CSS1Compat"
		var screenHeight = 
				window.innerHeight !== undefined
					? window.innerHeight
					: (window.document.body.clientHeight !== undefined
						? (strictMode_B
							? window.document.documentElement.clientHeight
							: window.document.body.clientHeight
							)
						: -2
						)

		var screenWidth =
				(window.innerWidth !== undefined
					? window.innerWidth
					: (window.document.body.clientWidth !== undefined
						? (strictMode_B
							? window.document.documentElement.clientWidth
							: window.document.body.clientWidth
							)
						: -1
						)
				)

		player.style.top = Math.round((screenHeight / 2) - (photoHeight /2)) + "px"
		player.style.left = Math.round((screenWidth / 2) - (photoWidth /2)) + "px"
		player.style.height = photoHeight + 6 + "px"
		player.style.width = photoWidth + 3 + "px"
		player.style.display = "inline"
		overlay.style.display = "inline"

//COMP:IE6: CSS h/w:100% on abs div not OK;
//SOL: do it here in abs px.
		if (isIE6) {
			overlay.style.height = window.document.body.clientHeight + "px"
			overlay.style.width = window.document.body.clientWidth + "px"
			}

		},

	//--------------------------------------
	hide: function () {
	//--------------------------------------
	// Hide the currently displayed photo.

		var player = document.getElementById("dailiesPhotoLayer")
		var overlay = document.getElementById("docOverlay")
		var photo = document.getElementById("dailiesPhoto")
		var progress = document.getElementById("progressImg")
		if (player && overlay && photo && progress) {
			player.style.display = "none"
			overlay.style.display = "none"
			photo.style.visibility = "hidden"
			progress.style.display = "block"
			}
		},

	//--------------------------------------
	onLoad: function (img) {
	//--------------------------------------
	// Show the currently displayed photo once loaded.
		if (img.src != "") {
			var progress = document.getElementById("progressImg")
			this.setSize(img.width, img.height)
			img.style.visibility = "visible"
			progress.style.display = "none"
			}
		}
	}

