(function(){
	function mycarousel_itemLoadCallback(carousel, state) {
		if (state != 'init') return;	
		jQuery.get('/content/includes/www/xml_shuttle/author_books.xml', function(data) { mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, data); });
	}
	
	function mycarousel_itemAddCallback(carousel, first, last, data) {
		var items = 0;
			
		jQuery('item',data).each(function(i){			
			carousel.add(i+1, mycarousel_getItemHTML(jQuery(this)));
			items += 1;
		});
	
		carousel.size(items);
		
		var ind='', pagination = Math.ceil(carousel.size() / carousel.options.scroll);
	
		for (var i = 0; i < pagination; i++) { ind += '<div id="indicator_' + i + '" class="indicator" />'; }
		jQuery('#abIndicatorBar').html(ind);
		jQuery('#abIndicatorBar div').each(function(i){
			jQuery(this).click(function(){
				jQuery('#abIndicatorBar div').removeClass().addClass('indicator');
				jQuery(this).removeClass().addClass('indicator_active');			
				carousel.scroll(jQuery.jcarousel.intval(carousel.options.scroll * i + 1));
			});
		});
		
		mycarousel_firstIn(carousel);
	}
	
	function mycarousel_firstIn(carousel) {	
		jQuery('#abIndicatorBar div').removeClass().addClass('indicator');
		jQuery('#indicator_' + (Math.ceil( carousel.last / carousel.options.scroll ) - 1)).removeClass().addClass('indicator_active'); 
	}
	
	/*** Item html creation helper. */
	function mycarousel_getItemHTML(data)
	{
		var imagePath = data.find('imagePath').text(), headline = data.find('headline').text(), link = data.find('link').text(), blurb = data.find('blurb').text();
		return '<a href="' + link + '"><img src="' + imagePath + '" width="100" height="110" alt="" border="0" /></a><br /><a href="' + link + '"><strong>' + headline + '</strong></a>' + '<br /><span>' + blurb + '</span>';
	}
	
	jQuery('#mycarousel').jcarousel({
		scroll: 3,
	    itemLoadCallback: mycarousel_itemLoadCallback,
		itemFirstInCallback: mycarousel_firstIn
	});
	
	jQuery('#abnewsl,#subquery,#TBWExchangeHomeSearch_Ntt').bind('focus',function() { if( this.value == this.defaultValue ) this.value = ''; });
	jQuery('#abnewsl,#subquery,#TBWExchangeHomeSearch_Ntt').bind('blur',function() { if( this.value == '' ) this.value = this.defaultValue; });

})();