

// OVERVIEW: CORE LOGIC

// Only one preview gallery is permitted per html page (at this stage).
// The only global-indentier this app reserves is the function name 'kpl_overview', 
// Global-variables are avoided - instead, non-transient data are stored as properties of the
// function-object 'kpl_overview' itself (typically referenced as the identifier 'me'). 
// This code uses simple closures (and aspires to avoid IE's memory leaks).
// [ singleton, nonconstructor ]

// desirable enhancement #1: upgrade preview auto-scaling for viewport width.
// desirable enhancement #2: use classes not IDs to allow multiple OverView structures in one page.
// useful    enhancement #3: allow multiple instances (redevelop as a prototype 'class').
// possible  enhancement #4: auto-positioning of preview to avoid/minimise view-port clipping.


function kpl_overview()
{

    function panels_show()
    {
        try
        {
            var me = kpl_overview; if(!me.enabled){return;}
            me.thumbnail = this;
            panels_hide();
            me.previewAbove = preview_positionAbove();
            if (me.captionEnabled)  { caption_show(); }
            if (me.previewEnabled)  { preview_preload(); }
        }
        catch(e){kpl_overview.enabled=false;}
    }

    function panels_hide()
    {
        try
        {
            var me = kpl_overview;
            me.previewSuperseded = true;
            me.caption.style.visibility = 'hidden';
            me.preview.style.visibility = 'hidden';
        }
        catch(e){kpl_overview.enabled=false;}
    }

    function preview_toggleHeightMaxOverride()
    {
        try
        {
            var me = kpl_overview; if(!me.enabled){return;}
            me.previewHeightMaxOverride = !me.previewHeightMaxOverride;
            if (me.msie)  { me.previewAbove = !me.previewAbove; }                                    // x-bwr
        }
        catch(e){kpl_overview.enabled=false;}
    }

    function preview_preload()
    {
        var me = kpl_overview;
        var pvw = me.preview;
        var pre = me.previewPreload;
        var thb_fldrName    = new RegExp('(\\/)' + me.THUMBS_FOLDER, 'i');                         // note '\\' 
        var pvw_fldrName    = '$1' + me.PREVIEWS_FOLDER;
        var previewImageURL = me.thumbnail.getAttribute('src').replace(thb_fldrName, pvw_fldrName);
        me.previewURL = previewImageURL;
        pre.onload = null;
        pre.setAttribute('src', null);
        me.previewPreload = new Image();
        pre = me.previewPreload;
        pre.onload = preview_onpreload;
        pre.setAttribute('src', previewImageURL);
    }

    function preview_onpreload()
    {
        try
        {
            var me     = kpl_overview; if(!me.enabled){return;}
            var pvw    = me.preview;
            var pvwImg = this;
            if (!preview_supersededURL(pvwImg))  
            { 
                preview_setDimensions(pvwImg);
                me.previewSuperseded = false;
                pvw.setAttribute('src', me.previewURL);
            }
            else
            { 
                me.previewSuperseded = true;
            }
        }
        catch(e){kpl_overview.enabled=false;}
    }

    function preview_onload()
    {
        function preview_hide()  { kpl_overview.preview.style.visibility = 'hidden'; }
        
        try
        {
            var me  = kpl_overview; if(!me.enabled){return;}
            var pvw = this;
            if (me.previewSuperseded || preview_supersededURL(pvw))  { return; }
            preview_setPosition(pvw);
            pvw.style.visibility = 'visible'; 
            me.previewSuperseded = true;                                   
            if (me.timerRefPreview)  { window.clearTimeout(me.timerRefPreview); }
            me.timerRefPreview = window.setTimeout(preview_hide, (me.previewShowTime * 1000));
        }
        catch(e){kpl_overview.enabled=false;}
    }


    function preview_setDimensions(pvwImg)
    {
        var me     = kpl_overview;
        var pvw    = me.preview;
        var pvwImgWidth   = pvwImg.width; 
        var pvwImgHeight  = pvwImg.height;
        var pvwImgHghtMax = me.previewHeightMax;
        var autoAdj       = me.previewHeightMaxAutoAdj;
        var hghtMax, scaling;
        
        if (!me.previewHeightMaxOverride)
        {
            if (pvwImgHghtMax != 'off')
            {
                hghtMax = (pvwImgHghtMax == 'auto') ? preview_heightMaxAuto() : pvwImgHghtMax;
                if (hghtMax < pvwImgHeight)  
                {   
                    scaling = hghtMax / pvwImgHeight;
                    pvwImgWidth  = Math.round(pvwImgWidth  * scaling); 
                    pvwImgHeight = Math.round(pvwImgHeight * scaling);  
                }
            }
        }
        pvw.style.width  = pvwImgWidth   + 'px'; 
        pvw.style.height = pvwImgHeight  + 'px'; 
    }
 
    function preview_setPosition(pvw)
    {
        var thb = me.thumbnail;
        var pvwClear  = me.previewClearance;
        var thbWidth  = thb.offsetWidth;
        var thbHeight = thb.offsetHeight;
        var pvwWidth  = pvw.offsetWidth;
        var pvwHeight = pvw.offsetHeight;
        var pvwLeft = dom_leftToBody(thb) - Math.round((pvwWidth - thbWidth) / 2);
        var pvwTop  = dom_topToBody(thb)  - pvwHeight;
        if (me.previewAbove)
        { 
            pvwTop -= pvwClear; 
        }
        else
        { 
            pvwTop += (pvwClear + (pvwHeight + thbHeight)); 
        }
        pvw.style.top  = pvwTop  + 'px';
        pvw.style.left = pvwLeft + 'px';
    }

    function preview_heightMaxAuto()
    {
        var me  = kpl_overview;
        var pvw = me.preview;
        var allotted, hghtMax;
        var pvwHeightMin = me.previewHeightMaxLowest;
        allotted  = me.previewClearance;
        allotted += parseInt(dom_element_getStyle(pvw, 'paddingTop',        'padding-top'        ));
        allotted += parseInt(dom_element_getStyle(pvw, 'paddingBottom',     'padding-bottom'     ));
        allotted += parseInt(dom_element_getStyle(pvw, 'borderTopWidth',    'border-top-width'   ));
        allotted += parseInt(dom_element_getStyle(pvw, 'borderBottomWidth', 'border-bottom-width'));
        allotted += me.previewHeightMaxPadding;
        hghtMax = ((viewport_height() / 2) - allotted) * me.previewHeightMaxAutoAdj;
        return ( (hghtMax >= pvwHeightMin) ? hghtMax : pvwHeightMin );
    }

    function preview_positionAbove()
    {
        var me = kpl_overview;
        var thb = me.thumbnail;
        var thbHeight = thb.offsetHeight;
        var tmbToViewportTop = (dom_topToBody(thb) - viewport_toBodyTop()) + (thbHeight/2);
        var tmbToViewportBot = viewport_height() - tmbToViewportTop;
        return (tmbToViewportTop > tmbToViewportBot); 
    }
    
    function preview_supersededURL(img)
    {
        return (img.getAttribute('src') != kpl_overview.previewURL);
    }

    function preview_makeElement(id)
    {
        var img, iso, me;
        me  = kpl_overview;
        img = window.document.createElement('img');
        iso = img.style;
        img.id         = id;
        iso.position   = 'absolute';
        iso.left       = '1px';
        iso.top        = '1px';
        iso.zindex     = '1000';
        iso.width      = '';                                                                    
        iso.height     = '';                                                                    
        iso.visibility = 'hidden';
        me.content.appendChild(img);
        return img;
    }


    function caption_show()
    {
        function caption_hide() { kpl_overview.caption.style.visibility = 'hidden'; }
        
        var me        = kpl_overview;
        var cpn       = me.caption;
        var cpnClear  = me.captionClearance; 
        var thb       = me.thumbnail;
        var thbWidth  = thb.offsetWidth;
        var thbHeight = thb.offsetHeight; 
        var cpnText   = thb.alt; 
        var readRateCPS  = me.captionReadSpeedCPS; 
        var minimum_secs = me.captionShowMinimum; 
        var display_secs;
       
        cpn.firstChild.firstChild.data = cpnText; 
        
        var cpnWidth  = cpn.offsetWidth;
        var cpnHeight = cpn.offsetHeight;
        var cpnLeft   = dom_leftToBody(thb) - Math.round((cpnWidth - thbWidth) / 2);
        var cpnTop    = dom_topToBody(thb);
        
        if (me.previewAbove)
        {  cpnTop += (cpnClear + thbHeight); }
        else
        {  cpnTop -= (cpnClear + cpnHeight); }
        cpn.style.top  = cpnTop  + 'px';
        cpn.style.left = cpnLeft + 'px';
        cpn.style.visibility = 'visible';
        
        display_secs = cpnText.length / readRateCPS;
        if (display_secs < minimum_secs)  { display_secs = minimum_secs; }
        if (me.timerRefCaption)  { window.clearTimeout(me.timerRefCaption); }
        me.timerRefCaption = window.setTimeout(caption_hide, Math.round(display_secs * 1000));
    }

    function caption_makeElement(id)
    {
        var div, spn, dso, me;
        me  = kpl_overview;
        div = window.document.createElement('div');
        dso = div.style;
        div.id         = id;
        dso.position   = 'absolute';
        dso.left       = '1px';
        dso.top        = '0px';
        dso.zindex     = '1001';
        dso.width      = me.captionWidth + 'px';                                                                   
        dso.height     = '';                                                                    // !important
        dso.visibility = 'hidden';
        spn = window.document.createElement('span');                                   // see css font-sizing
        spn.appendChild(window.document.createTextNode(''));
        div.appendChild(spn);
        me.content.appendChild(div);
        return div;
    }


    function viewer_show()
    {
        try
        {
            var me = kpl_overview; if(!me.enabled){return;}
            var link             = this;
            var thumb            = this.firstChild;
            var SEARCH_FAILED    = -1;
            var FILE_EXT_JPG     = /\.jpg$/i;
            var FILE_EXT_GIF     = /\.gif$/i;
            var waitTimeMS       = 100;
            var vwrURL           = me.VIEWER_PAGE_URL;
            var argNameImage     = 'url';
            var argNameCaption   = 'caption';
            var argNameShowMinm  = 'showminimum';
            var tmbCaption, urlQuery;
            
            var href   = link.href;
            var notJPG = (href.search(FILE_EXT_JPG) == SEARCH_FAILED);  
            var notGIF = (href.search(FILE_EXT_GIF) == SEARCH_FAILED);  
            if (notJPG && notGIF)  { return; }

            tmbCaption = window.encodeURIComponent(thumb.alt);
            urlQuery   = vwrURL + '?' + argNameImage     + '=' + href         + ',' +  
                                        argNameCaption   + '=' + tmbCaption   + ',' +
                                        argNameShowMinm  + '=' + me.captionShowMinimum;
            window.setTimeout('window.location.href="' + urlQuery + '"', waitTimeMS);
            return false;                                                              // cancel link-action
        }
        catch(e){kpl_overview.enabled=false;}
    }



    function dom_leftToBody(el) 
    {
        return ( (el.offsetParent) ? (el.offsetLeft + dom_leftToBody(el.offsetParent)) : el.offsetLeft ); 
    }

    function dom_topToBody(el) 
    {
        return ( (el.offsetParent) ? (el.offsetTop  + dom_topToBody(el.offsetParent))  : el.offsetTop  ); 
    }

    function dom_ofClass(elementRef, className)
    {
        var CLASS_NAME_SEPARATOR = ' ';
        var classes  = elementRef.className.split(CLASS_NAME_SEPARATOR);
        for(var i=0; i<classes.length; i++)
        { if (classes[i] == className) { return true; } }
        return false; 
    }

    function dom_element_getStyle(elem, IEStyleProp, CSSStyleProp) 
    {
        if (elem.currentStyle) 
        { return elem.currentStyle[IEStyleProp]; } 
        if (window.getComputedStyle) 
        { return window.getComputedStyle(elem, '').getPropertyValue(CSSStyleProp); }
        return '';
    }


    function viewport_toBodyTop()
    {
        var sIE6, sIE5, sNS6, scrl;   sIE6 = sIE5 = sNS6 = scrl = 0;
        if (window.document.documentElement)
              { sIE6 = parseInt(window.document.documentElement.scrollTop); }
        sIE5 = parseInt(window.document.body.scrollTop);
        sNS6 = parseInt(window.scrollY);
        if (!(numb_isnumPos(sIE6)))  { sIE6 = 0; }
        if (!(numb_isnumPos(sIE5)))  { sIE5 = 0; }
        if (!(numb_isnumPos(sNS6)))  { sNS6 = 0; }
        if      (sIE6 > 0) { scrl = sIE6; }
        else if (sIE5 > 0) { scrl = sIE5; }
        else if (sNS6 > 0) { scrl = sNS6; }
        else               { scrl = 0;    }
        return Math.round(scrl);
    }

    function viewport_height()
    {
  		var doc = window.document;
  		if (window.innerHeight)                                                  // all except ie
  		{
  			return window.innerHeight;
  		}
  		else if (doc.documentElement && doc.documentElement.clientHeight)        // ie6 Strict Mode
  		{
  			return doc.documentElement.clientHeight;
  		}
  		else if (doc.body)                                                       // other ie
  		{
  			return doc.body.clientHeight;
  		}
    }

    function numb_isnum(aValue)     { return ( !isNaN(Number(aValue)) ); }
    function numb_isnumPos(aValue)  { return ( (numb_isnum(aValue)) ? (aValue >= 0) : false ); }




    try
    {
        var me      = kpl_overview;
        var thumb   = new Image();
        var thumbs  = new Array();
        var tmbsBox = null;
        var doc     = window.document;
        var dom1, dom2, has, ctt, link;
        
        if (this instanceof me)           { return null; }
        dom1 = doc;
        if (!dom1)                        { return null; }
        if (!dom1.getElementById)         { return null; }
        if (!dom1.createElement)          { return null; }
        if (!dom1.firstChild)             { return null; }
        if (!dom1.firstChild.parentNode)  { return null; }
        me.content = doc.getElementById(me.CONTENT_ID);
        if (!me.content)                  { return null; }
        dom2 = me.content;
        if (!dom2.style)                  { return null; }
        if (!dom2.className)              { return null; }
        if (!dom2.offsetParent)           { return null; }
        if (!dom2.offsetHeight)           { return null; }
        if (!dom2.offsetWidth)            { return null; }
        tmbsBox = doc.getElementById(me.THUMBNAILS_ID);
        if (!tmbsBox)                     { return null; }
        thumbs = tmbsBox.getElementsByTagName('img');
        if (!(thumbs.length > 0))         { return null; }
        
        has = dom_ofClass;
        ctt  = me.content;
        if (has(ctt, me.CLASS_OVW_DISABLED)) { me.enabled = false; return null;   }
        if (has(ctt, me.CLASS_PVW_AUTO    )) { me.previewHeightMax = 'auto';      }
        if (has(ctt, me.CLASS_PVW_AUTO150 )) { me.previewHeightMaxAutoAdj = 1.50; }
        if (has(ctt, me.CLASS_PVW_AUTO140 )) { me.previewHeightMaxAutoAdj = 1.40; }
        if (has(ctt, me.CLASS_PVW_AUTO130 )) { me.previewHeightMaxAutoAdj = 1.30; }
        if (has(ctt, me.CLASS_PVW_AUTO120 )) { me.previewHeightMaxAutoAdj = 1.20; }
        if (has(ctt, me.CLASS_PVW_AUTO110 )) { me.previewHeightMaxAutoAdj = 1.10; }
        if (has(ctt, me.CLASS_PVW_AUTO105 )) { me.previewHeightMaxAutoAdj = 1.05; }
        if (has(ctt, me.CLASS_PVW_AUTO100 )) { me.previewHeightMaxAutoAdj = 1.00; }
        if (has(ctt, me.CLASS_PVW_AUTO95  )) { me.previewHeightMaxAutoAdj = 0.95; }
        if (has(ctt, me.CLASS_PVW_AUTO90  )) { me.previewHeightMaxAutoAdj = 0.90; }
        if (has(ctt, me.CLASS_PVW_AUTO85  )) { me.previewHeightMaxAutoAdj = 0.85; }
        if (has(ctt, me.CLASS_PVW_AUTO80  )) { me.previewHeightMaxAutoAdj = 0.80; }
        if (has(ctt, me.CLASS_PVW_AUTO75  )) { me.previewHeightMaxAutoAdj = 0.75; }
        if (has(ctt, me.CLASS_PVW_AUTO70  )) { me.previewHeightMaxAutoAdj = 0.70; }
        if (has(ctt, me.CLASS_PVW_AUTO65  )) { me.previewHeightMaxAutoAdj = 0.65; }
        if (has(ctt, me.CLASS_PVW_AUTO60  )) { me.previewHeightMaxAutoAdj = 0.60; }
        if (has(ctt, me.CLASS_PVW_AUTO55  )) { me.previewHeightMaxAutoAdj = 0.55; }
        if (has(ctt, me.CLASS_PVW_AUTO50  )) { me.previewHeightMaxAutoAdj = 0.50; }
        if (has(ctt, me.CLASS_PVW_AUTO45  )) { me.previewHeightMaxAutoAdj = 0.45; }
        if (has(ctt, me.CLASS_PVW_AUTO40  )) { me.previewHeightMaxAutoAdj = 0.40; }
        if (has(ctt, me.CLASS_PVW_600     )) { me.previewHeightMax = 600;         }
        if (has(ctt, me.CLASS_PVW_500     )) { me.previewHeightMax = 500;         }
        if (has(ctt, me.CLASS_PVW_400     )) { me.previewHeightMax = 400;         }
        if (has(ctt, me.CLASS_PVW_350     )) { me.previewHeightMax = 350;         }
        if (has(ctt, me.CLASS_PVW_330     )) { me.previewHeightMax = 330;         }
        if (has(ctt, me.CLASS_PVW_300     )) { me.previewHeightMax = 300;         }
        if (has(ctt, me.CLASS_PVW_275     )) { me.previewHeightMax = 275;         }
        if (has(ctt, me.CLASS_PVW_250     )) { me.previewHeightMax = 250;         }
        if (has(ctt, me.CLASS_PVW_225     )) { me.previewHeightMax = 225;         }
        if (has(ctt, me.CLASS_PVW_200     )) { me.previewHeightMax = 200;         }
        if (has(ctt, me.CLASS_PVW_175     )) { me.previewHeightMax = 175;         }
        if (has(ctt, me.CLASS_PVW_150     )) { me.previewHeightMax = 150;         }
        if (has(ctt, me.CLASS_PVW_125     )) { me.previewHeightMax = 125;         }
        if (has(ctt, me.CLASS_PVW_100     )) { me.previewHeightMax = 100;         }
        if (has(ctt, me.CLASS_PVW_OFF     )) { me.previewHeightMax = 'off';       }
        if (has(ctt, me.CLASS_PVW_ENABLED )) { me.previewEnabled = true;          }
        if (has(ctt, me.CLASS_PVW_DISABLED)) { me.previewEnabled = false;         }
        if (has(ctt, me.CLASS_CPN_ENABLED )) { me.captionEnabled = true;          }
        if (has(ctt, me.CLASS_CPN_DISABLED)) { me.captionEnabled = false;         }

        me.caption = caption_makeElement(me.CAPTION_ID);
        me.preview = preview_makeElement(me.PREVIEW_ID);
        me.preview.onload     = preview_onload;
        me.preview.onclick    = panels_hide;
        me.caption.onclick    = panels_hide;
        me.content.ondblclick = preview_toggleHeightMaxOverride;
        for(var i=0; i<thumbs.length; i++)
        {
            thumb = thumbs[i];
            link  = thumb.parentNode;
            link.onclick      = viewer_show;                         
            thumb.onclick     = panels_hide;
            thumb.onmouseover = panels_show;
            thumb.onmouseout  = panels_hide;
            thumb.alt   = thumb.title; 
            thumb.title = '';
        }
        if ((me.previewHeightMax != 'off') && (me.msie || me.opera))                                                                  // firefox has probs
        { 
            me.content.title = 'double-click to zoom flash-image to/fro full-size'; 
            me.content.firstChild.title = '';
        }
        me.previewPreload = new Image();
        
        me.enabled = true;
    }
    catch(e){kpl_overview.enabled=false;}    

}


// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

kpl_overview.VIEWER_PAGE_URL    = 'xoview/picpage/viewer.htm';        
kpl_overview.PREVIEW_ID         = 'kpl_ovw_preview';                  
kpl_overview.CAPTION_ID         = 'kpl_ovw_caption';                  
kpl_overview.THUMBNAILS_ID      = 'kpl_ovw_thumbnailed-links';        
kpl_overview.CONTENT_ID         = 'kpl_ovw_content';                  
kpl_overview.CLASS_PVW_AUTO     = 'kpl_ovw_preview_height_max_auto';
kpl_overview.CLASS_PVW_AUTO150  = 'kpl_ovw_preview_height_max_auto150';
kpl_overview.CLASS_PVW_AUTO140  = 'kpl_ovw_preview_height_max_auto140';
kpl_overview.CLASS_PVW_AUTO130  = 'kpl_ovw_preview_height_max_auto130';
kpl_overview.CLASS_PVW_AUTO120  = 'kpl_ovw_preview_height_max_auto120';
kpl_overview.CLASS_PVW_AUTO110  = 'kpl_ovw_preview_height_max_auto110';
kpl_overview.CLASS_PVW_AUTO105  = 'kpl_ovw_preview_height_max_auto105';
kpl_overview.CLASS_PVW_AUTO100  = 'kpl_ovw_preview_height_max_auto100';
kpl_overview.CLASS_PVW_AUTO95   = 'kpl_ovw_preview_height_max_auto95';
kpl_overview.CLASS_PVW_AUTO90   = 'kpl_ovw_preview_height_max_auto90';
kpl_overview.CLASS_PVW_AUTO85   = 'kpl_ovw_preview_height_max_auto85';
kpl_overview.CLASS_PVW_AUTO80   = 'kpl_ovw_preview_height_max_auto80';
kpl_overview.CLASS_PVW_AUTO75   = 'kpl_ovw_preview_height_max_auto75';
kpl_overview.CLASS_PVW_AUTO70   = 'kpl_ovw_preview_height_max_auto70';
kpl_overview.CLASS_PVW_AUTO65   = 'kpl_ovw_preview_height_max_auto65';
kpl_overview.CLASS_PVW_AUTO60   = 'kpl_ovw_preview_height_max_auto60';
kpl_overview.CLASS_PVW_AUTO55   = 'kpl_ovw_preview_height_max_auto55';
kpl_overview.CLASS_PVW_AUTO50   = 'kpl_ovw_preview_height_max_auto50';
kpl_overview.CLASS_PVW_AUTO45   = 'kpl_ovw_preview_height_max_auto45';
kpl_overview.CLASS_PVW_AUTO40   = 'kpl_ovw_preview_height_max_auto40';
kpl_overview.CLASS_PVW_600      = 'kpl_ovw_preview_height_max_600px'; 
kpl_overview.CLASS_PVW_500      = 'kpl_ovw_preview_height_max_500px'; 
kpl_overview.CLASS_PVW_400      = 'kpl_ovw_preview_height_max_400px'; 
kpl_overview.CLASS_PVW_350      = 'kpl_ovw_preview_height_max_350px'; 
kpl_overview.CLASS_PVW_330      = 'kpl_ovw_preview_height_max_330px'; 
kpl_overview.CLASS_PVW_300      = 'kpl_ovw_preview_height_max_300px'; 
kpl_overview.CLASS_PVW_275      = 'kpl_ovw_preview_height_max_275px'; 
kpl_overview.CLASS_PVW_250      = 'kpl_ovw_preview_height_max_250px'; 
kpl_overview.CLASS_PVW_225      = 'kpl_ovw_preview_height_max_225px'; 
kpl_overview.CLASS_PVW_200      = 'kpl_ovw_preview_height_max_200px'; 
kpl_overview.CLASS_PVW_175      = 'kpl_ovw_preview_height_max_175px'; 
kpl_overview.CLASS_PVW_150      = 'kpl_ovw_preview_height_max_150px'; 
kpl_overview.CLASS_PVW_125      = 'kpl_ovw_preview_height_max_125px'; 
kpl_overview.CLASS_PVW_100      = 'kpl_ovw_preview_height_max_100px'; 
kpl_overview.CLASS_PVW_OFF      = 'kpl_ovw_preview_height_max_off';   
kpl_overview.CLASS_PVW_ENABLED  = 'kpl_ovw_preview_enabled';       
kpl_overview.CLASS_PVW_DISABLED = 'kpl_ovw_preview_disabled';      
kpl_overview.CLASS_CPN_ENABLED  = 'kpl_ovw_caption_enabled';       
kpl_overview.CLASS_CPN_DISABLED = 'kpl_ovw_caption_disabled';      
kpl_overview.CLASS_OVW_DISABLED = 'kpl_ovw_disabled';              

kpl_overview.opera = (window.navigator.userAgent.toLowerCase().indexOf('opera') > -1 );
kpl_overview.msie  = (window.navigator.userAgent.toLowerCase().indexOf('msie')  > -1)  &&
                     (!kpl_overview.opera);

// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

kpl_overview.previewEnabled          = true;        // PREVIEW IS TO BE SHOWN
kpl_overview.captionEnabled          = true;        // CAPTION IS TO BE SHOWN

kpl_overview.previewHeightMax        = 0;      // PREVIEW MAX-HEIGHT: in px (auto = full height)
kpl_overview.previewHeightMaxAutoAdj = 0;         // PREVIEW MAX-HGHT AUTOSCALE VERNIER:  (0.9=90%)
kpl_overview.previewHeightMaxLowest  = 0;         // PREVIEW MAX-HGHT MINIMUM: lower limit     (px)
kpl_overview.previewHeightMaxPadding = 0;          // PREVIEW MAX-HGHT PAD: clear viewport,etc. (px)
kpl_overview.previewClearance        = 0;           // PREVIEW CLEARANCE: offset from thumbnail  (px)
kpl_overview.captionClearance        = 4;           // CAPTION CLEARANCE: offset from thumbnail  (px)
kpl_overview.captionWidth            = 180;         // CAPTION WIDTH                             (px)
kpl_overview.previewShowTime         = 10;          // PREVIEW DISPLAY-TIME (secs)
kpl_overview.captionReadSpeedCPS     = 20;          // CAPTION READ-RATE: user read speed (chars/sec)
kpl_overview.captionShowMinimum      = 3;           // CAPTION DISPLAY-TIME (secs) short caption

kpl_overview.PREVIEWS_FOLDER         = 'preview';   // FOLDER-NAME: PREVIEW   images
kpl_overview.THUMBS_FOLDER           = 'thumbnail'; // FOLDER-NAME: THUMBNAIL images


// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


// TECH NOTE: BUGGER!
// If the PREVIEW-IMAGE is mispositioned (eg, LOW in IE6 but not Firefox1.5 or Opera8),
// then you've introduced borders into the containing-structure somewhere thru to
// the body-element and these border-sizes are being included by IE in
// the 'offsetTop'and 'offsetLeft values - see functions 'dom_topToBody'/'dom_topToBody'.




// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .




// when page fully loaded, initialise OverView if a modern-browser [obsolete browsers are not countenanced].
// important: OverView is a component and reserves 'window.onload' for possible use by the host-page.

(       
        function ()
        {
            try
            {
                var EVT_CAPTURE_W3C     = false;
                var ON_PAGE_LOADED_W3C  = 'load';
                var ON_PAGE_LOADED_MSIE = 'onload';                  
                var W3C_events          = !!(window.addEventListener);
                var MSIE_events         = !!(window.attachEvent);
                
                if (W3C_events)  
                {
                   window.addEventListener(ON_PAGE_LOADED_W3C, kpl_overview, EVT_CAPTURE_W3C);
                } 
                else if (MSIE_events)  
                {
                   window.attachEvent(ON_PAGE_LOADED_MSIE, kpl_overview);
                } 
            }
            catch(e){ }
       }    
 )();


// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .




/*
  Copyright (c) 2005   Ian Brown  (contact: see www.kleeton.com.au)

  Permission is hereby granted, free of charge, to any person obtaining a copy of
  this software and associated documentation files (the "Software"), to deal in
  the Software for non-commercial purposes including without limitation the rights
  to use, copy, publish, distribute and/or sublicense copies of the Software,
  and to permit persons to whom the Software is furnished to do so,
  subject to the following conditions:

  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.

  The Software shall be used for Peaceful Purposes and Greater Good.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.
  
  To deal in the Software for commercial purposes, please contact Kleeton PL.
*/







// FOR DEBUG AND DEMO USE ONLY (NOT A PART OF OVERVIEW)

// Toggle stylesheet(s) off/on. When Off, the default HTML styles are used.
// Note: disabling stylesheets is W3C DOM2 functionality. No-go in Opera8.
// (( loop thru stylesheets collection, set the 'disabled' property of all ))
// (( stylesheets to the inverted 'disabled' property of the first sheet.  ))

function xStyleSheetOnOff()
{
   var oSheets, disabledSetting, sheetIndex;
   oSheets = window.document.styleSheets;
   if (oSheets.length > 0)  {
      disabledSetting = !(oSheets[0].disabled);               // invert sheet0
      for (sheetIndex = 0; sheetIndex < oSheets.length; sheetIndex++)
      {   oSheets[sheetIndex].disabled = disabledSetting;
      }
   }
}
