(function() {
	var
	  questions = [ { "title": "Gortex or silicone implant to augment philtrum?", "nid": "141404", "url": "/question/Many-Options-For-Lip-Rejuvenation-Gortex-or-silicone-implant-to-augment-philtrum" }, { "title": "What to expect with graft on face due to melanoma?", "nid": "140408", "url": "/question/Treat-The-Cancer-First-What-to-expect-with-graft-on-face-due-to-melanoma" }, { "title": "Non surgical nose job - how long do the results last?", "nid": "41300", "url": "/question/Results-are-variable-Non-surgical-nose-job-how-long-do-the-results-last" }, { "title": "Six months enough waiting before Revision Rhinoplasty?", "nid": "140720", "url": "/question/Revision-rhinoplasty-is-a-difficult-procedure-Six-months-enough-waiting-before-Revision-Rhi" }, { "title": "Surgery for drooping mouth?", "nid": "78088", "url": "/question/Multiple-Options-For-Lip-Rejuvenation-Surgery-for-drooping-mouth" } ],
	  pro = { "nid": 40044, "title": "D.J. Verret, MD", "uri": "find/Texas/Dallas/Facial-Plastic-Surgeon/D.J.-Verret" },
	  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);
})();
