﻿//\/////

//\  coolTip Adaptive Width Plugin

//\  This file requires coolTip 1.00 or later.

//\  Modified June 9, 2005

//\

//\  You may not remove or change this notice.

//\  Copyright Robert E Boughner 2005. All rights reserved.

//\  

//\  This plugin is governed by the same restrictions set forth

//\  in the prologue to cCore.js.

//\/////

//\  THIS IS A VERY MODIFIED VERSION. DO NOT EDIT OR PUBLISH. GET THE ORIGINAL!

if (typeof cInfo == cUdf || !cInfo.meets(1.00)) alert('coolTip 1.00 or later is required for the Adaptive_Width Plugin.'); else {
    registerCommands('adaptive_width');

    setDefaultVariables('adaptive_width|');

    var cAWDefault = '300,720,4,9';

    function setAdaptiveWidthVariables(obj) { obj.adaptive_width = cd_adaptive_width; }

    function parseAdaptiveWidthExtras(pf, i, ar) {
        var k = i; if (k < ar.length) { if (ar[k] == ADAPTIVE_WIDTH) { k = getAWArgs(++k, ar, (pf + 'adaptive_width')); adjustAWSettings(pf + 'adaptive_width'); return k; } }

        return -1;
    }

    function getAWArgs(i, args, parameter) {
        var k = i, l, re, pV, str = ''; for (k = i; k < args.length; k++) { if (typeof args[k] == 'number' && args[k] > pmStart) break; str += args[k] + ','; }

        if (str) str = str.replace(/,$/, ''); k--; pV = (cNs4 && /cellpad/i.test(parameter)) ? str.split(',')[0] : str; eval(parameter + '="' + pV + '"'); return k;
    }

    function adjustAWSettings(pmStr) { var theVal; if (/'cd_'/.test(pmStr)) { theVal = eval(pmStr); if (theVal) cAWDefault = setAWarr(theVal).join(','); } else if (!eval(pmStr)) eval(pmStr + '="' + cAWDefault + '"'); }

    function checkAdaptiveWidth() {
        var po = cTip.pop; with (po) { if (adaptive_width) { if (wrap) clearWrapSettings(); width = dynamicSizer(text, cap, setAWarr(adaptive_width)); } }

        return true;
    }

    function setAWarr(vArrStr) { var tmpArr = new Array(), dfArr = cAWDefault.split(','), awArr = vArrStr.split(','); for (var i = 0; i < dfArr.length; i++) tmpArr[tmpArr.length++] = (i < awArr.length && awArr[i]) ? awArr[i] : dfArr[i]; return tmpArr; }

    function dynamicSizer(aText, aCap, awArr) { var textWide = Math.floor(parseInt(awArr[0]) + aText.length / awArr[2]); if (aCap) textWide = Math.max(textWide, Math.floor(aCap.length * awArr[3])); return Math.min(parseInt(awArr[1]), textWide); }

    function clearWrapSettings() { nbspCleanup(); cTip.pop.wrap = 0; }

    registerRunTimeFunction(setAdaptiveWidthVariables); registerCmdLineFunction(parseAdaptiveWidthExtras); registerPostParseFunction(checkAdaptiveWidth);
}

