// inject promotions images into template only if JS is turned on
// - get images from db table: homepage_promo using ajax
// - build unordered list of images

Promotions = {
	
	init: function() {

		// promotions block exist?
		if ($('promotionsBlock')) {

			// get promotions data
			new Request.JSON({
				url: '/ajax/promotions.php',
				onComplete: function(data) {
					if (data) {
						var list = new Element('ul');
						$('promotionsBlock').grab(list);

						data.each(function(element) {
							var imageSrc =  'http://static.routesonline.com/images/cached/promotions-' + element['id'] + '-standard-182x182.jpg';
							var listItem = new Element('li');
							var anchor = new Element('a', {
								href: element['url']
							});
							anchor.grab(new Element('img', {
								src: imageSrc,
								alt: element['description']
							}));
							listItem.grab(anchor);
							// following not required yet
							//listItem.grab(new Element('h2', {html: element['title']}));
							//listItem.grab(new Element('div', {html: element['description']}));
							list.grab(listItem);
						});
						// set up the scroller
						var promotionsScroller = new ContentScroller({slideDuration: 8000});
						promotionsScroller.addSlides($$('div#promotionsBlock li'));
						promotionsScroller.start();
					}
				}
			}).get();
		}
	}


}

window.addEvent('domready', Promotions.init);