﻿function InitializeRotator(placementname, containerid, templateid, targetid) 
{
	$.ajax({
		dataType: "json",
		url: "/services/content.svc/GetAdsByPlacementName?$format=json&placementname='" + placementname + "'",
		success: function (data) {
			var ad = data.d; 			 // Get the movies array from the data

			$('.' + placementname).empty(); 		 // Remove current set of movie template items

			$("#" + templateid).tmpl(ad) // Render the template with the movies data
						.appendTo('#' + targetid); 	 // and insert the rendered HTML under the "movieList" element

			var renderAsRotator = data.d.length > 1;

			if (renderAsRotator) {
				$("#" + targetid).jshowoff({ speed: 4000, links: true, effect: 'fade', changeSpeed: 200, controls: true, animatePause: false});
			}

			if (data.d.length > 0) {
				$("#" + containerid).show();
			}
		}
	});
}
