// scrollable plugin - home marquee

(function($) {
	$(document).ready(function() {
		var root = $("#pagination").tabs(".slides_container > div", {

			// enable "cross-fading" effect
			effect: 'fade',
			fadeInSpeed: 1000,
			fadeOutSpeed: 500,
			// event: 'mouseover',
			onBeforeClick: function(event, tabIndex) {
				//console.log(this.getTabs());
				this.getTabs().find('.action').show(); //shows all .action buttons
				if(tabIndex === 0) {
					$('#pagination li.marquee-1').find('.action').hide();
					//console.log('less');
				} else {
					this.getCurrentTab().next().find('.action').hide(); //hides current tabs .action button
				}
			},
			
			// start from the beginning after the last tab
			rotate: true

		// use the slideshow plugin. It accepts its own configuration
		}).slideshow({autoplay:true, autopause: false, interval: 8000, clickable: false,});
		
		var api = root.data('slideshow');
		$('.backward, .forward').hover(api.pause, api.play);
		
		//truncation
		/*
			Truncation happens on the word.  If max_length is set to an index that lands in the middle of the word,
			it will truncate to the end of the previous word.
		*/
		$('#pagination .marquee-desc a, #pagination .marquee-desc p').each( function() {
			if($(this).is('p')) {
				var max_length = 50;
			} else {
				var max_length = 38;
			}
			
			if($(this).text().length > max_length) {
				//$(this).text($(this).text().substr(0,max_length-3)).append('...');
				$(this).text($(this).text().substr(0,$(this).text().lastIndexOf(' ', max_length - 3))).append('...');
			}
		});
		
		// enable links within tabs (scrollable prevents links in tabs to be clicked)
		$('#pagination li a').click(function(e) {
			e.stopPropagation();
		});
		
	});	
})(jQuery142);

