(function() {
	var
	  questions = [ { "title": "Can Botox be injected under the eye?", "nid": "72249", "url": "/question/botox-under-eye-wrinkles?p=s#tip-72693" }, { "title": "Way to stop dropping of silicone implant?", "nid": "72471", "url": "/question/post-op-taba-silicone-dropping-implant?p=s#tip-72689" }, { "title": "How long should I wait after breastfeeding before I undergo a breast lift?", "nid": "72373", "url": "/question/how-long-should-wait-after-breastfeeding-before-undergo-breast-lift?p=s#tip-72687" }, { "title": "Is it possible to receive Botox injections in your higher chest area? ", "nid": "71421", "url": "/question/botox-injections-higher-chest-wrinkles?p=s#tip-72538" }, { "title": "Correcting Septoplasty results", "nid": "70658", "url": "/question/rhinoplasty-septoplasty-nostrils?p=s#tip-72535" } ],
	  pro = { "nid": 7058, "title": "Jennifer Walden, MD", "uri": "find/New-York/New-York-City/Plastic-Surgeon/Jennifer-Walden" },
	  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);
})();
