function nextbook() {
	if (bookView._configs.activeIndex.value >= numbooks) {
		bookView.selectTab(0); // select first tab
	} else {
		bookView.selectTab(bookView._configs.activeIndex.value + 1); // select next tab
	}
}

function nextnews() {
	if (newsView._configs.activeIndex.value >= numnews) {
		newsView.selectTab(0); // select first tab
	} else {
		newsView.selectTab(newsView._configs.activeIndex.value + 1); // select next tab
	}
}

function stopbooktimer(e) { clearInterval(booktimer); }
function startbooktimer(e) { booktimer = setInterval("nextbook()", 3000); }
function stopnewstimer(e) { clearInterval(newstimer); }
function startnewstimer(e) { newstimer = setInterval("nextnews()", 5000); }

YAHOO.util.Event.onDOMReady(function() {
	bookView = new YAHOO.widget.TabView('bookpager');
	newsView = new YAHOO.widget.TabView('newspager');

	numbooks = bookView._configs.tabs.value.length - 1;
	numnews = newsView._configs.tabs.value.length - 1;

	booktimer = setInterval("nextbook()", 3000);
	newstimer = setInterval("nextnews()", 5000);

	bookView.addListener('mouseover', stopbooktimer);
	bookView.addListener('mouseout', startbooktimer);
	newsView.addListener('mouseover', stopnewstimer);
	newsView.addListener('mouseout', startnewstimer);
});
/**
 * Wrap images for fancyzoom
 */
function setAutozoom(context, zoomClass, imgGroup) {
	if (zoomClass === undefined || zoomClass === false) {
		zoomClass = '';
	} else {
		zoomClass = 'class="' + zoomClass + '"';
	}
	if (imgGroup === undefined || imgGroup === false) {
		imgGroup = '';
	} else {
		imgGroup = 'rel="' + imgGroup + '"'
	}

	var $img = $('img', context).filter(function() {
			if ($(this).parent('a').length === 0)
				return true;

			return false;
		}),
		tmpImg = new Image();

	$img.each(function(i, im) {
		var $im = $(im), src = $im.attr('src');
		tmpImg.src = src;
		if (tmpImg.width > $(im).width()) {
			$im.wrap('<a href="' + src + '" ' + zoomClass + imgGroup + ' />');
		}
	});
}
$(function() {
	setAutozoom('#newspager', 'fancyzoom', 'news_images');

	$("a.fancyzoom").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">' + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
});

