//******************************************************
// all the javascript stuff for the consed-Like-viewer in contigbean
//
// author:  Mike Imelfort
// created: 31-july-2007
//
//******************************************************
//******************************************************
//
//  GLOBAL VARIABLES FOR THE CONTIG VIEWER
//
//
//******************************************************


 // this is the main width for all tables on the page
 // change the image width to suit when changing this variable
 // image width is set in ContigBean.java

MAIN_TABLE_WIDTH = 960;
MAIN_TABLE_HEIGHT = 505;


 // for the consed-viewer
CONSED_LABEL_WIDTH = 86;
consWidth = MAIN_TABLE_WIDTH - 2;
consDiv = MAIN_TABLE_WIDTH - CONSED_LABEL_WIDTH - 2;
    
 // for the SBS viewer
currentSNPIndex = 0;
//******************************************************

function setAllWidths() {
    // call this on start to set the width of all things
    document.getElementById('blastHeader').style.width = MAIN_TABLE_WIDTH + "px";
    document.getElementById('mainHeader').style.width = MAIN_TABLE_WIDTH + "px";
    document.getElementById('blastListing').style.width = MAIN_TABLE_WIDTH + "px";
    document.getElementById('snpHeader').style.width = MAIN_TABLE_WIDTH + "px";
    
    y = document.getElementById('snpImage');
    if(y) {
        y.style.width = MAIN_TABLE_WIDTH + "px";

    }
    y = document.getElementById('snpListing')
    if(y) {
        y.style.width = MAIN_TABLE_WIDTH + "px";
    }
    document.getElementById('estTable').style.width = MAIN_TABLE_WIDTH + "px";
    document.getElementById('estListing').style.width = MAIN_TABLE_WIDTH + "px";
    document.getElementById('consedMain').style.width = consWidth + "px";
    document.getElementById('GBblastHeader').style.width = MAIN_TABLE_WIDTH + "px";
    document.getElementById('GOHeader').style.width = MAIN_TABLE_WIDTH + "px";
    document.getElementById('RefHeader').style.width = MAIN_TABLE_WIDTH + "px";
    document.getElementById('swissHeader').style.width = MAIN_TABLE_WIDTH + "px";
    document.getElementById('gbblastlisting').style.width = MAIN_TABLE_WIDTH + "px";
    document.getElementById('golisting').style.width = MAIN_TABLE_WIDTH + "px";
    document.getElementById('reflisting').style.width = MAIN_TABLE_WIDTH + "px";
    document.getElementById('swissListing').style.width = MAIN_TABLE_WIDTH + "px";
  
    document.getElementById('consedDivLabel').style.height = MAIN_TABLE_HEIGHT + "px";
    document.getElementById('consedDivLabel').style.width = CONSED_LABEL_WIDTH + "px";
    document.getElementById('consedDivSeq').style.height = MAIN_TABLE_HEIGHT + "px";
    document.getElementById('consedDivSeq').style.width = consDiv + "px"; 
    document.getElementById('labelTop').style.width = CONSED_LABEL_WIDTH + "px";
    document.getElementById('contigTop').style.width = consDiv + "px";
    
    document.getElementById('consedDivLabelSBS').style.height = MAIN_TABLE_HEIGHT + "px";
    document.getElementById('consedDivLabelSBS').style.width = CONSED_LABEL_WIDTH + "px";
    document.getElementById('consedDivSeqSBS').style.height = MAIN_TABLE_HEIGHT + "px";
    document.getElementById('consedDivSeqSBS').style.width = consDiv + "px"; 
    document.getElementById('labelTopSBS').style.width = CONSED_LABEL_WIDTH + "px";
    document.getElementById('contigTopSBS').style.width = consDiv + "px";

}

function centerSnp(snpIndex, seqLength, minCon, off, seqCount) {
 // center a SNP on the screen
    if(document.getElementById('allSNPdata').style.display=="inline") {
        // CONSED VIEWER

        if(snpIndex-minCon <= off)
        {
            setScroll(0);
        }
        else if(snpIndex-minCon >= seqLength - off)
        {
            setScroll(document.getElementById('consedDivSeq').scrollWidth);
        }
        else
        {
            setScroll(document.getElementById('consedDivSeq').scrollWidth * (snpIndex - off - minCon) / seqLength);
        }
    }
    else
    {
        // SBS viewer
        for(i = 0; i < seqCount; i++)
 {
            if(currentSNPIndex !=0){
                document.getElementById(i.toString()+"SBS"+currentSNPIndex.toString()).style.borderRight='solid white 1px';
                document.getElementById(i.toString()+"SBS"+currentSNPIndex.toString()).style.borderLeft='solid white 1px';
            }
            document.getElementById(i.toString()+"SBS"+snpIndex.toString()).style.borderRight='solid black 1px';
            document.getElementById(i.toString()+"SBS"+snpIndex.toString()).style.borderLeft='solid black 1px';
        }
        for(i = 0; i < 4; i++) {
            if(currentSNPIndex !=0){
                document.getElementById("SBS"+currentSNPIndex.toString()+i.toString()).style.borderRight='solid white 1px';
                document.getElementById("SBS"+currentSNPIndex.toString()+i.toString()).style.borderLeft='solid white 1px';
            }
            document.getElementById("SBS"+snpIndex.toString()+i.toString()).style.borderRight='solid red 1px';
            document.getElementById("SBS"+snpIndex.toString()+i.toString()).style.borderLeft='solid red 1px';
        }
        currentSNPIndex = snpIndex;
    }
}

function setScroll(newValue) {
 // set the scroll bar position from the consed div...
 
    document.getElementById('consedDivSeq').scrollLeft = newValue;
}

