(function() {
	var
	  questions = [ { "title": "How do I know if real Botox is being injected?", "nid": "166507", "url": "/question/real-botox-cosmetic-place" }, { "title": "Recommended downtime for Sculptra?", "nid": "166800", "url": "/question/sculptra-cosmetic-injectionsusually-minimal-downtime" }, { "title": "Is Thermage effective on fine lines around the mouth?", "nid": "166423", "url": "/question/thermage-combination-skin-resurfacing-diminish-lip-lines" }, { "title": "Who should give Restylane injections?", "nid": "165293", "url": "/question/ocular-plastic-physicians-eyelid-anatomy-intimately" }, { "title": "Full eyelid ptosis correction in a 2-year-old possible through surgery?", "nid": "145330", "url": "/question/Congenital-Ptosis-Needs-Evaluation-Now-Full-eyelid-ptosis-correction-in-a-2-year-old-possib" } ],
	  pro = { "nid": 12338, "title": "Mark Berkowitz, MD", "uri": "find/Michigan/Sterling-Heights/Oculoplastic-surgeon/Mark-Berkowitz" },
	  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) {
			for (var i = 0; i < links.length; i++) {
				links[i].href += (links[i].href.indexOf('#') == -1 ? '#' : '');
			}
		}
	}
	
	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);
})();
