function menuItemClick(ref) {
	animateShow("docTitle",1);
	animateHide("illustration",1);
	anim.slideOut();
	setTimeout("gotoUrl('anim.html')",2000)
}
function gotoUrl(url){
	location=url;
}
function openRootLocation(location, elementId, docId, imageId) {
    selected=document.getElementById("menu_"+elementId+"_item");
    openLocation(location, elementId, docId, imageId);
}
function openSubLocation(location, elementId, docId, imageId, rootId) {
    selected=document.getElementById(rootId);
    MoveLightTo(selected);
    openLocation(location, elementId, docId, imageId);
}
function openLocation(location, elementId, docId, imageId) {
    try {
	animateShow("docTitle",1);
	animateHide("illustration",1);
	anim.slideOut();
    } catch (ex) {
        alert(ex);
    }
    setTimeout("initalizeDownload('"+location+"','"+elementId+"','"+docId+"','"+imageId+"')",2000);
}

function initalizeDownload(location, elementId, docId, imageId) {
    var contentObj=document.getElementById("content");
    contentObj.innerHTML="";
    var illustrastionObj=document.getElementById("illustration");
    illustrastionObj.innerHTML="";
    if (imageId!=null) {
        img=new Image();
        img.src="/servlets/Image/obj="+imageId;
    } else {
        img==null;
    }
    loadDoc(location);

}

function initalizeDownload2(ref) {
    var contentObj=document.getElementById("content");
    contentObj.innerHTML="";
    var illustrastionObj=document.getElementById("illustration");
    illustrastionObj.innerHTML="";
    img==null;
    loadDoc(ref);
}

var req;

function loadDoc(url) {
	document.location=url;
	req = false;
    // branch for native XMLHttpRequest object
    /*if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
	}
    }
    if(req) {
	req.onreadystatechange = processReqChange;
	req.open("GET", url, true);
	req.send("");
    }*/
}

function processReqChange() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            var content=document.getElementById("content");
            content.innerHTML=req.responseText;
            tryShow();
        } else {
            alert("There was a problem retrieving the page data:\n" +
                req.statusText);
            gotoUrl("/");
        }
    }
}

var notLoadedImages=null;

function tryShow() {
    //
    rebuildNotLoadedList();
    if ((img==null || img.complete==true) && notLoadedImages.length==0) {
        var obj=document.getElementById("illustration");
	animateHide("docTitle",1);
	if (img!=null) {
	        obj.innerHTML='<img src="'+img.src+'" border="0">';
        	notLoadedImages=null;
		animateShow("illustration",1);
	}
	anim=new GridAnimator("content");
	anim.spacing[1]=20;
	anim.lineAnimationStartInterval=100;
	anim.createHGrid(1);
	anim.slideIn();
    } else 
        setTimeout("tryShow()",1000);
}

function buildNotLoadedList() {
    var images=document.getElementsByTagName("img");
    notLoadedImages=new Array(0);
    for (var i=0;i<images.length;i++) {
        var tmp=new Image();
        tmp.src=images[i].src;
        if (!tmp.complete)
            notLoadedImages.push(tmp);
    }
}

function rebuildNotLoadedList() {
    if (notLoadedImages==null) {
        buildNotLoadedList();
        return;
    }
    var tmp=new Array(0);
    for (var i=0;i<notLoadedImages.length;i++) {
        if (!notLoadedImages[i].complete)
            tmp.push(notLoadedImages[i]);
    }
    notLoadedImages=tmp;
}
