/*--------------------------
  Move Viewpoint Model - Highlight navigation icons
---------------------------*/



function vmpColourAnim ( hexcode, material_name, secs ) {

	if (!vmp) return ;
    if (material_name == "") return ;
    if (!secs) secs="0.1"

    var rgb = getRGB ( hexcode ) ;
    /*
    if (vmp) {
        vmp.SetProperty('MTSMaterial.'+material_name, 'difc', rgb );
        vmp.Render();
    }
    */
    var mtx =
        '<MTSTimeElem Type=\\"Keyframe\\"  On=\\"1\\" >' +
        '<Target Name=\\"MTSMaterial.' + material_name + '\\" Property=\\"difc\\"  Timeline=\\"colourchange_T1\\" />' +
        '<Time> 0  ' + secs + ' </Time>' +
        '<Timeline Name=\\"colourchange_T1\\"  Type=\\"3D\\" >' +
        '*  [ ' + rgb + ' ]' +
        '</Timeline>' +
        '</MTSTimeElem>'
    if (vmp) vmp.Execute(mtx);
    return false;
}


//----------
// convert hexcode to a [r g b] string for viewpoint
//----------
function getRGB ( hexcode ) {
    // check for leading '#'
    if (hexcode.indexOf('#')==0)
        hexcode = hexcode.substr(1,6)

    if ( hexcode == "" ) {
        // default colour = Nondescript Grey
        r = g = b = 0.8
    }
    else {

        // convert hex to r g b for mtx
        r = parseInt( '0x' + hexcode.substr(0,2) ) * 0.0039 ;
        r = Math.round(r*1000) / 1000 ;

        g = parseInt( '0x' + hexcode.substr(2,2) ) * 0.0039 ;
        g = Math.round(g*1000) / 1000 ;

        b = parseInt( '0x' + hexcode.substr(4,2) ) * 0.0039 ;
        b = Math.round(b*1000) / 1000 ;
    }
    var rgb = r + ' ' + g + ' ' + b
    return rgb ;
}

function rotateUp() {
    document.images['rotate_u'].src = 'images/move_u_on.gif' ;
    if (vmp) vmp.SetProperty("MTSTimeElem.rotate_up", "trgr", 1, "mts_int");
}
function rotateUpOff() {
    document.images['rotate_u'].src = 'images/move_u.gif' ;
    if (vmp) vmp.SetProperty("MTSTimeElem.rotate_up", "runs", 0, "mts_int");
}
function rotateLeft() {
    document.images['rotate_l'].src = "images/move_l_on.gif";
    if (vmp) vmp.SetProperty("MTSTimeElem.rotate_left", "trgr", 1, "mts_int");
}
function rotateLeftOff() {
    document.images['rotate_l'].src = "images/move_l.gif";
    if (vmp) vmp.SetProperty("MTSTimeElem.rotate_left", "runs", 0, "mts_int");
}
function rotateRight() {
    document.images['rotate_r'].src = "images/move_r_on.gif";
    if (vmp) vmp.SetProperty("MTSTimeElem.rotate_right", "trgr", 1, "mts_int");
}
function rotateRightOff() {
    document.images['rotate_r'].src = "images/move_r.gif";
    if (vmp) vmp.SetProperty("MTSTimeElem.rotate_right", "runs", 0, "mts_int");
}
function rotateDown() {
    document.images['rotate_d'].src = "images/move_d_on.gif";
    if (vmp) vmp.SetProperty("MTSTimeElem.rotate_down", "trgr", 1, "mts_int");
}
function rotateDownOff() {
    document.images['rotate_d'].src = "images/move_d.gif";
    if (vmp) vmp.SetProperty("MTSTimeElem.rotate_down", "runs", 0, "mts_int");
}

function moveUp() {
    document.images['move_u'].src = "images/move_u_on.gif";
    if (vmp) vmp.SetProperty("MTSTimeElem.trans_up", "trgr", 1, "mts_int");
}
function moveUpOff() {
    document.images['move_u'].src = "images/move_u.gif";
    if (vmp) vmp.SetProperty("MTSTimeElem.trans_up", "runs", 0, "mts_int");
}
function moveLeft() {
    document.images['move_l'].src = "images/move_l_on.gif";
    if (vmp) vmp.SetProperty("MTSTimeElem.trans_left", "trgr", 1, "mts_int");
}
function moveLeftOff() {
    document.images['move_l'].src = "images/move_l.gif";
    if (vmp) vmp.SetProperty("MTSTimeElem.trans_left", "runs", 0, "mts_int");
}
function moveRight() {
    document.images['move_r'].src = "images/move_r_on.gif";
    if (vmp) vmp.SetProperty("MTSTimeElem.trans_right", "trgr", 1, "mts_int");
}
function moveRightOff() {
    document.images['move_r'].src = "images/move_r.gif";
    if (vmp) vmp.SetProperty("MTSTimeElem.trans_right", "runs", 0, "mts_int");
}
function moveDown() {
    document.images['move_d'].src = "images/move_d_on.gif";
    if (vmp) vmp.SetProperty("MTSTimeElem.trans_down", "trgr", 1, "mts_int");
}
function moveDownOff() {
    document.images['move_d'].src = "images/move_d.gif";
    if (vmp) vmp.SetProperty("MTSTimeElem.trans_down", "runs", 0, "mts_int");
}

// could also build an anim.
var tZoom ; // timer zoom ID
function zoomIn() {
    // don't put image swap in timer
    document.images['zoom_in'].src = "images/zoom_in_on.gif";
    timerZoomIn();
    //vmp.SetProperty("MTSTimeElem.zoom_in", "trgr", 1, "mts_int");
}
function timerZoomIn () {
    var cdst = parseFloat(vmp.GetProperty('MTSScene', 'cdst', 'mts_pnt1d'));
    if (cdst > 0.2) cdst -= 0.01 ;
    vmp.SetProperty('MTSScene', 'cdst', cdst);
    tZoom = setTimeout('timerZoomIn()',20);
}
function zoomInOff() {
    document.images['zoom_in'].src = "images/zoom_in.gif";
    clearTimeout(tZoom);
    // vmp.SetProperty("MTSTimeElem.zoom_in", "runs", 0, "mts_int");
}

function zoomOut() {
    document.images['zoom_out'].src = "images/zoom_out_on.gif";
    timerZoomOut();
    // vmp.SetProperty("MTSTimeElem.zoom_out", "trgr", 1, "mts_int");
}
function timerZoomOut () {
    var cdst = parseFloat(vmp.GetProperty('MTSScene', 'cdst', 'mts_pnt1d'));
    if (cdst < 4.5) cdst += 0.01  ;
    vmp.SetProperty('MTSScene', 'cdst', cdst);
    tZoom = setTimeout('timerZoomOut()',20);
}
function zoomOutOff() {
    document.images['zoom_out'].src = "images/zoom_out.gif";
    clearTimeout(tZoom);
    // vmp.SetProperty("MTSTimeElem.zoom_out", "runs", 0, "mts_int");
}
