// load content from ajax feeds.


function loadCarouselContent() {
	var feed_url = 'http://' + ajax_feed_host + '/ajax_carousel_feed.php';
//	console.log('feed_url: ' + feed_url);
	jQuery.getJSON('http://' + ajax_feed_host + '/ajax_carousel_feed.php?callback=?', function(data) {processCarouselContent(data);} );
}


function processCarouselContent(books) {
	// clear carousels
	jQuery('#new_books_carousel_large').empty();
	jQuery('#new_books_carousel_large').append('<ul>');
	
	jQuery('#new_books_carousel_small').empty();
	jQuery('#new_books_carousel_small').append('<ul>');
	
	if (books.length > 0) {
		for(var i = 0; i < books.length; i++) {
			var currentBook = null;
			books[i].image =books[i].image.replace('book_images_temp', 'book_images'); 
//			console.log(books[i]);
			currentBook = ajaxFeedCreateBookLargeCarouselElement(books[i]);
			jQuery('#new_books_carousel_large ul').append(currentBook);

			currentBook = ajaxFeedCreateBookSmallCarouselElement(books[i]);
			jQuery('#new_books_carousel_small ul').append(currentBook);

		}
	}
	initCarousels();
}


function ajaxFeedCreateBookLargeCarouselElement(book) {
	var bookLi = jQuery('<li>');
	
	jQuery(bookLi).append('<div class="book_image"><img alt="' + book['title'] + '" src="http://' + ajax_feed_host + '/i/book_images/' + book['image'] + '" />');
	jQuery(bookLi).append('<div class="book_copy"><div class="book_title">' + book['title'] + '</div><div class="book_author">' + book['author'] + '</div><div class="book_copy_text"><span class="copy_content">' + book['copy'] + '</span>&nbsp;<a class="book_link" href="' + book['link'] + '">read more</a>');
	
	return bookLi;
}

function ajaxFeedCreateBookSmallCarouselElement(book) {
	var bookLi = jQuery('<li>');
	
	jQuery(bookLi).append('<div class="book_image"><img class="small_carousel_book_image" alt="" src="http://' + ajax_feed_host + '/i/book_images/' + book['image'] + '" />');
	
	return bookLi;
}



function loadTickerContent() {
	var feed_url = 'http://' + ajax_feed_host + '/ajax_ticker_feed.php';
//	console.log('feed_url: ' + feed_url);
	jQuery.getJSON('http://' + ajax_feed_host + '/ajax_ticker_feed.php?callback=?', function(data) {processTickerContent(data);} );
}


function processTickerContent(items) {
	var currentItem;

//	console.log(items);
	jQuery('#hidden_news_ticker').empty();
	if (items.length > 0) {
		for(var i = 0; i < items.length; i++) {
			if (items[i].link != "") {
				currentItem = jQuery('<li><a href="' + items[i].link + '">' + items[i].copy + '</a></li>');
			} else {
				currentItem = jQuery('<li>' + items[i].copy + '</li>');
			}
			jQuery('#hidden_news_ticker').append(currentItem);
		}
	}
	initNewsTicker();
}



