
var isIE = document.all;

function maskVertical() {
    $("verticalAspectRatioText").fade();
    new Effect.SlideDown('rightVertical', {duration: 3.0});
    new Effect.SlideDown('leftVertical', {duration: 3.0, afterFinish: function() { $("verticalAspectRatioText").innerHTML = "16:9"; new Effect.Appear("verticalAspectRatioText"); } });
}
function unmaskVertical() {
    $("verticalAspectRatioText").fade();
    new Effect.SlideUp('rightVertical', {duration: 3.0});
    new Effect.SlideUp('leftVertical', {duration: 3.0, afterFinish: function() { $("verticalAspectRatioText").innerHTML = "2.35:1"; new Effect.Appear("verticalAspectRatioText"); } });
}

function maskHorizontal() {
    $("horizontalAspectRatioText").fade();
    new Effect.SlideDown('topHorizontal', {duration: 3.0});
    new Effect.SlideDown('bottomHorizontal', {duration: 3.0, afterFinish: function() { $("horizontalAspectRatioText").innerHTML = "2.35:1"; new Effect.Appear("horizontalAspectRatioText"); } });
}
function unmaskHorizontal() {
    $("horizontalAspectRatioText").fade();
    new Effect.SlideUp('topHorizontal', {duration: 3.0});
    new Effect.SlideUp('bottomHorizontal', {duration: 3.0, afterFinish: function() { $("horizontalAspectRatioText").innerHTML = "16:9"; new Effect.Appear("horizontalAspectRatioText"); } });
}


function maskCIHto16by9() {
    $("CIHAspectRatioText").fade();
    new Effect.BlindRight('rightCIH', {duration: 3.0, scaleFrom: 0, scaleTo: 50, restoreAfterFinish: false});
    new Effect.BlindRight('leftCIH', {duration: 3.0, scaleFrom: 0, scaleTo: 50, restoreAfterFinish: false, 
        afterFinish: function() { $("CIHAspectRatioText").innerHTML = "16:9"; new Effect.Appear("CIHAspectRatioText"); window.setTimeout(maskCIHto4by3,2000); } });
}
function maskCIHto4by3() {
    $("CIHAspectRatioText").fade();
    new Effect.BlindRight('rightCIH', {duration: 3.0, scaleFrom: 100, scaleTo: 200, restoreAfterFinish: false});
    new Effect.BlindRight('leftCIH', {duration: 3.0, scaleFrom: 100, scaleTo: 200, restoreAfterFinish: false,
        afterFinish: function() { $("CIHAspectRatioText").innerHTML = "4:3"; new Effect.Appear("CIHAspectRatioText"); window.setTimeout(unmaskCIH,2000); } });
}
function unmaskCIH() {
    $("CIHAspectRatioText").fade();
    new Effect.BlindLeft('rightCIH', {duration: 3.0});
    new Effect.BlindLeft('leftCIH', {duration: 3.0, 
        afterFinish: function() { $("CIHAspectRatioText").innerHTML = "2.35:1"; new Effect.Appear("CIHAspectRatioText"); 
        window.setTimeout(maskCIHto16by9,2000); $('rightCIH').width = '51px'; $('leftCIH').width = '51px'; } })
}


// this will work by figuring out the diagonal units, then calculating from there...so, for 16:9 aspect ratio
// we use this: Plugging in diagonal^2 = 9*9 + 16*16 = 337
// Diagonal = sqrt(337) = 18.3576 units.
// H/D = 9/18.3576 = 0.4903
// W/D = 16/18.3576 = 0.8716
// Those are constants for any size 16:9 display.
// Multiply by the 200" diagonal for 174.3" wide by 98.06" high
function updateInnerCalculationDisplay(aspectRatioWidth, aspectRatioHeight, diagonalMeasurement, displayPrefix) {
    var diagonalUnits = Math.sqrt(Math.pow(aspectRatioHeight, 2) + Math.pow(aspectRatioWidth, 2));
    var heightUnits = aspectRatioHeight/diagonalUnits;
    var widthUnits = aspectRatioWidth/diagonalUnits;
    
    //TODO: convert to inches first, make calculations, then check for metric
    
    $(displayPrefix + "InnerHeight").innerHTML = getMeasurementDisplay(diagonalMeasurement * heightUnits, displayPrefix);
    $(displayPrefix + "InnerWidth").innerHTML = getMeasurementDisplay(diagonalMeasurement * widthUnits, displayPrefix);
    $(displayPrefix + "DiagonalMeasurement").innerHTML = getMeasurementDisplay(diagonalMeasurement, displayPrefix);
}

function updateCalculationDisplay(aspectRatioWidth, aspectRatioHeight, displayPrefix) {
    if (aspectRatioWidth == null) { // use selected native aspect ratio
        var selectedAspectRatio = getNativeAspectRatio(displayPrefix);
        aspectRatioWidth = selectedAspectRatio.split(':')[0];
        aspectRatioHeight = selectedAspectRatio.split(':')[1];
    }
    var diagonalMeasurement = getDiagonalInInches(displayPrefix);
    var diagonalUnits = Math.sqrt(Math.pow(aspectRatioHeight, 2) + Math.pow(aspectRatioWidth, 2));
    var heightUnits = aspectRatioHeight/diagonalUnits;
    var widthUnits = aspectRatioWidth/diagonalUnits;
    
    //TODO: convert to inches first, make calculations, then check for metric
    
    var innerHeight = diagonalMeasurement * heightUnits;
    $(displayPrefix + "InnerHeight").innerHTML = getMeasurementDisplay(innerHeight, displayPrefix);
    var innerWidth = diagonalMeasurement * widthUnits;
    $(displayPrefix + "InnerWidth").innerHTML = getMeasurementDisplay(innerWidth, displayPrefix);
    $(displayPrefix + "DiagonalMeasurement").innerHTML = getMeasurementDisplay(diagonalMeasurement, displayPrefix);
    $(displayPrefix + "Diagonal").value = getMeasurementDisplay(diagonalMeasurement, displayPrefix);
    
    // horizontal measurements
    $(displayPrefix + "FrameWidth").innerHTML = getMeasurementDisplay(innerWidth + 12.5, displayPrefix);
    $(displayPrefix + "TopWallspace").innerHTML = getMeasurementDisplay(innerWidth + 16.5, displayPrefix);
    // vertical measurements
    $(displayPrefix + "FrameHeight").innerHTML = getMeasurementDisplay(innerHeight + 12.5, displayPrefix);
    $(displayPrefix + "Wallspace").innerHTML = getMeasurementDisplay(innerHeight + 13.3, displayPrefix);
}

// this is for the sliders measurement <ul>
function updateDiagonalMeasurementRange(displayPrefix) {
    var listItems = $(displayPrefix + "DiagonalRange").childElements();
    for(var i = 0; i < listItems.length; i++) {
        if ($(displayPrefix + 'MeasurementTypeInches').checked && listItems[i].innerHTML.indexOf("cm") > -1) {
            listItems[i].innerHTML = parseInt(parseInt(listItems[i].innerHTML.replace("cm","")) / 2.54) + "\"";
        } else if (!$(displayPrefix + 'MeasurementTypeInches').checked && listItems[i].innerHTML.indexOf("\"") > -1){
            listItems[i].innerHTML = parseInt(parseInt(listItems[i].innerHTML.replace("\"","")) * 2.54) + "cm";
        }
    }
}

function getMeasurementDisplay(unitsInInches, displayPrefix) {
    if ($(displayPrefix + 'MeasurementTypeInches').checked) {
        return Math.round(unitsInInches*10)/10 + "\"";
    } else {
        return Math.round(unitsInInches * 2.54*10)/10 + "cm";
    }
}

function getNativeAspectRatio(displayPrefix) {
    return $(displayPrefix + "NativeAspectRatioButton").value;
}

function setNativeAspectRatio(aspectRatio, displayPrefix) {
    setNativeAspectRatioText(aspectRatio, displayPrefix);
    updateCalculationDisplay(aspectRatio.split(':')[0], aspectRatio.split(':')[1], displayPrefix);
}
function setNativeAspectRatioText(aspectRatio, displayPrefix) {
    $(displayPrefix + "NativeAspectRatioButton").value = aspectRatio;
    $(displayPrefix + "AspectRatioText").innerHTML = aspectRatio;
}

function getDiagonal(displayPrefix) {
    return parseFloat($F(displayPrefix + "Diagonal").replace("\"", "").replace("cm", ""));
}
function getDiagonalInInches(displayPrefix) {
    var diagonalMeasurement = getDiagonal(displayPrefix);
    if ($(displayPrefix + 'CurrentMeasurementType').value != 'inches') {
        diagonalMeasurement = diagonalMeasurement /  2.54; // it's in cm
    }
    return Math.round(diagonalMeasurement*10)/10;
}

function selectDiagonalText(displayPrefix) {
    $(displayPrefix + "Diagonal").value = $(displayPrefix + "Diagonal").value.replace("\"", "").replace("cm","");
    $(displayPrefix + "Diagonal").focus();
    $(displayPrefix + "Diagonal").select();
}

function changeDiagonal(displayPrefix) {
    var diagonalMeasurement = getDiagonalInInches(displayPrefix);
    updateCalculationDisplay(null,null,displayPrefix);
    switch(displayPrefix) {
        case "horizontal":
            horizontalSlider.setValue(diagonalMeasurement);
            break;
        case "vertical":
            verticalSlider.setValue(diagonalMeasurement);
            break;
        case "cih":
            cihSlider.setValue(diagonalMeasurement);
            break;
        default:
            horizontalSlider.setValue(diagonalMeasurement);
            break;
    } 
}

function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 46 || charCode > 57))
    return false;

    return true;
}
function detectReturnKey(evt, displayPrefix){
    evt = ( evt ) ? evt : window.event;
    var charCode = ( evt.which ) ? evt.which : evt.keyCode;
    if (charCode == 13) {
        changeDiagonal(displayPrefix);
    }
}

// used when the user holds down the +/- buttons
var sliderInterval = null;
var mouseDownSlider = null;
var mouseDownDisplayPrefix = null;
function plusKeyDown(displayPrefix, slider) {
    mouseDownDisplayPrefix = displayPrefix;
    mouseDownSlider = slider;
    sliderInterval = setInterval(plusDiagonalTimed, 150);
}
function plusKeyUp() {
    clearInterval ( sliderInterval );
}
function minusKeyDown(displayPrefix, slider) {
    mouseDownDisplayPrefix = displayPrefix;
    mouseDownSlider = slider;
    sliderInterval = setInterval(minusDiagonalTimed, 150);
}
function minusKeyUp() {
    clearInterval ( sliderInterval );
}
function plusDiagonalTimed() {
    mouseDownSlider.setValue(getDiagonalInInches(mouseDownDisplayPrefix) + 0.1);
}
function minusDiagonalTimed() {
    mouseDownSlider.setValue(getDiagonalInInches(mouseDownDisplayPrefix) - 0.1);
}

function plusDiagonal(displayPrefix, slider) {
    slider.setValue(getDiagonalInInches(displayPrefix) + 0.1);
}
function minusDiagonal(displayPrefix, slider) {
    slider.setValue(getDiagonalInInches(displayPrefix) - 0.1);
}


function getInches(inputId, displayPrefix) {
    if ($(displayPrefix + 'MeasurementTypeInches').checked) {
        return Math.round(parseFloat($(inputId).innerHTML.replace("\"", ""))*10)/10;
    } else {
        return Math.round((parseFloat($(inputId).innerHTML.replace("\"", "")) / 2.54)*10)/10;
    }
}

function derivehorizontalMaskedDiagonal(mask) {
    var height = 0;
    var width = getInches("horizontalInnerWidth", 'horizontal');
    if (mask) { // 2.35: 1 (or selected native aspect ratio)
        height = (width / 2.35); // subtract for masking
    } else { // 16:9 
        height = (width / 16) * 9; // add for unmasking
    }
    return Math.round(Math.sqrt(Math.pow(height, 2) + Math.pow(width, 2))*10)/10;
}

function showHorizontalMask() {
    // hide inner stuff
    $("innerHorizontalHeight").fade();
    $("innerHorizontalWidth").fade();
    $("horizontalDiagonalLine").fade();
    $("horizontalAspectRatioText").fade();
    
    
    new Effect.SlideDown('topHorizontal', {duration: 3.0});
    new Effect.SlideDown('bottomHorizontal', {duration: 3.0, afterFinish: function() { 
        // move and calculate
        $("innerHorizontalHeight").style.top = 32; // move vertical line
        $("horizontalHeightLine").style.height = (isIE ? 253 : 249) - 64 + "px"; // change vertical line height
        $("horizontalAspectRatioText").innerHTML = "2.35:1";  // change aspect ratio
        $("horizontalDiagonalLine").style.top = isIE ? 22 : 42;
        $("horizontalDiagonal1").style.borderWidth = "0px 0px 185px 450px";
        $("horizontalDiagonal2").style.borderWidth = "0px 0px 185px 450px";
        
        var updatedDiagonal = derivehorizontalMaskedDiagonal(true);
        updateInnerCalculationDisplay(2.35, 1, updatedDiagonal, "horizontal");
        
        $("horizontalDiagonalMeasurement").style.left = "140";
        
        // show inner stuff
        new Effect.Appear("horizontalAspectRatioText"); 
        $("innerHorizontalHeight").appear();
        $("innerHorizontalWidth").appear();
        $("horizontalDiagonalLine").appear();
        toggleHorizontalControls(false);
     } });
}
function toggleHorizontalControls(showNative) {
    $("horizontalNativeAspectRatioButton").disabled = showNative
    $("horizontalMaskButton").disabled = !showNative;
    $("horizontalMin").disabled = !showNative;
    $("horizontalAdd").disabled = !showNative;
    if (!showNative) {
        horizontalSlider.setDisabled();
    } else {
        horizontalSlider.setEnabled();
    }
    $("horizontalDiagonal").disabled = !showNative;
    var aspectRatios = document.getElementsByName("horizontalNativeAspectRatioOption");
    for (var i = 0; i < aspectRatios.length; i++) {
        aspectRatios[i].disabled = !showNative;
    }
}
function showHorizontalUnmask() {
    $("innerHorizontalHeight").fade();
    $("innerHorizontalWidth").fade();
    $("horizontalDiagonalLine").fade();
    $("horizontalAspectRatioText").fade();
    
    
    new Effect.SlideUp('topHorizontal', {duration: 3.0});
    new Effect.SlideUp('bottomHorizontal', {duration: 3.0, afterFinish: function() { 
        $("innerHorizontalHeight").style.top = 0; // move vertical line
        $("horizontalHeightLine").style.height = (isIE ? 248 : 244) + "px"; // change vertical line height
        $("horizontalAspectRatioText").innerHTML = "16:9"; 
        $("horizontalDiagonalLine").style.top = isIE ? -10 : 10;
        $("horizontalDiagonal1").style.borderWidth = "0px 0px 250px 450px";
        $("horizontalDiagonal2").style.borderWidth = "0px 0px 250px 450px";
        
        var updatedDiagonal = derivehorizontalMaskedDiagonal(false);
        updateInnerCalculationDisplay(16, 9, updatedDiagonal, "horizontal");
        
        $("horizontalDiagonalMeasurement").style.left = "200";
        
        new Effect.Appear("horizontalAspectRatioText"); 
        $("innerHorizontalHeight").appear();
        $("innerHorizontalWidth").appear();
        $("horizontalDiagonalLine").appear();
        toggleHorizontalControls(true);
    } });
}

function deriveverticalMaskedDiagonal(mask) {
    var height = getInches("verticalInnerHeight", 'vertical');
    var width = 0;
    if (mask) { // 16:9
        width = (height / 9) * 16;
    } else { // 2.35:1 (or selected native aspect ratio)
        width = (height * parseFloat(getNativeAspectRatio('vertical').split(':')[0]));
    }
    return Math.round(Math.sqrt(Math.pow(height, 2) + Math.pow(width, 2))*10)/10;
}

function showVerticalMask() {
    // hide inner stuff
    $("innerVerticalHeight").fade();
    $("innerVerticalWidth").fade();
    $("verticalDiagonalLine").fade();
    $("verticalAspectRatioText").fade();

    new Effect.SlideDown('rightVertical', {duration: 3.0});
    new Effect.SlideDown('leftVertical', {duration: 3.0, afterFinish: function() {
        // move and calculate
        $("innerVerticalWidth").style.left = 57; // move width line
        $("verticalWidthLine").style.width = 450 - (57*2) + "px"; // change width line width
        $("verticalAspectRatioText").innerHTML = "16:9";  // change aspect ratio
        $("verticalDiagonalLine").style.left = 67;
        $("verticalDiagonal1").style.borderWidth = "0px 0px 180px 336px";
        $("verticalDiagonal2").style.borderWidth = "0px 0px 180px 336px";
        
        var updatedDiagonal = deriveverticalMaskedDiagonal(true);
        updateInnerCalculationDisplay(16, 9, updatedDiagonal, "vertical");
        
        $("verticalDiagonalMeasurement").style.left = "120";
        
        // show inner stuff
        new Effect.Appear("verticalAspectRatioText"); 
        $("innerVerticalHeight").appear();
        $("innerVerticalWidth").appear();
        $("verticalDiagonalLine").appear();
        toggleVerticalControls(false);
     } });
}
function toggleVerticalControls(showNative) {
    $("verticalNativeAspectRatioButton").disabled = showNative
    $("verticalMaskButton").disabled = !showNative;
    $("verticalMin").disabled = !showNative;
    $("verticalAdd").disabled = !showNative;
    if (!showNative) {
        verticalSlider.setDisabled();
    } else {
        verticalSlider.setEnabled();
    }
    $("verticalDiagonal").disabled = !showNative;
    var aspectRatios = document.getElementsByName("verticalNativeAspectRatioOption");
    for (var i = 0; i < aspectRatios.length; i++) {
        aspectRatios[i].disabled = !showNative;
    }
}
function showVerticalUnmask() {
    $("innerVerticalHeight").fade();
    $("innerVerticalWidth").fade();
    $("verticalDiagonalLine").fade();
    $("verticalAspectRatioText").fade();

    new Effect.SlideUp('rightVertical', {duration: 3.0});
    new Effect.SlideUp('leftVertical', {duration: 3.0, afterFinish: function() {
        var nativeAspectRatio = getNativeAspectRatio('vertical');
        $("innerVerticalWidth").style.left = 0; // move width line
        $("verticalWidthLine").style.width = "450px"; // change horizontal line width
        $("verticalAspectRatioText").innerHTML = nativeAspectRatio; 
        $("verticalDiagonalLine").style.left = 10;
        $("verticalDiagonal1").style.borderWidth = "0px 0px 180px 450px";
        $("verticalDiagonal2").style.borderWidth = "0px 0px 180px 450px";
        
        var updatedDiagonal = deriveverticalMaskedDiagonal(false);
        
        updateInnerCalculationDisplay(nativeAspectRatio.split(':')[0], nativeAspectRatio.split(':')[1], updatedDiagonal, "vertical");
        
        $("verticalDiagonalMeasurement").style.left = "150";
        
        new Effect.Appear("verticalAspectRatioText"); 
        $("innerVerticalHeight").appear();
        $("innerVerticalWidth").appear();
        $("verticalDiagonalLine").appear();
        toggleVerticalControls(true);
    } });
}

function derivecihMaskedDiagonal(aspectRatio) {
    var height = getInches("cihInnerHeight", 'cih');
    if (aspectRatio == "16:9") {
        width = (height / 9) * 16; 
    } else if (aspectRatio == "4:3") {
        width = (height / 3) * 4; 
    } else if (aspectRatio == "1.85:1") {
        width = height * 1.85;
    } else { // 2.35:1 (or selected native aspect ratio)
        width = height * parseFloat(getNativeAspectRatio('cih').split(':')[0]);
    }
    return Math.round(Math.sqrt(Math.pow(height, 2) + Math.pow(width, 2))*10)/10;
}

function showCihMaskto185by1() {
    maskCIH("1.85:1");
}
function showCihMaskto16by9() {
    maskCIH("16:9");
}
function showCihMaskto4by3() {
    maskCIH("4:3");
}

function maskCIH(aspectRatio) {
    // hide inner stuff
    $("innerCihHeight").fade();
    $("innerCihWidth").fade();
    $("cihDiagonalLine").fade();
    $("cihAspectRatioText").fade();
    
    // height = 200 px, original width = 470...this will give the mask width for one side
    var desiredMaskWidth = (470 - ((200 / aspectRatio.split(':')[1]) * aspectRatio.split(':')[0])) / 2;
    
    var currentScale = $("rightCIH").style.width == "" ? 0 : $("rightCIH").style.width.replace("px","");
    var maxCIHMaskWidth = 102;
    
    if (currentScale > desiredMaskWidth) {
        var scaleFrom = 100;
        var scaleTo =  scaleFrom - (((currentScale - desiredMaskWidth) / currentScale)*100);
        var duration = (scaleFrom - scaleTo) / 20;
        if (duration < 1) { duration = 1; }
        
        new Effect.BlindLeft('rightCIH', {duration: duration, scaleFrom: scaleFrom , scaleTo: scaleTo, restoreAfterFinish: false, 
            afterFinishInternal: function(effect) { effect.element.undoClipping(); }
            });
        new Effect.BlindLeft('leftCIH', {duration: duration, scaleFrom: scaleFrom , scaleTo: scaleTo, restoreAfterFinish: false,  afterFinish: function() {
            cihAfterFinish(aspectRatio, desiredMaskWidth);
         }, afterFinishInternal: function(effect) { effect.element.undoClipping(); } 
         });
    } else {
        var scaleFrom = currentScale == 0 ? 0 : 100;
        var scaleTo =  currentScale == 0 ? desiredMaskWidth + scaleFrom - 1 : ((desiredMaskWidth - currentScale) / currentScale)*100 + scaleFrom - 1;
        var duration = (scaleTo - scaleFrom) / 20;
        if (duration < 1) { duration = 1; }
        
        new Effect.BlindRight('rightCIH', {duration: duration, scaleFrom: scaleFrom , scaleTo: scaleTo, restoreAfterFinish: false});
        new Effect.BlindRight('leftCIH', {duration: duration, scaleFrom: scaleFrom , scaleTo: scaleTo, restoreAfterFinish: false,  afterFinish: function() {
            cihAfterFinish(aspectRatio, desiredMaskWidth);
         } });
    }
}

function cihAfterFinish(aspectRatio, desiredMaskWidth) {
    // move and calculate
    $("innerCihWidth").style.left = desiredMaskWidth+1; // move width line
    $("cihWidthLine").style.width = 449 - (desiredMaskWidth*2) + "px"; // change width line width
    $("cihAspectRatioText").innerHTML = aspectRatio;  // change aspect ratio
    $("cihDiagonalLine").style.left = desiredMaskWidth+5;
    $("cihDiagonal1").style.borderWidth = "0px 0px 180px " + (450 - (desiredMaskWidth*2)) + "px";
    $("cihDiagonal2").style.borderWidth = "0px 0px 180px " + (450 - (desiredMaskWidth*2)) + "px";
    
    var updatedDiagonal = derivecihMaskedDiagonal(aspectRatio);
    updateInnerCalculationDisplay(aspectRatio.split(':')[0], aspectRatio.split(':')[1], updatedDiagonal, "cih");
    
    $("cihDiagonalMeasurement").style.left = "100";
    
    // show inner stuff
    new Effect.Appear("cihAspectRatioText"); 
    $("innerCihHeight").appear();
    $("innerCihWidth").appear();
    $("cihDiagonalLine").appear();
    toggleCihControls(false, aspectRatio);
}

function CihMaskto16by9AfterFinish() {
    // move and calculate
    $("innerCihWidth").style.left = 51; // move width line
    $("cihWidthLine").style.width = 450 - (51*2) + "px"; // change width line width
    $("cihAspectRatioText").innerHTML = "16:9";  // change aspect ratio
    $("cihDiagonalLine").style.left = 67;
    $("cihDiagonal1").style.borderWidth = "0px 0px 180px 336px";
    $("cihDiagonal2").style.borderWidth = "0px 0px 180px 336px";
    
    var updatedDiagonal = derivecihMaskedDiagonal("16:9");
    updateInnerCalculationDisplay(16, 9, updatedDiagonal, "cih");
    
    $("cihDiagonalMeasurement").style.left = "100";
    
    // show inner stuff
    new Effect.Appear("cihAspectRatioText"); 
    $("innerCihHeight").appear();
    $("innerCihWidth").appear();
    $("cihDiagonalLine").appear();
    toggleCihControls(false, "16:9");
}

function toggleCihControls(showNative, aspectRatio) {
    $("cihNativeAspectRatioButton").disabled = showNative
    if (aspectRatio == "16:9") {
        $("cihMaskButton").disabled = true;
        $("cihMaskButton2").disabled = false;
        $("cihMaskButton3").disabled = false;
    } else if (aspectRatio == "4:3") {
        $("cihMaskButton").disabled = false;
        $("cihMaskButton2").disabled = true;
        $("cihMaskButton3").disabled = false;
    } else if (aspectRatio == "1.85:1") {
        $("cihMaskButton").disabled = false;
        $("cihMaskButton2").disabled = false;
        $("cihMaskButton3").disabled = true;
    } else {
        $("cihMaskButton").disabled = false;
        $("cihMaskButton2").disabled = false;
        $("cihMaskButton3").disabled = false;
    }
    $("cihMin").disabled = !showNative;
    $("cihAdd").disabled = !showNative;
    if (!showNative) {
        cihSlider.setDisabled();
    } else {
        cihSlider.setEnabled();
    }
    $("cihDiagonal").disabled = !showNative;
    var aspectRatios = document.getElementsByName("cihNativeAspectRatioOption");
    for (var i = 0; i < aspectRatios.length; i++) {
        aspectRatios[i].disabled = !showNative;
    }
}
function showCihUnmask() {
    $("innerCihHeight").fade();
    $("innerCihWidth").fade();
    $("cihDiagonalLine").fade();
    $("cihAspectRatioText").fade();
    
    new Effect.BlindLeft('rightCIH', {duration: 3.0});
    new Effect.BlindLeft('leftCIH', {duration: 3.0, afterFinish: function() {
        var nativeAspectRatio = getNativeAspectRatio('cih');
        $("innerCihWidth").style.left = 0; // move width line
        $("cihWidthLine").style.width = "450px"; // change horizontal line width
        $("cihAspectRatioText").innerHTML = nativeAspectRatio; 
        $("cihDiagonalLine").style.left = 10;
        $("cihDiagonal1").style.borderWidth = "0px 0px 180px 450px";
        $("cihDiagonal2").style.borderWidth = "0px 0px 180px 450px";
        
        var updatedDiagonal = derivecihMaskedDiagonal("");
        updateInnerCalculationDisplay(nativeAspectRatio.split(':')[0], nativeAspectRatio.split(':')[1], updatedDiagonal, "cih");
        
        $("cihDiagonalMeasurement").style.left = "150";
        
        new Effect.Appear("cihAspectRatioText"); 
        $("innerCihHeight").appear();
        $("innerCihWidth").appear();
        $("cihDiagonalLine").appear();
        toggleCihControls(true);
        $("leftCIH").style.width = "";
        $("rightCIH").style.width = "";
    } });
}

function sendContactEmail() {
    // TODO: get prefix based on page
    var currentPageParts = window.location.pathname.split('/');
    var currentPage = currentPageParts[currentPageParts.length-1];
    var displayPrefix = "horizontal";
    switch (currentPage.toLowerCase()) {
        case "masqueradecihcalculator.aspx":
            displayPrefix = "cih";
            break;
        case "verticalmasqueradecalculator.aspx":
            displayPrefix = "vertical";
            break;
        default:
            displayPrefix = "horizontal";
            break;
    }
    
    var emailDiagonal = getDiagonalInInches(displayPrefix);
    var emailAspectRatio = $(displayPrefix + "NativeAspectRatioButton").value;
    var emailMeasurementType = $(displayPrefix + 'MeasurementTypeInches').checked ? "inches" : "cm";
    
    var message = "I am looking at: %0D%0D";
	
	message += "http://www.carada.com/" + currentPage + "?measurement=" + emailMeasurementType + "%26diagonal=" + emailDiagonal + "%26nativeAspectRatio=" + emailAspectRatio;
	message += "%0D%0D And I have the following questions: %0D%0D";
	
	var email = "info@carada.com";
	var subject = "Carada Masquerade questions..."; 
	
	var mailto_link = 'mailto:'+email+'?subject='+subject+'&body='+message; 
	win = window.open(mailto_link,'emailWindow');
    if (win && win.open &&!win.closed) win.close(); 
}