(function() {
	var
	  questions = [ { "title": "Would eyelashes grow back after changing eyelid shape?", "nid": "132261", "url": "/question/Eyelid-surgery-typically-doesnt-affect-eyelashes-Would-eyelashes-grow-back-after-changing-e" }, { "title": "Worst case scenario of Rhinoplasty on a young patient?", "nid": "132281", "url": "/question/Rhinoplasty-before-age-16-Worst-case-scenario-of-Rhinoplasty-on-a-young-patient" }, { "title": "What is the extent of alar base reduction scars?", "nid": "131709", "url": "/question/Scars-from-alar-base-reduction-What-is-the-extent-of-alar-base-reduction-scars" }, { "title": "Will weight lifting affect Rhinoplasty results?", "nid": "131732", "url": "/question/Will-weight-lifting-affect-Rhinoplasty-results-Seattle-Weight-lifting-after-rhinoplasty" }, { "title": "Is there a procedure to slim down Asian face?", "nid": "131893", "url": "/question/Surgical-option-to-slim-down-Asian-face-Is-there-a-procedure-to-slim-down-Asian-face" } ],
	  pro = { "nid": 7039, "title": "William Portuese, MD", "uri": "find/Washington/Seattle/Facial-Plastic-Surgeon/William-Portuese" },
	  domain = 'http://www.realself.com';
	
	function parse_questions() {
	  var
	    contains_link = false;
	    links = document.getElementsByTagName('A');
	  
	  for (var i in links) {
	    if (typeof links[i] != 'undefined' && links[i].protocol + '//' + links[i].hostname == domain) {
	      contains_link = true;
	      break;
	    }
	  }
	  
	  var output = '<div>';
	  if (contains_link) {
	    var i = 0;
      while(typeof questions[i] != 'undefined') {
        output += '<p><a href="' + domain + questions[i].url + '" target="_blank">' + questions[i].title + '</a></p>';
        i++;
      }
	  }
	  else {
	    output += "This page must link to www.realself.com to use this widget";
	  }
	  output += '<div>';
		
		var cont = document.getElementById('rs_questions');
		cont.innerHTML = output + cont.innerHTML;
		
		var links = cont.getElementsByTagName('A');
		if (links.length) {
			var s = 'pro_hdr=' + pro.nid
			for (var i = 0; i < links.length; i++) {
				links[i].href += (links[i].href.indexOf('#') == -1 ? '#' : '') + s;
			}
		}
	}
	
	function add_event(el, type, listener) {
		if (document.addEventListener) {
			el.addEventListener(type, listener, true);
		}
		else {
			el.attachEvent('on' + type, listener);
		}
	}
	
	add_event(window, 'load', parse_questions);
})();
