// CONTENTS ====================================================================
/*
- DEFAULT 							- common code that runs on every page.
- ROTATOR 							- manages the image rotator in the sidebar
*/

// VARS --------------------------------------------------------------
var current = -1;	// currently visible rotator item

// DEFAULT --------------------------------------------------------------
function InitDefault(){
	
	// call other Init functions
	
	
}

function InitNav() {
	// add js to make the nav work in IE6
	if (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6) {
		// force widths on sub nav
		$('#main-nav li').each(function(){
			$(this).children('ul').width( $(this).width() );
		});
		// attach hover
		$('#main-nav li').hover(function(){
			$(this).addClass('hover');
		}, function(){
			$(this).removeClass('hover');
		})
	}
}

// ROTATOR --------------------------------------------------------------

function InitRotator() {
	$('#previous-image').hide();
	$('#next-image').click(NextImage);
	$('#previous-image').click(PreviousImage);
	$('#rotator li a').colorbox({transition:'fade', speed:500});
	NextImage();
}

function NextImage() {

	// hide old
	var item = $('#rotator li')[current];
	$(item).animate({left: -302}, {duration: 1000});
	// update current
	current ++;
	if (current == $('#rotator li').length) current = 0;

	CheckRotatorLinks();	
	
	// show new
	item = $('#rotator li')[current];
	$(item).css("left", 310);
	$(item).animate({ left: 0 }, { duration: 1000 });

	
	return false;
}

function PreviousImage() {

	// hide old
	var item = $('#rotator li')[current];
	$(item).animate({ left: 310 }, { duration: 1000 });
	// update current
	current--;
	
	if (current == -1) current = ($('#rotator li').length-1);

	CheckRotatorLinks();
		
	// show new
	item = $('#rotator li')[current];
	$(item).css("left", -302);
	$(item).animate({ left: 0 }, { duration: 1000 });
	
	return false;
}

function CheckRotatorLinks() {
	if (current == ($('#rotator li').length - 1)) {
		$('#next-image').hide();
	}
	else {
		$('#next-image').show();
	}

	if (current == 0) {
		$('#previous-image').hide();
	}
	else {
		$('#previous-image').show();
	}	
}

// ======================================================================
