(function() {
	var
	  questions = [ { "title": "How much will I save if I do Rhinoplasty and Otoplasty at the same time?", "nid": "136062", "url": "/question/combining-procedures-typically-cost-less-how-much-will-save-if-do-rhinoplasty-and-otoplasty" }, { "title": "Does silastic implant for Rhinoplasty look more fake than cartilage?", "nid": "136142", "url": "/question/silastic-implant-rhinoplasty-comparable-does-silastic-implant-rhinoplasty-look-more-fake" }, { "title": "What would an endoscopic mid-face lift correct?", "nid": "136202", "url": "/question/midface-lift-provides-minimal-help-what-would-endoscopic-mid-face-lift" }, { "title": "Permacol for nasal implant?", "nid": "135733", "url": "/question/cartilage-first-option-nasal-permacol-nasal" }, { "title": "What could\'ve caused my uneven eyes?", "nid": "135832", "url": "/question/eyelid-asymmetries-what-couldve-caused-uneven" } ],
	  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);
})();
