// Rimnetics Examples page PhotoLink & PhotoDiv popups
var PhotoDivOn = false;
var PhotoDivTimeout;
addOnloadEvent(function(){
	// Start all PhotoLinks hidden
	$(".PhotoLink").css({opacity:0});
	// animate each PhotoLink's entry, and setup click event to open PhotoDivs
	$(".PhotoLink").each(function() {
		if ($(this).attr("rel") == "blank")
			$(this).css({cursor:"default",display:"block"}).animate({opacity: 0}, Math.ceil(Math.random()*500)).animate({opacity: 1}, 250);
		else
			$(this).css({display:"block"}).animate({opacity: 0}, 500+Math.ceil(Math.random()*1500)).animate({opacity: 1}, 500);
		var PhotoLinkID;
		$(this).click(function(){
			hideAllPhotoDivs();
			PhotoLinkID = $(this).attr("rel");
			if ($("#"+PhotoLinkID).css("display") == "none") {
				$("#"+PhotoLinkID).customFadeIn(500);
				clearTimeout(PhotoDivTimeout);
				PhotoDivTimeout = setTimeout(function(){PhotoDivOn=true;},500);
			}
		});
	});
	
	// setup body click handler to hide PhotoDiv
	$("body").click(function(){
		if (PhotoDivOn) {
			hideAllPhotoDivs();
		}
	});
	// stop propogation of body click event to PhotDivs and PhotoLinks
	$(".PhotoDiv").click(function(event){
		event.stopPropagation();
	});
	$(".PhotoLink").click(function(event){
		event.stopPropagation();
	});
	// hide PhotoDivs onclick on any image inside
	$(".PhotoDiv * img").click(function(){
		hideAllPhotoDivs();
	});
	
	// preload all rollovers, and add roll class to all images in table
	var i = new Array();
	var iCount = 0;
	$(".structuralEnclosureTable * img").each(function(){
		$.preloadImages($(this).attr("src").replace(".gif","-over.gif"));
		if ($(this).attr("src").indexOf("blank.gif") == -1) {
			$(this).attr("class","roll");
		}
	});
	$(".roll").hover(function(){
		if ($(this).attr("src").indexOf("-over.gif") == -1)
			$(this).attr("src",$(this).attr("src").replace(".gif","-over.gif"));
	},
	function() {
		if ($(this).attr("src").indexOf("-over.gif") != -1)
			$(this).attr("src",$(this).attr("src").replace("-over.gif",".gif"));
	});

});

function hideAllPhotoDivs() {
	$(".PhotoDiv").customFadeOut(500);
	clearTimeout(PhotoDivTimeout);
	PhotoDivTimeout = setTimeout(function(){PhotoDivOn=false;},500);
}

