function findEditSet(element) {
    var editset = element.childNodes;
    for (var i=0;i < editset.length; ++i) {
        if (editset[i].className == "editgui-gui-border-panel") {
            return true;
        }
    }
    return false;
}
function findVimeoUrlElement(element) {
    var children = element.childNodes;
    for (var i = 0; i < children.length; ++i) {
        if (children[i].className && children[i].className.search(/vimeo_url/i) >= 0)
            return children[i];

        if (children[i].childNodes ) {
            var urlElement = findVimeoUrlElement(children[i]);
            if (urlElement)
                return urlElement;
        }
    }
    return;
}
function onMouseOVerVimeoUrl(element) {
    if (!findEditSet(element)) return;
    var vimeoBlock = findVimeoUrlElement(element);
    if (vimeoBlock)
        vimeoBlock.style.display="block";
}
function onMouseOutVimeoUrl(element) {
    if (!findEditSet(element)) return;
    var vimeoBlock = findVimeoUrlElement(element);
    if (vimeoBlock)
        vimeoBlock.style.display="none";
}

function onChangeVimeoUrl(element) {
    var vimeoElement = element.parentNode.parentNode;
    /*while ( vimeoElement.className.search(/vimeoMain/i) < 0)
        vimeoElement = vimeoElement.parentNode;*/

    var children = vimeoElement.childNodes;
    for (var i = 0; i < children.length; ++i) {
        if ( children[i].className=="vimeoObject") {
            children = children[i].childNodes;
            break;
        }
    }

    var movieElement;
    var auxElement;
    for (var i = 0; i < children.length; ++i) {
        if ( movieElement && auxElement )
            break;

        if ( children[i].name=="movie") {
            movieElement = children[i];
            continue;
        }
        else if (children[i].name=="aux") {
            auxElement = children[i];
            continue;
        }
    }


    var clipIp;
    children = element.parentNode.childNodes;
    for (var i = 0; i < children.length; ++i) {
        if ( children[i].name=="vimeolink") {
            //clipIp = children[i].value.substring(children[i].value.lastIndexOf("/")+1,children[i].value.length);
            clipIp = children[i].value.substring(children[i].value.search(/[0-9]*$/i),children[i].value.length);
            break;
        }
    }

    var regExpClipId = /clip_id=/i;
    movieElement.value = movieElement.value.substring(0, (movieElement.value.search(regExpClipId)+8)) + clipIp + movieElement.value.substring(movieElement.value.indexOf("&"),movieElement.value.length);
    auxElement.src = auxElement.src.substring(0, (auxElement.src.search(regExpClipId)+8)) + clipIp + auxElement.src.substring(auxElement.src.indexOf("&"),auxElement.src.length);

}

