﻿// Copyright (C) 2007 XtractPro (Data Extraction Magazine)
// http://www.xtractpro.com, support@xtractpro.com
//
// This code is provided AS IS, with NO WARRANTY expressed or implied.
// Any use of this free open source code is at your own risk.
//
// You are hereby granted the right to use it and change it,
// provided that you acknowledge XtractPro somewhere in your
// source files, documentation, web site and application.

// current animated docking panel content element
var crtDockContent = null;

function TogglePanel(contentID, imageId, interval, step, vert) {
    var content = document.getElementById(contentID);
    var chevron = document.getElementById(imageId);

    // wait for another animated expand/collapse action to end
    if (typeof (content) != "undefined"
        && typeof (chevron) != "undefined"
        && crtDockContent == null) {
        crtDockContent = content;
        var expand = (content.style.display == "none");
        if (expand)
            content.style.display = "block";

        toggleChevronIcon(chevron);
        var max_height = (vert ? content.offsetHeight : content.offsetWidth);
        var step_height = step + (expand ? 0 : -max_height);

        // schedule first animated collapse/expand event
        if (vert)
            content.style.height = Math.abs(step_height) + "px";
        else
            content.style.width = Math.abs(step_height) + "px";
        setTimeout("ToggleDockingPanelAnimation("
            + interval + "," + step + "," + max_height + ","
            + step_height + "," + vert + ")", interval);
    }
}
function ToggleDockingPanelAnimation(interval, step, max_height, step_height, vert) {
    if (crtDockContent == null)
        return;

    var step_height_abs = Math.abs(step_height);

    // schedule next animated collapse/expand event
    if (step_height_abs >= step && step_height_abs <= (max_height - step)) {
        step_height += step;
        if (vert)
            crtDockContent.style.height = Math.abs(step_height) + "px";
        else
            crtDockContent.style.width = Math.abs(step_height) + "px";
        setTimeout("ToggleDockingPanelAnimation("
            + interval + "," + step + "," + max_height + ","
            + step_height + "," + vert + ")", interval);
    }
    // animated expand/collapse done
    else {
        if (step_height_abs < step)
            crtDockContent.style.display = "none";
        if (vert)
            crtDockContent.style.height = "";
        else
            crtDockContent.style.width = "";
        crtDockContent = null;
    }
}
function toggleChevronIcon(chevron) {
    var expand = (chevron.src.indexOf("expand.gif") > 0);
    chevron.src = chevron.src
        .split(expand ? "expand.gif" : "collapse.gif")
        .join(expand ? "collapse.gif" : "expand.gif");
}
