(function() {
	var
	  questions = [ { "title": "Loose skin under eyes after Blepharoplasty", "nid": "85817", "url": "/question/blepharoplasty-loose-skin-under-eyes?p=s#tip-106527" }, { "title": "Is two weeks after Blepharoplasty too soon to travel?", "nid": "85821", "url": "/question/travel-upper-blepharoplasty?p=s#tip-106525" }, { "title": "Is it safe to have Blepharoplasty after Juvederm injection?", "nid": "85998", "url": "/question/blepharoplasty-juvederm-injection?p=s#tip-106524" }, { "title": "Does a chin implant ever leak or expire?", "nid": "85707", "url": "/question/had-chin-implant-do-they-ever-expire-or-leak?p=s#tip-106521" }, { "title": "Chin implant revision", "nid": "85759", "url": "/question/chin-implant-revision?p=s#tip-106518" } ],
	  pro = { "nid": 7039, "title": "William Portuese, MD", "uri": "find/Washington/Seattle/Facial-Plastic-Surgeon/William-Portuese" },
	  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);
})();
