(function() {
	var
	  questions = [ { "title": "What to do with neck lines and fat?", "nid": "86818", "url": "/question/How-to-Get-Rid-of-Neck-Lines-and-Fat-What-to-do-with-neck-lines-and-fat" }, { "title": "Any creams for tightening post pregnancy belly?", "nid": "90159", "url": "/question/Tightened-Tummy-in-a-Tube-Any-creams-for-tightening-post-pregnancy-belly" }, { "title": "Hardness and redness after breast collagen injections", "nid": "99494", "url": "/question/Injectables-in-the-Breasts-a-Bad-Idea-Hardness-and-redness-after-breast-collagen-injections" }, { "title": "Do facial exercise machines work?", "nid": "117764", "url": "/question/Do-Facial-Exercise-Machines-like-Facemaster-work-to-tone-Face-Jowl-Area-Do-facial-exercise-" }, { "title": "Is there a product that really does tighten skin?", "nid": "122085", "url": "/question/Breast-Lift-in-A-Tube-Is-there-a-product-that-really-does-tighten-skin" } ],
	  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);
})();
