var hasShow=false


function isIE(){
	if(navigator.userAgent.toLowerCase().indexOf('msie') + 1)
		return true
	else
		return false
}

function ontdMouseOver(obj){
	hasShow=true
	obj.className="mouseOver"
}

function ontdMouseOut(obj){
	hasShow=false
	obj.className="mouseOut"
}

function goTo(url){
	if(url.search("fleet/ships/")>=0){
		document.getElementById("hiddenPringDiv").style.display="block"		
		document.getElementById("backToTop").style.display="none"	
		
	}
	else{
		document.getElementById("hiddenPringDiv").style.display="none"
		document.getElementById("backToTop").style.display="block"	
	}
	
	if(url=='fleet/fleet.html'){						
		document.getElementById("fleetTabDIV").style.display="block"
		document.getElementById("mainFrame").style.display="none"
	}
	else{
		mainFrame.window.location=url
		document.getElementById("mainFrame").style.display="block"
		document.getElementById("fleetTabDIV").style.display="none"
		
	}
	
}



function doOnResize(){
	if(divOBJ!=""){		
		
		reposition()		
	}
}

function reposition(){	
	if(isIE()){
		divOBJ.style.width=getElementWidth(tdID)+2+ 'px';
		divOBJ.style.left=findPosX(tdOBJ)+ 'px';
		divOBJ.style.top=findPosY(tdOBJ)+26+ 'px';
	}		
	else{		
		divOBJ.style.width=getElementWidth(tdID)+ 'px';
		divOBJ.style.left=findPosX(tdOBJ)-1+ 'px';
		divOBJ.style.top=findPosY(tdOBJ)+25+ 'px';
	}	
}


var tdID = ""
var tdOBJ = ""
var divID  = ""
var divOBJ = ""

function show(id){
	
	hide()
	divID = id+"div"
	tdID = id+"td"	

	divOBJ = document.getElementById(divID)
	divOBJ.style.visibility="visible"		

	tdOBJ = document.getElementById(tdID)
	
	if(isIE()){
		divOBJ.style.width=getElementWidth(tdID)+2+ 'px';
		divOBJ.style.left=findPosX(tdOBJ)+ 'px';
		divOBJ.style.top=findPosY(tdOBJ)+26+ 'px';
	}		
	else{
		divOBJ.style.width=getElementWidth(tdID)+ 'px';
		divOBJ.style.left=findPosX(tdOBJ)-1+ 'px';
		divOBJ.style.top=findPosY(tdOBJ)+25+ 'px';
	}	
}

function hide(){	
	if(divOBJ!=""&&!hasShow){
		divOBJ.style.visibility="hidden"
		divOBJ=""		
	}
}

function getElementWidth(Elem) {

	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
	xPos = elem.offsetWidth;

	return xPos;

}

function getElementHeight(Elem) {

	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
	xPos = elem.offsetHeight;

	return xPos;

}




function findPosX(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 findPosY(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;
}

function adjustFrame(){
	
	if(isIE()){		
		document.getElementById('mainFrame').style.height =mainFrame.document.body.scrollHeight + 35+ 'px';
		
	}
	else	{		
		document.getElementById('mainFrame').style.height = mainFrame.document.body.scrollHeight + 16+ 'px';
	}
}

function mouseDown(){
	alert("down")
}

function mouseUp(){
	alert("Up")
}


function pausecomp(millis)
{
	date = new Date();
	var curDate = null;

	do { var curDate = new Date(); }
	while(curDate-date < millis);
}

var showSHIP=0

var shipNumber=8

function showShipDetails(alink, url, shipID){
	
	
	var thisTR = alink.parentNode.parentNode.parentNode
	
	var item = document.getElementById('shipDetailFrame')
	
	var hideDiv = document.getElementById('hideDiv'+shipID)
	var printHideDiv = document.getElementById('printHideDiv'+shipID)
	
	var showDiv = document.getElementById('showDiv'+shipID)
	var printShowDiv = document.getElementById('printShowDiv'+shipID)
	

	
	
	position(thisTR, 'shipDetailFrame')
			
	
	if(showSHIP==0||showSHIP!=shipID){
		showDiv.style.display="none"
		printShowDiv.style.display="none"
		
		hideDiv.style.display="block"
		printHideDiv.style.display="block"
		
		item.src= url
		if(showSHIP!=0){			
			document.getElementById('hideDiv'+showSHIP).style.display="none"
			document.getElementById('printHideDiv'+showSHIP).style.display="none"
					
			document.getElementById('showDiv'+showSHIP).style.display="block"
			document.getElementById('printShowDiv'+showSHIP).style.display="block"
		}
		
		showSHIP=shipID
		
		var finalHeight = 2030
		if(shipID==5|| shipID==6 || shipID==8){
			finalHeight = 2260
		}
		
		changeHeight('shipDetailFrame', finalHeight, 5)
	}
	else{		
		showDiv.style.display="block"
		printShowDiv.style.display="block"
		
		hideDiv.style.display="none"		
		printHideDiv.style.display="none"		
		
		showSHIP=0
		clearTimeout(heightTimeout)
		item.style.height=0
		item.style.display="none"
		item.src=""
	}	
		
}

var heightTimeout

function changeHeight(id, newHeight, wait){
	var item = document.getElementById(id)

	item.style.display = "block"

	var currentHeight = parseInt(item.style.height.substring(0, item.style.height.length-2))
	
	var heightToAdd=20
	
	if(currentHeight>(newHeight*0.2)){
		heightToAdd=200
	}

	if(currentHeight<newHeight){
		var interHeight = currentHeight+heightToAdd	
		if(interHeight>newHeight){
			interHeight=newHeight
		}
		
		item.style.height=interHeight +"px"
		
		
		heightTimeout = window.setTimeout( "changeHeight( '"+ id +"' ," + newHeight +" ," + wait +  ")", wait )
	}
	else{
		
	}
}

function position(row, frameID){
	//var row = document.getElementById(rowID)
	var shipFrame = document.getElementById(frameID)

	var rowPosX = findPosX(row)
	var rowPosY = findPosY(row)+ row.offsetHeight

	shipFrame.style.width = row.offsetWidth
	shipFrame.style.top = rowPosY+"px"
	shipFrame.style.left = rowPosX+"px"

}

function printFrame(frameName){	
	
	if (isIE())
	{
		eval("document."+frameName).focus();
		eval("document."+frameName).window.print();
	}
	else
	{
		window.frames[frameName].focus();
		window.frames[frameName].window.print();
	}
} 



document.onclick=hide
window.onresize = doOnResize


