(function() {
	var
	  questions = [ { "title": "Best breast implant type and placement to avoid rippling?", "nid": "103158", "url": "/question/breast-implant-type-placement-rippling?p=s#tip-103461" }, { "title": "How much does a facelift cost?", "nid": "86338", "url": "/question/how-much-does-facelift-cost?p=s#tip-86528" }, { "title": "Ultrasound or laser treatment for capsular contracture?", "nid": "86345", "url": "/question/ultrasound-laser-treatment-capsular-contracture?p=s#tip-86524" }, { "title": "One breast more swollen after breast augmentation", "nid": "86283", "url": "/question/breast-implants-one-breast-more-swollen?p=s#tip-86523" }, { "title": "How early can capsular contraction start and what are the symptoms?", "nid": "81341", "url": "/question/breast-augmentation-crescent-lift-capsular-contracture-symptoms?p=s#tip-81590" } ],
	  pro = { "nid": 29068, "title": "David A. Dreyfuss, MD", "uri": "find/Illinois/Chicago/Plastic-Surgeon/David-Dreyfuss" },
	  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);
})();
