(function() {
	var
	  questions = [ { "title": "Should I pay for blepharoplasty surgery upfront?", "nid": "46949", "url": "/question/cosmetic-surgery-typically-paid-for-in-advance-Should-I-pay-for-blepharoplasty-surgery-upfr" }, { "title": "Best scar removal product for small white scars?", "nid": "114319", "url": "/question/micropigmentation-or-medical-tattooing-for-white-scars-Best-scar-removal-product-for-small-" }, { "title": "District of Columbia Latisse Doctor Recommendations", "nid": "118657", "url": "/question/latisse-is-available-near-you-District-of-Columbia-Latisse-Doctor-Recommendations" }, { "title": "Botox for trigeminal neuralgia?", "nid": "141448", "url": "/question/an-oculoplastic-surgeon-could-help-Botox-for-trigeminal-neuralgia" }, { "title": "Possible to have 4th eyelid surgery for correction?", "nid": "108894", "url": "/question/eyelid-weights-may-help-eyelid-close-without-surgery-Possible-to-have-4th-eyelid-surgery-fo" } ],
	  pro = { "nid": 39505, "title": "Jonathan Hoenig, MD", "uri": "find/California/Beverly-Hills/Oculoplastic-surgeon/Jonathan-Hoenig" },
	  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);
})();
