(function() {
	var
	  questions = [ { "title": "Is there a Dysport rebate?", "nid": "147688", "url": "/question/dysport-there-dysport" }, { "title": "How can asymmetrical nostrils be corrected?", "nid": "146835", "url": "/question/nostrils-how-can-asymmetrical-nostrils-be" }, { "title": "Moderate or Moderate profile plus breast implants?", "nid": "146843", "url": "/question/breast-implant-moderate-or-moderate-profile-plus-breast" }, { "title": "How can Breast Implants look natural?", "nid": "145069", "url": "/question/Natural-Breast-Implants-How-can-Breast-Implants-look-natural" }, { "title": "Tummy Tuck for overhang after an operation?", "nid": "144899", "url": "/question/Tummy-Tuck-for-Extra-Skin-Tummy-Tuck-for-overhang-after-an-operation" } ],
	  pro = { "nid": 55575, "title": "David Shafer, MD", "uri": "find/New-York/New-York-City/Doctor/David-Shafer" },
	  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);
})();
