//belenusHome.registerModule("Detail", self); //register module onload...

/* =================================
  customized interface for DetailFrame
================================== */

var APPLET_TABLE_TYPE = 1;
var HTML_TABLE_TYPE = 2;
var currentTableType = APPLET_TABLE_TYPE;

var currentView; // set initial view
if (belenusHome.showImage == "never") currentView = "onlyTable";
else currentView = "imageAndTable";
if(belenusHome.showImageState == null) belenusHome.setShowImageState(currentView);

function messageHandler(message, params) {
  //alert("messageHandler detail: "+message+ "\nparams: "+params);
  if(message == "SetDetailFrameViews") {
    var view = belenusHome.getQueryField(params,"View");
    if(view == "imageAndTable" || view == "onlyImage" || view == "onlyTable") setDetailFrameViews(belenusHome.getQueryField(params,'MIMEType'), view);
    else setDetailFrameViews(belenusHome.getQueryField(params,'MIMEType'), currentView);
  }
}

function getProperty(property, params) {
  return "";
}

function setDetailFrameViews(MIMEType, view) {  //return;
	try {
  var detailsViewsHorizontal = new Array();
  var detailsViewsVertical = new Array();
  var toolbarFrameHeightX = belenusHome.useAppletForStandardImageDisplaying ? belenusHome.toolbarFrameHeight : 0
  
  //
  detailsViewsHorizontal['application/x-hd3'] = new Array();
  detailsViewsHorizontal['application/x-hd3']['imageAndTable'] = belenusHome.toolbarFrameHeight+','+belenusHome.mediaFrameSize+','+belenusHome.partsDrawingHeight+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsHorizontal['application/x-hd3']['onlyImage'] = belenusHome.toolbarFrameHeight+','+belenusHome.mediaFrameSize+',100%,*,'+belenusHome.footnoteFrameSize;
  detailsViewsHorizontal['application/x-hd3']['onlyTable'] = '0,'+belenusHome.mediaFrameSize+',0,*,'+belenusHome.footnoteFrameSize;
  
  detailsViewsVertical['application/x-hd3'] = new Array();
  detailsViewsVertical['application/x-hd3']['imageAndTable'] = belenusHome.toolbarFrameHeight+','+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsVertical['application/x-hd3']['onlyImage'] = belenusHome.toolbarFrameHeight+','+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsVertical['application/x-hd3']['onlyTable'] = '0,'+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;
    
  //
  detailsViewsHorizontal['image/tiff'] = new Array();
  detailsViewsHorizontal['image/tiff']['imageAndTable'] = belenusHome.toolbarFrameHeight+','+belenusHome.mediaFrameSize+','+belenusHome.partsDrawingHeight+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsHorizontal['image/tiff']['onlyImage'] = belenusHome.toolbarFrameHeight+','+belenusHome.mediaFrameSize+',100%,*,'+belenusHome.footnoteFrameSize;
  detailsViewsHorizontal['image/tiff']['onlyTable'] = '0,'+belenusHome.mediaFrameSize+',0,*,'+belenusHome.footnoteFrameSize;
  
  detailsViewsVertical['image/tiff'] = new Array();
  detailsViewsVertical['image/tiff']['imageAndTable'] = belenusHome.toolbarFrameHeight+','+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsVertical['image/tiff']['onlyImage'] = belenusHome.toolbarFrameHeight+','+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsVertical['image/tiff']['onlyTable'] = '0,'+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;  

  //
  detailsViewsHorizontal['image/svg+xml'] = new Array();
  detailsViewsHorizontal['image/svg+xml']['imageAndTable'] = belenusHome.toolbarFrameHeight+','+belenusHome.mediaFrameSize+','+belenusHome.partsDrawingHeight+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsHorizontal['image/svg+xml']['onlyImage'] = belenusHome.toolbarFrameHeight+','+belenusHome.mediaFrameSize+',100%,*,'+belenusHome.footnoteFrameSize;
  detailsViewsHorizontal['image/svg+xml']['onlyTable'] = '0,'+belenusHome.mediaFrameSize+',0,*,'+belenusHome.footnoteFrameSize;
  
  detailsViewsVertical['image/svg+xml'] = new Array();
  detailsViewsVertical['image/svg+xml']['imageAndTable'] = belenusHome.toolbarFrameHeight+','+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsVertical['image/svg+xml']['onlyImage'] = belenusHome.toolbarFrameHeight+','+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsVertical['image/svg+xml']['onlyTable'] = '0,'+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;  

  //
  detailsViewsHorizontal['application/pdf'] = new Array();
  detailsViewsHorizontal['application/pdf']['imageAndTable'] = '0,'+belenusHome.mediaFrameSize+','+belenusHome.partsDrawingHeight+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsHorizontal['application/pdf']['onlyImage'] = '0,'+belenusHome.mediaFrameSize+',100%,*,'+belenusHome.footnoteFrameSize;
  detailsViewsHorizontal['application/pdf']['onlyTable'] = '0,'+belenusHome.mediaFrameSize+',0,*,'+belenusHome.footnoteFrameSize;

  detailsViewsVertical['application/pdf'] = new Array();
  detailsViewsVertical['application/pdf']['imageAndTable'] = '0,'+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsVertical['application/pdf']['onlyImage'] = '0,'+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsVertical['application/pdf']['onlyTable'] = '0,'+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;  
  
  //
  detailsViewsHorizontal['text/html'] = new Array();
  detailsViewsHorizontal['text/html']['imageAndTable'] = '0,'+belenusHome.mediaFrameSize+','+belenusHome.partsDrawingHeight+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsHorizontal['text/html']['onlyImage'] = '0,'+belenusHome.mediaFrameSize+',100%,*,'+belenusHome.footnoteFrameSize;
  detailsViewsHorizontal['text/html']['onlyTable'] = '0,'+belenusHome.mediaFrameSize+',0,*,'+belenusHome.footnoteFrameSize;
  
  detailsViewsVertical['text/html'] = new Array();
  detailsViewsVertical['text/html']['imageAndTable'] = '0,'+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsVertical['text/html']['onlyImage'] = '0,'+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsVertical['text/html']['onlyTable'] = '0,'+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;  
  
  //
  detailsViewsHorizontal['application/x-xvlplayer'] = new Array();
  detailsViewsHorizontal['application/x-xvlplayer']['imageAndTable'] = belenusHome.toolbarFrameHeight+','+belenusHome.mediaFrameSize+','+belenusHome.partsDrawingHeight+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsHorizontal['application/x-xvlplayer']['onlyImage'] = belenusHome.toolbarFrameHeight+','+belenusHome.mediaFrameSize+',100%,*,'+belenusHome.footnoteFrameSize;
  detailsViewsHorizontal['application/x-xvlplayer']['onlyTable'] = '0,'+belenusHome.mediaFrameSize+',0,*,'+belenusHome.footnoteFrameSize;
  
  detailsViewsVertical['application/x-xvlplayer'] = new Array();
  detailsViewsVertical['application/x-xvlplayer']['imageAndTable'] = belenusHome.toolbarFrameHeight+','+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsVertical['application/x-xvlplayer']['onlyImage'] = belenusHome.toolbarFrameHeight+','+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsVertical['application/x-xvlplayer']['onlyTable'] = '0,'+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;
  
  //
  detailsViewsHorizontal['image/cgm'] = new Array();
  detailsViewsHorizontal['image/cgm']['imageAndTable'] = '0,'+belenusHome.mediaFrameSize+','+belenusHome.partsDrawingHeight+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsHorizontal['image/cgm']['onlyImage'] = '0,'+belenusHome.mediaFrameSize+',100%,*,'+belenusHome.footnoteFrameSize;
  detailsViewsHorizontal['image/cgm']['onlyTable'] = '0,'+belenusHome.mediaFrameSize+',0,*,'+belenusHome.footnoteFrameSize;

  detailsViewsVertical['image/cgm'] = new Array();  
  detailsViewsVertical['image/cgm']['imageAndTable'] = '0,'+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsVertical['image/cgm']['onlyImage'] = '0,'+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsVertical['image/cgm']['onlyTable'] = '0,'+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;
  
  //
  detailsViewsHorizontal['image/jpeg'] = new Array();
  detailsViewsHorizontal['image/jpeg']['imageAndTable'] = toolbarFrameHeightX+','+belenusHome.mediaFrameSize+','+belenusHome.partsDrawingHeight+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsHorizontal['image/jpeg']['onlyImage'] = toolbarFrameHeightX+','+belenusHome.mediaFrameSize+',100%,*,'+belenusHome.footnoteFrameSize;
  detailsViewsHorizontal['image/jpeg']['onlyTable'] = '0,'+belenusHome.mediaFrameSize+',0,*,'+belenusHome.footnoteFrameSize;

  detailsViewsVertical['image/jpeg'] = new Array();  
  detailsViewsVertical['image/jpeg']['imageAndTable'] = toolbarFrameHeightX+','+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsVertical['image/jpeg']['onlyImage'] = toolbarFrameHeightX+','+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsVertical['image/jpeg']['onlyTable'] = '0,'+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;
  
  //
  detailsViewsHorizontal['image/gif'] = new Array();
  detailsViewsHorizontal['image/gif']['imageAndTable'] = toolbarFrameHeightX+','+belenusHome.mediaFrameSize+','+belenusHome.partsDrawingHeight+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsHorizontal['image/gif']['onlyImage'] = toolbarFrameHeightX+','+belenusHome.mediaFrameSize+',100%,*,'+belenusHome.footnoteFrameSize;
  detailsViewsHorizontal['image/gif']['onlyTable'] = '0,'+belenusHome.mediaFrameSize+',0,*,'+belenusHome.footnoteFrameSize;

  detailsViewsVertical['image/gif'] = new Array();  
  detailsViewsVertical['image/gif']['imageAndTable'] = toolbarFrameHeightX+','+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsVertical['image/gif']['onlyImage'] = toolbarFrameHeightX+','+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsVertical['image/gif']['onlyTable'] = '0,'+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;    
  
  //
  detailsViewsHorizontal['image/png'] = new Array();
  detailsViewsHorizontal['image/png']['imageAndTable'] = toolbarFrameHeightX+','+belenusHome.mediaFrameSize+','+belenusHome.partsDrawingHeight+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsHorizontal['image/png']['onlyImage'] = toolbarFrameHeightX+','+belenusHome.mediaFrameSize+',100%,*,'+belenusHome.footnoteFrameSize;
  detailsViewsHorizontal['image/png']['onlyTable'] = '0,'+belenusHome.mediaFrameSize+',0,*,'+belenusHome.footnoteFrameSize;

  detailsViewsVertical['image/png'] = new Array();  
  detailsViewsVertical['image/png']['imageAndTable'] = toolbarFrameHeightX+','+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsVertical['image/png']['onlyImage'] = toolbarFrameHeightX+','+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;
  detailsViewsVertical['image/png']['onlyTable'] = '0,'+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize;    
  
 
  if((belenusHome.detailFrameArrangement == "horizontal" && detailsViewsHorizontal[MIMEType]) || (belenusHome.detailFrameArrangement == "vertical" && detailsViewsVertical[MIMEType])) {
  	if(belenusHome.detailFrameArrangement == "horizontal") {
	// 	alert("detailsViewsHorizontal[MIMEType][view]: "+detailsViewsHorizontal[MIMEType][view]+"\n\nMIMEType: "+MIMEType+"\n\nview: "+view);
	    document.getElementById('detailsframeset').setAttribute("rows",detailsViewsHorizontal[MIMEType][view]);
	} else {
	//	alert("detailsViewsHorizontal[MIMEType][view]: "+detailsViewsHorizontal[MIMEType][view]+"\n\nMIMEType: "+MIMEType+"\n\nview: "+view);
        document.getElementById('detailsframeset').setAttribute("rows",detailsViewsVertical[MIMEType][view]);
        var subFramesetSetting = belenusHome.partsDrawingHeight+',*';
        if(view == "onlyImage") subFramesetSetting = "100%,*";
        else if(view == "onlyTable") subFramesetSetting = "*,100%";
    	document.getElementById('subdetailframeset').setAttribute("cols",subFramesetSetting);
    }
    currentView = view;
  } else if(belenusHome.showImage == "ifAvailable" || belenusHome.showImage == "never") {
  	if(belenusHome.detailFrameArrangement == "horizontal") {
    	document.getElementById('detailsframeset').setAttribute("rows","0,"+belenusHome.mediaFrameSize+",0,*,"+belenusHome.footnoteFrameSize);
    } else {
    	document.getElementById('detailsframeset').setAttribute("rows",'0,'+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize);
    	document.getElementById('subdetailframeset').setAttribute("cols","*,100%");
    }
  } else {
	  	if(belenusHome.detailFrameArrangement == "horizontal") {
	  		document.getElementById('detailsframeset').setAttribute("rows",belenusHome.toolbarFrameHeight+','+belenusHome.mediaFrameSize+','+belenusHome.partsDrawingHeight+',*,'+belenusHome.footnoteFrameSize);
	  	} else {
		  	document.getElementById('detailsframeset').setAttribute("rows",belenusHome.toolbarFrameHeight+','+belenusHome.mediaFrameSize+',*,'+belenusHome.footnoteFrameSize);
		  	document.getElementById('subdetailframeset').setAttribute("cols",belenusHome.partsDrawingHeight+",*");
	  	}
	}

  	//ieFrameResizeTroubleShooter
	if(belenusHome.browserName == "Internet Explorer") {
		try {
		  	top.resizeBy(1,-1);
		  	top.resizeBy(-1,1);
	  	} catch(e) {
	  		//throw e
	  	}
	}

	} catch(e) {
		alert(e.message);
	}
}

function getimageviewHeight(percentSign) {
  var c = belenusHome.imageviewHeight+"";
  if(!percentSign) {
    c = c.replace(/%/,"");	
  }
  return c;
}

// workaround for ms+jvm repaint problem with frame resizing
var resizeTimeoutBin;
var jV = belenusHome.getXCookie("j")+""; // cookie is set in the viewer/index.jsp
var throwResizeEvent= (belenusHome.browserName=="Internet Explorer"&&jV.indexOf("Sun")!=-1) ? true : false;
function startResizing() { // called by the onresize attribute in the table frame
	if(!throwResizeEvent) {clearTimeout(resizeTimeoutBin);return;}
	clearTimeout(resizeTimeoutBin);
	belenusHome.resizeTimeoutBin = setTimeout('belenusHome.eventHandler("TableFrameResizeEnd","");',200);
}