﻿function Blind(expandElementId, minValue, maxValue, flowVertical, shrinkElementId) {
    var targetValue;
    
    if (typeof(flowVertical) == 'undefined')
        flowVertical = true;
    
    var expandElement = document.getElementById(expandElementId);
    
    if (flowVertical) {
        if (expandElement.offsetHeight < maxValue)
            targetValue = maxValue;
        else
            targetValue = minValue;
    }
    else {
        if (expandElement.offsetWidth < maxValue)
            targetValue = maxValue;
        else
            targetValue = minValue;
    }
    
    AdjustSize(expandElementId, targetValue, flowVertical, shrinkElementId)
}

function AdjustSize(expandElementId, targetValue, flowVertical, shrinkElementId) {
    if (typeof(flowVertical) == undefined)
        flowVertical = true;
        
    var expandElement = document.getElementById(expandElementId);
    var shrinkElement;
    if (typeof(shrinkElementId) != undefined)
        shrinkElement = document.getElementById(shrinkElementId);
    
    var doExpand = false;
    if (flowVertical)
        doExpand = expandElement.offsetHeight < targetValue;
    else
        doExpand = expandElement.offsetWidth < targetValue;
    
    var step = -2;
    if (doExpand)
        step = 2;
        
    if (flowVertical) {
        expandElement.style.height = (expandElement.offsetHeight + step) + 'px';
        expandElement.style.display = '';
        
        if (shrinkElement) {
            shrinkElement.style.height = (shrinkElement.offsetHeight + (step * -1)) + 'px';
            if (shrinkElement.style.height == '0px')
                shrinkElement.style.display = 'none';
        }
        
        if ((doExpand && expandElement.offsetHeight < targetValue) || (!doExpand && expandElement.offsetHeight > targetValue))
            window.setTimeout("AdjustSize('" + expandElementId + "', " + targetValue + ", " + flowVertical + ", '" + shrinkElementId + "')", 1);
    }
    else {
        expandElement.style.width = (expandElement.offsetWidth + step) + 'px';
        expandElement.style.display = '';
        
        if (shrinkElement) {
            shrinkElement.style.width = (shrinkElement.offsetWidth + (step * -1)) + 'px';
            if (shrinkElement.style.width == '0px')
                shrinkElement.style.display = 'none';
        }
        
        if ((doExpand && expandElement.offsetHeight < targetValue) || (!doExpand && expandElement.offsetHeight > targetValue))
            window.setTimeout("AdjustSize('" + expandElementId + "', " + targetValue + ", " + flowVertical + ", '" + shrinkElementId + "')", 1);
    }
}

var navigationElements = null;
var currentElement = null;

function Blend(id, fileNotation) {
    var object;
    if(navigationElements == null) {
        navigationElements = new Array();
        object = document.getElementsByTagName("div");
        for(var i=0; i<object.length; i++) {
            if(object[i].id.indexOf(fileNotation) > -1)
                navigationElements.push(object[i]);
        }
    }
    if(currentElement == null) {
        for(var i=0; i<navigationElements.length; i++) {
           if(document.getElementById(navigationElements[i].id.substr(fileNotation.toString().length,navigationElements[i].id.toString().length)).className == "current")
             currentElement = navigationElements[i].id.substr(fileNotation.toString().length,navigationElements[i].id.toString().length);
        }
        
    }
    for(var i=0; i<navigationElements.length; i++) {
        navigationElements[i].style.display = "none";
        document.getElementById(id).className = "normal";
    }
    document.getElementById(id).className = "current";
    document.getElementById(fileNotation + id).style.display = "block";
    
}
function BlendOut(fileNotation) {
    var currentItem;
    for(var i=0; i<navigationElements.length; i++) {
        currentItem = navigationElements[i].id.substr(fileNotation.toString().length,navigationElements[i].id.toString().length);
        document.getElementById(currentItem).className = "normal";
        if(currentElement != null) 
            document.getElementById(currentElement).className = "current";
        document.getElementById(fileNotation+currentItem).style.display = "none";
    }
    
}