var lastInvoker = 0;	// last anchor-invoker
var marker = document.createElement("img");
marker.id = "marker";
marker.src = "popup/images/number.gif";
marker.style.position = "absolute";

marker.style.zIndex = -1;

var isIE = (navigator.appVersion.indexOf("MSIE") != -1);	// is Internet Explorer
//var isOpera = (navigator.userAgent.indexOf("Opera") != -1);	// is Opera
function waitUntilFirstAnchorLoadedRoutine(){	
	if (documentLoaded==null){
		window.alert("call images.js after common.js");
	}
	
	if (document.getElementById("firstAnchor")==null)
		if (documentLoaded==true){
			window.alert("element with id = \"firstAnchor\" not found");
			return;
		}
		else{
			window.setTimeout("waitUntilFirstAnchorLoadedRoutine();",100);
		}
	else{		
		markFirstLink();		
	}

}

function markFirstLink(){	
	if (!lastInvoker.firstChild){
		lastInvoker = document.getElementById("firstAnchor");
		markLink(lastInvoker);
	}
	if (window.location.href.indexOf("=")!=-1){	
	
		photoNumber = window.location.href.substring(window.location.href.indexOf("=")+1, window.location.href.length);
		
		var invoker = document.getElementById("links_pod_photo");
		
		loadImage(invoker.tBodies[0].rows[0].cells[parseInt(photoNumber,10)-1].firstChild,'img/ph/history/' + photoNumber + '.jpg');
	}
}

window.setTimeout("waitUntilFirstAnchorLoadedRoutine();",50);

loadImage = function(invoker, src){
	if (!lastInvoker.firstChild){		
		lastInvoker = document.getElementById("firstAnchor");		
	}

	unmarkLink(lastInvoker);
	
	if (document.getElementById('image').src.indexOf(src)==-1){
		document.getElementById('loading').innerHTML='Загружается...';	
		window.setTimeout(function(){document.getElementById('image').src=src;},10);
	}
		
	markLink(invoker);
	
	lastInvoker = invoker;
}

function markLink(invoker){
	/*invoker.style.background = "url(\"popup/images/number.gif\") no-repeat";
	if (isIE){
		lastInvoker.firstChild.style.filter="alpha(opacity=100)";
	}
	else{
		lastInvoker.firstChild.style.opacity = "1";
	}*/
	//invoker.style.paddingTop = "3px";
	//invoker.style.backgroundColor = "rgb(207, 205, 104)";
	invoker.style.zIndex = 2;
	marker.style.marginTop = "3px";
	var offsetLeft = -invoker.parentNode.offsetWidth/2;
	if (offsetLeft==0) offsetLeft=-11;
	marker.style.marginLeft = offsetLeft + "px";
	invoker.parentNode.appendChild(marker);
	invoker.parentNode.zIndex = -1;
	
}

function unmarkLink(lastInvoker){
	/*lastInvoker.style.background = "";
	//lastInvoker.style.backgroundColor = "";
	
	if (isIE){
		lastInvoker.firstChild.style.filter="alpha(opacity=25)";
	}
	else{
		lastInvoker.firstChild.style.opacity = ".25";
	}*/
	
}
