﻿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)
}

var showHideElement = new Array();

function showElement(id) {
    var child = document.getElementById(id).getElementsByTagName('ul')[0];
    if (child) {
        showHideElement[child.id] = 'show';
        window.setTimeout('doDisplay(\'' + child.id + '\',true)', 0);
    }
}
function hideElement(id) {
    var child = document.getElementById(id).getElementsByTagName('ul')[0];
    if (child) {
        showHideElement[child.id] = 'hide';
        window.setTimeout('doDisplay(\'' + child.id + '\',false)', 1);
    }
}
function doDisplay(id,bDisplay) {
    if (bDisplay) {
        if (showHideElement[id] == 'show') {
            document.getElementById(id).style.display = 'block';
        }
    } else {
        if (showHideElement[id] == 'hide') {
            document.getElementById(id).style.display = 'none';
        }
    }
}


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 newsletterDefaultValue = '';
function initiateNewsletterForm(id) {
    newsletterDefaultValue = document.getElementById(id).value;
    document.getElementById(id).className = 'inactiv';
}
function handleNewsletterForm(id, b) {
    if (id != null && document.getElementById(id) != null) {
        if (b) {
            if (document.getElementById(id).value == newsletterDefaultValue) {
                document.getElementById(id).value = '';
                document.getElementById(id).className = '';
            }
        } else {
            if (document.getElementById(id).value == '') {
                document.getElementById(id).value = newsletterDefaultValue;
                document.getElementById(id).className = 'inactiv';
            }
        }
    }
}

//schwarzkopf lasche
function handle_clip(time) {
    if (!time)
        time = 1000;
    $('#clip').mouseover(function () {
        if (!clipIsAnimating) {
            clipIsAnimating = true;
            $('#clip').animate({
                width: 199
            }, time, function () {
                clipIsAnimating = false;
            });
        }

    });
    $('#clip').mouseout(function () {

        $('#clip').animate({
            width: 52
        }, time);

    });
}
var clipIsAnimating = false;

$(document).ready(function () {
    handle_clip(500);
});
