function docLoaded(){
	setFuncs();
}

function showImg(o){
		var strSrc=o.src.toString();
		var theBigImg=strSrc.replace(/tn\//,"");
		var w=window.open("","Preview","height=600,width=800,resizable");
		w.document.body.innerHTML="<img src=" + theBigImg + ">";
		w.focus( );
}

function getEl(id){
	return document.getElementById(id);	
}

function setFuncs(){
	var Menu=getEl("tdMenu");
	var c=Menu.children;	
	var t=getEl("TopMenu");
	t.innerHTML="";
	var fover=function(){this.style.backgroundColor="#CCCCCC";doItem(this);};
	var fout=function(){this.style.backgroundColor="";};
	var h="";
	
	for (var i=0;i<c.length;i++){
		var d=newDiv();
		if (c[i].children.length>1){
			h=c[i].children[1].outerHTML;
		}else{
			h="";
		}
		d.innerHTML=c[i].children[0].outerHTML + h;
		
		d.onmouseover=fover;
		d.onmouseout=fout;
		t.appendChild(d);
		
		c[i].onmouseover=fover;	
		c[i].onmouseout=fout;
	}
	SubMenu.onmouseleave=function(){this.timerid=setTimeout("fadeMenu()",750);};
	SubMenu.onmouseover=function(){clearTimeout(this.timerid);};
	
	
}

function doClick(o){
	SubMenu.timerid=setTimeout("fadeMenu()",2500);
	var c=o.parentNode.children;
	var img=getEl("imgDiv");
	var btnA=getEl("btnAdd");
	var btnR=getEl("btnRemove");
	var title=o.innerText;
	if (c.length>1){
		img.innerHTML="";
		getEl("tdMain").innerHTML=c[1].innerHTML;
		if (c.length>2){
			doImages(img,c);
		}else{
			var img=document.createElement("img");
			img.src="Images/imLogo.gif";
			img.onclick="";
			ImagesDiv.appendChild(img);
		}
	}else{
		getEl("tdMain").innerHTML="Under Construction!!!";	
	}
	
	btnA.title=title;
	btnR.title=title;
	
}

function addItem(o){
	var el=frames["IMiFrame"].document.imForm.Comments
	if (el.value.indexOf(o.title) ==-1){
		el.value+="\n"+o.title;
	}
	var r=/\n\r/g;
	el.value=el.value.replace(r,"");
	
	
}
function removeItem(o){
	var el=frames["IMiFrame"].document.imForm.Comments
	el.value=el.value.replace(o.title,"");
	var r=/\n\r/g;
	el.value=el.value.replace(r,"");
}

function doImages(ImagesDiv,c){
	for (var i=c.length-1;i>1;i--){
		var img=document.createElement("img");
		img.src="Images/tn/" + c[i].innerText;
		img.style.width="160px";
		img.style.height="160px";
		img.onclick=function(){showImg(this);};
		ImagesDiv.appendChild(img);
	}
}

function newDiv(){
	var d=document.createElement("div");
	document.body.appendChild(d);
	return d;
	
	
}

function doItem(o){
	clearTimeout(SubMenu.timerid);
	var w=0;
	var h=0;
	if (o.parentNode.tagName=="TD")	{
		w=o.offsetWidth;
	}else{
		h=o.offsetHeight;	
	}
	
	var x=PosX(o)+w;
	var y=PosY(o)+h;
	SubMenu.style.left=x;
	SubMenu.style.top=y;
	if (o.children.length>1) {
		SubMenu.innerHTML=o.children[1].outerHTML;
		SubMenu.style.display="block";
		
		var em=SubMenu.getElementsByTagName("em");
		for (var z=0;z<em.length;z++){
			em[z].onmouseover=function(){this.style.backgroundColor="#CCCCCC";};
			em[z].onmouseout=function(){this.style.backgroundColor="";};
		}
	}else{
		SubMenu.style.display="none"	
	}
}

function fadeMenu(){
	SubMenu.style.display="none";
}


function PosX(obj){
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function PosY(obj){
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

