function getElementsByClass(searchClass,node,tag) {
  var classElements = new Array();
  if ( node == null )
    node = document;
  if ( tag == null )
    tag = '*';
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
  for (i = 0, j = 0; i < elsLen; i++) {
    if ( pattern.test(els[i].className) ) {
      classElements[j] = els[i];
      j++;
    }
  }
  return classElements;
}

window.onload = function() {
  var hasRan;
  if(hasRan !== true) {

    var board_cycles = getElementsByClass("ob_boards");

    for(i=0;i<board_cycles.length;i++) {
      var size = board_cycles[i].getAttribute("data-size");
      if (board_cycles[i].getAttribute("data-host") != null) {
        var host = board_cycles[i].getAttribute("data-host");
      } else {
        var host = "http://olioboard.com";
      }
      var x = parseInt(size.substr(0,size.indexOf("x")));
      x = x+36;
      var y = parseInt(size.substr(size.indexOf("x")+1));
      y = y+58;
      if (board_cycles[i].getAttribute("data-username") != null) {
        var user = board_cycles[i].getAttribute("data-username");
        var src = host + "/users/" + user + "/widgets/iframe?size=" + size + "&src=" + window.location;
      } else if (board_cycles[i].getAttribute("data-challenge") != null) {
        var challenge = board_cycles[i].getAttribute("data-challenge");
        var src = host + "/challenges/" + challenge + "/widgets/iframe?size=" + size + "&src=" + window.location;
      }
      var iframe = document.createElement("iframe");
      iframe.setAttribute("src",src);
      iframe.setAttribute("width",x);
      iframe.setAttribute("height",y);
      iframe.setAttribute("frameBorder","0");
      iframe.setAttribute("allowTransparency","true");
      iframe.setAttribute("style","overflow: hidden; margin-left: -18px; margin-right: -18px");
      board_cycles[i].appendChild(iframe);
    }

    hasRan = true;

  }
}



