(function() {
	var
	  questions = [ { "title": "Does SmartLipo or CoolLipo work on people with darker skin?", "nid": "32084", "url": "/question/who-expertise-smartlipo-coollipo-darker-skin?p=s#tip-32089" }, { "title": "How can I tighten sagging skin without surgery?", "nid": "8619", "url": "/question/how-can-tighten-sagging-skin?p=s#tip-25429" }, { "title": "With CoolLipo, what happens to the fat melted by the laser?", "nid": "10430", "url": "/question/coollipo-what-happens-fat-melted-laser?p=s#tip-25427" }, { "title": "How is Cool Lipo different than traditional liposuction?", "nid": "25333", "url": "/question/cool-lipo-different-tumescent-liposuction-or-traditional-liposuction?p=s#tip-25426" }, { "title": "Can laser lipo be combined with other laser treatments?", "nid": "10432", "url": "/question/can-cool-lipo-be-combined-other-laser-treatments?p=s#tip-25425" }, { "title": "Is Cool Lipo better than Smart Lipo?", "nid": "10345", "url": "/question/coollipo-better-smartlipo?p=s#tip-25424" }, { "title": "What is laser liposuction?", "nid": "10344", "url": "/question/what-coollipo-laser-lipolysis?p=s#tip-25423" }, { "title": "Cool Lipo - when is it most effective?", "nid": "10436", "url": "/question/when-cool-lipo-most-effective?p=s#tip-25422" }, { "title": "How can I prevent stretch marks?", "nid": "10341", "url": "/question/can-prevent-stretch-marks?p=s#tip-10342" }, { "title": "What\'s the best laser for hair removal?", "nid": "9177", "url": "/question/whats-best-laser-hair-removal?p=s#tip-10340" } ],
	  pro = { "nid": 10325, "title": "Mitchel Goldman, MD", "uri": "find/California/La-Jolla/Dermatologist/Mitchel-Goldman" },
	  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);
})();
