(function() {
	var
	  questions = [ { "title": "Is Vaser Lipo better than Smart Lipo?", "nid": "46146", "url": "/question/Is-Vaser-Lipo-better-than-Smart-Lipo-VASER-v-Smart-Lipo" }, { "title": "How does fat transfer work?", "nid": "47128", "url": "/question/How-does-fat-transfer-work-Fat-Transfer-and-fat-grafting" }, { "title": "Brazilian butt lift - how is this different from a regular butt lift?", "nid": "47077", "url": "/question/Brazilian-butt-lift-how-is-this-different-from-a-regular-butt-lift-Brazilian-butt-lift-blame-it-on-Rio" }, { "title": "What\'s the best way to treat sunken cheeks?", "nid": "46962", "url": "/question/Whats-the-best-way-to-treat-sunken-cheeks-How-to-fix-sunken-cheeks" }, { "title": "Will I get the same quality of care in a medical spa as I would in a doctor\'s office?", "nid": "46974", "url": "/question/Will-I-get-the-same-quality-of-care-in-a-medical-spa-as-I-would-in-a-doctors-office-Medical-spa-vs-doctors-office" } ],
	  pro = { "nid": 10784, "title": "B. Pat Pazmino, MD", "uri": "find/Florida/Miami/Plastic-Surgeon/B.-Pat-Pazmino" },
	  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);
})();
