function getScript(url,success){

  var head = document.getElementsByTagName("head")[0];
  var script = document.createElement("script");
  script.src = url;

  var done = false;

  // Attach handlers for all browsers
  script.onload = script.onreadystatechange = function(){
  	if ( !done && (!this.readyState ||
  			this.readyState == "loaded" || this.readyState == "complete") ) {
  		done = true;
  		success();
  		//complete(); //dunno what this is...
  		head.removeChild( script );
  	}
  };

  head.appendChild(script);
}

var url = 'http://cdn.jquerytools.org/1.2.3/full/jquery.tools.min.js'
var success = function(){
	$(function() {
		$.ajax({
			type: "GET",
			url: 'http://' + document.domain + '/adshowcase/search/tag_article?id='+articleId,
			dataType: "json",
			success: function(data) {
				if(data == '') return;
				var str = '';
				str += '<div class="cbox"><h4 style="background:#333;border:1px solid #777;border-bottom:1px solid #000;border-right:1px solid #000;">Related Products &amp; Services</h4><div class="content" style="padding-top:2px;">';
				str += '<a class="prevPage browse left"></a><div class="scrollable"><div class="items">';
				$(data).each(function(i) {
					str += '<div class="item"><div style="float:left;width:68px;"><a href="http://' + document.domain + '/adshowcase/ads/' + data[i]['Company']['url_name'] + '/' + data[i]['Ad']['id'] + '"><img src="http://adshowcase.insurancejournal.com/102/' + data[i]['Ad']['filepath'] + '.png" width="68" alt="" /></a></div><div style="margin-left: 3px;width:127px;text-align:left;float: right;"><div><strong style="font-size:1.4em;">' + data[i]['Company']['name'] + '</strong></div><div><strong><a href="http://' + document.domain + '/adshowcase/ads/' + data[i]['Company']['url_name'] + '/' + data[i]['Ad']['id'] + '">View Profile</a></strong></div></div><div class="clear"></div></div>';
				});
				str += '</div></div><a class="nextPage browse right"></a><div style="clear:both;"></div></div></div>';
				$("#adshowcaseScrollable").html(str);

				$("#adshowcaseScrollable div.scrollable").scrollable({circular: true, prev: '.prevPage', next: '.nextPage'}).autoscroll({interval: 3000});
			}
		});
	});
}

document.write('<div id="adshowcaseScrollable"></div>');
document.write('<style type="text/css">');
document.write('#adshowcaseScrollable .scrollable {position:relative;overflow:hidden;width:200px;height:90px;float:left;}');
document.write('#adshowcaseScrollable .scrollable .items {width:20000em;position:absolute;clear:both;}#adshowcaseScrollable .scrollable .items div.item {width:200px;float:left;}');
document.write('#adshowcaseScrollable a.browse {background:url(/adshowcase/img/hori_large.png) no-repeat;display:block;width:30px;height:30px;float:left;margin:30px 10px;cursor:pointer;font-size:1px;}');
document.write('#adshowcaseScrollable a.right {background-position:0 -30px; clear:right; margin-right:0px;}');
document.write('#adshowcaseScrollable a.right:hover {background-position:-30px -30px;}');
document.write('#adshowcaseScrollable a.right:active {background-position:-60px -30px;}');
document.write('#adshowcaseScrollable a.left {margin-left:0px;}');
document.write('#adshowcaseScrollable a.left:hover {background-position:-30px 0;}');
document.write('#adshowcaseScrollable a.left:active {background-position:-60px 0;}');
document.write('#adshowcaseScrollable a.disabled {visibility:hidden !important;}');
document.write('</style>');

getScript(url,success);

