/* ------------------- Helper functions below --------------------- */

function getElementsByClass(containingEl, tagName, className){
   // Convenience function
    var collection;
    var returnedCollection = new Array(0);
    var counter = 0;
    if(containingEl.all && tagName == "*") tagName = containingEl.all;
    else collection = containingEl.getElementsByTagName(tagName);
    for(var i = 0; i < collection.length; i++){
        if(collection[i].className == className){
            returnedCollection[counter] = collection[i];
            counter++;
        }
    }
    return returnedCollection;
}


function settBildetekstbredde(parentElement, elementType, elementClass) {
  var nodes = new Array();
  var el = document.getElementById(parentElement);
  var boxList = getElementsByClass(el, elementType, elementClass);
  for (var i = 0; i < boxList.length; i++) {
    var box = boxList[i];
    var id = box.id;	
    var imgElement = box.getElementsByTagName("img")[0];
    var textElement = getElementsByClass(box, "p", "pictureText")[0];
    var width = imgElement.width;
    textElement.style.width = width;
  }
}