﻿// JScript File

function setGripperSWF(app)
{
    var dir = "images/animations/";
    var imgDir = "images/orientations/";  // directory for orientation images
    
    var imgExt = ""; // last part of image name for orientation images depending on jaw number and type
    var so;
    var fileName;
    var orientation;
    var clicked;

    // set it to something if it is null
    if (app == null) {
        app = '';
    }
    
    // Right now there is only one orientation so it is set manually. Later there will be other orientations.
    clicked = "Horizontal";
    
    // check what orientation is picked
    if (element(app + "rbHorizontalOrientation").checked) {
        clicked = "Horizontal";
    }
    else if (element(app + "rbVerticalOrientation").checked)
    {
        clicked = "Vertical";
    }
    else if (element(app + "rbVerticalOrientationSide").checked)
    {
        clicked = "VerticalSide";
    }

    
    
    
    switch(clicked)
    {
        case "Horizontal":
        {
            fileName = "Horizontal_";
            break;
        }
        case "Vertical":
        {
            fileName = "Vertical_";
            break;
        }
        case "VerticalSide":
        {
            fileName = "VerticalSide_";
            break;
        }
        case "HorizontalOffset":
        {
            fileName = "HorizontalOffset_";
            break;
        }
        case "VerticalOffset":
        {
            fileName = "VerticalOffset_";
            break;
        }
        case "HorizontalRotation":
        {
            fileName = "HorizontalRotation_";
            break;
        }
        case "VerticalRotation":
        {
            fileName = "VerticalRotation_";
            break;
        }
        case "HorizontalRotationOffset":
        {
            fileName = "HorizontalRotationOffset_";
            break;
        }
        default:
        {
            fileName = "Horizontal_";
            break;
        }
    }
    
    if (element("rb2jaw").checked)
    {
        if(element("rbAngular").checked)
        {
            orientation = "Angular_2.swf";
            imgExt = "Angular_2.gif";
        }
        else
        {
            orientation = "Parallel_2.swf";
            imgExt = "Parallel_2.gif";
        }
    }
    else
    {
        orientation = "3.swf";
        imgExt = "3.gif";
    }
    var prefix = "";
    var App2prefix = "";
    
    if (element(app + "rbInternalGrip").checked)
        prefix = "Internal";

    // set the orientation image source
//    if (clicked == "Horizontal") {
//        element(app + "imgHorizontal").src = imgDir + prefix + fileName + imgExt;
//    }
//    else if (clicked == "Vertical") {
//        element(app + "imgVertical").src = imgDir + prefix + fileName + imgExt;
//    }
//    else if (clicked == "VerticalSide") {
//        element(app + "imgVerticalSide").src = imgDir + prefix + fileName + imgExt;
//    }


    // rbFrictionGrip
    if (element(app + "rbFrictionGrip").checked) {

        // set all images
        element(app + "imgHorizontal").src = imgDir + prefix + "Horizontal_fric" + imgExt;

        element(app + "imgVertical").src = imgDir + prefix + "Vertical_fric" + imgExt;

        element(app + "imgVerticalSide").src = imgDir + prefix + "VerticalSide_fric" + imgExt;

        // only run for standard mode
        if (app != "App2") {
            //so = new SWFObject(dir + fileName + orientation, "flashID", "250", "250", "7", "#336699");
            so = new SWFObject(dir + prefix + fileName + "fric_" + orientation, "flashID", "250", "250", "7", "#336699");
        }
        
    }
    else {

        // set all images
        element(app + "imgHorizontal").src = imgDir + prefix + "Horizontal_" + imgExt;

        element(app + "imgVertical").src = imgDir + prefix + "Vertical_" + imgExt;

        element(app + "imgVerticalSide").src = imgDir + prefix + "VerticalSide_" + imgExt;

        // Only run for standard mode
        if (app != "App2") {
            //so = new SWFObject(dir + fileName + orientation, "flashID", "250", "250", "7", "#336699");
            so = new SWFObject(dir + prefix + fileName + orientation, "flashID", "250", "250", "7", "#336699");
        }

    }

       
    // Only run for standard mode
    if (app != "App2") {
    
        so.name = "flashID";
        so.addVariable("name", "flashID");
        so.write("flashcontent");
        flashID = element("flashID");


        if (flashID) {
            flashID.name = "flashID";
        }
        else {
            element("flashcontent").innerHTML = so.altTxt;
        }
    }
    
	return;
    
}
