/**
 * @author abazzone
 */
var selectButton;

pageTitle = document.title;
parent.document.title = pageTitle;

function mDown(theId){
    fileName = document.getElementById(theId).src.split('/');
    selectButton = theId;
    if (fileName[fileName.length - 1].indexOf('-off') != -1) {
        if (theId == 'diagnosticTool') {
            location.href = 'startAssess.html';            
        }
        else {
            location.href = 'caseGallery.html';
        }
    }
}

function mOver(theId){
    fileName = document.getElementById(theId).src.split('/');
    if (fileName[fileName.length - 1].indexOf('_off') != -1) 
        fileName = theId + "_on.gif";
    document.getElementById(theId).src = "images/buttons/" + fileName;
}

function mOut(theId){
    fileName = document.getElementById(theId).src.split('/');
    if (fileName[fileName.length - 1].indexOf('_on') != -1) 
        fileName = theId + "_off.gif"
    document.getElementById(theId).src = "images/buttons/" + fileName;
}

function gaOver(theId){
    theSrc = document.getElementById(theId).src.replace(/-off/g, "-on");
    document.getElementById(theId).src = theSrc;
    document.getElementById("click").play();
    //document.getElementById("sound").innerHTML=
    "<embed src=\"sound/click2.wav\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";
}

function gaOut(theId){
    theSrc = document.getElementById(theId).src.replace(/-on/g, "-off");
    document.getElementById(theId).src = theSrc;
}

function gaOn(theId){
    location.href = 'cg_viewer.html?slide=' + theId;
}

function getPos(This){
    var el = This;
    var pL = 0;
    while (el) {
        pL += el.offsetLeft;
        el = el.offsetParent;
    }
    return pL;
}

function getTopPos(This){
    var el = This;
    var pL = 0;
    while (el) {
        pL += el.offsetTop;
        el = el.offsetParent;
    }
    return pL;
    
}

function setPos(){
      
   /*
    * ** This code may be used in future if tabs are added to UI 
    * tab1a = document.getElementById('tab1');
    tab1Pos = startPoint + 40;
    tab1a.style.left = tab1Pos + "px";
    tab2a = document.getElementById('tab2');
    tab2Pos = startPoint + 225;
    tab2a.style.left = tab2Pos + "px";
    tab1a.attachEvent('onmouseover', function(){
        tab1a.style.cursor = 'pointer';
    });
    tab2a.attachEvent('onmouseover', function(){
        tab2a.style.cursor = 'pointer';
    });
    tab1a.attachEvent('onmousedown', function(){
        mDown('caseGallery');
    });
    tab2a.attachEvent('onmousedown', function(){
        mDown('diagnosticTool')
    });
    var dTool = document.getElementById('diagnosticTool');
    var cGall = document.getElementById('caseGallery');
    if (selectButton == "caseGallery") {
        dTool.style.zIndex = 5;
        tab1a.style.color = "#000";
        tab2a.style.color = "#fff";
        dTool.src = "images/buttons/tab-off.gif";
        dTool.disabled = false;
        dTool.style.visibility = 'hidden'; // tabs are not being shown now
        tab2a.disabled = false;
        cGall.src = "images/buttons/tab-on.gif";
        cGall.disabled = true;
        tab1a.disabled = true;
        cGall.style.visibility = 'hidden'; // tabs are not being shown now
    }
    else {
        dTool.style.zIndex = 50;
        tab2a.style.color = "#000";
        tab1a.style.color = "#fff";
        dTool.src = "images/buttons/tab-on.gif";
        dTool.disabled = true;
        tab2a.disabled = true;
        cGall.src = "images/buttons/tab-off.gif";
        cGall.disabled = false;
        tab1a.disabled = false;
    }
    tab1a.style.visibility = 'hidden';
    tab2a.style.visibility = 'hidden';*/
	
}


function initScrollLayer(){
    // arguments: id of layer containing scrolling layers (clipped layer), id of layer to scroll, 
    // if horizontal scrolling, id of element containing scrolling content (table?)
    var wndo = new dw_scrollObj('wn', 'lyr1');
    
    // bSizeDragBar set true by default (explained at www.dyn-web.com/dhtml/scroll/ )
    // wndo.bSizeDragBar = false;
    
    // arguments: dragBar id, track id, axis ("v" or "h"), x offset, y offset
    // (x/y offsets of dragBar in track)
    wndo.setUpScrollbar("dragBar", "track", "v", 1, 1);
    
    // pass id('s) of scroll area(s) if inside table(s)
    // i.e., if you have 3 (with id's wn1, wn2, wn3): dw_scrollObj.GeckoTableBugFix('wn1', 'wn2', 'wn3');
    dw_scrollObj.GeckoTableBugFix('wn');
    
    // sometimes ns6+ needs extra help to position correctly
    // dw_scrollObj.rePositionGecko();
    theDivHeight = document.getElementById("lyr1").offsetHeight;
    if (theDivHeight > 199) 
        document.getElementById("scrollbar").style.visibility = "visible";
    else 
        document.getElementById("scrollbar").style.visibility = "hidden";
    
}

window.onload = new function(){
    window.onresize = setPos;
};

function shadeOn(){
    shadeLayer.style.backgroundColor = 'gray';
    shadeLayer.style.filter = 'Alpha(opacity=30)';
    document.getElementById(document.forms[0].id).disabled = true;
}

function shadeOff(){
    shadeLayer.style.backgroundColor = '#fff';
    shadeLayer.style.filter = 'Alpha(opacity=100)';
    document.getElementById(document.forms[0].id).disabled = false;
}

function getUrlParam(ji){
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
        }
    }
}

