// JavaScript Document

var CURRENT_ITEM = 0;
var SLIDER_ID;

slideToImage = function(direction)
{
	clearInterval(SLIDER_ID);
	if (direction == 'previous') {
		var nextItem = CURRENT_ITEM - 1
		if (nextItem < 0) { nextItem = $('.slideritem').length - 1; };
	};
	if (direction == 'next') {
		var nextItem = CURRENT_ITEM + 1;
		if (nextItem > ($('.slideritem').length - 1)) { nextItem = 0; };
	};
	$('#slidercontainer').scrollTo( $('.slideritem:eq('+nextItem+')'), 'slow' );
	CURRENT_ITEM = nextItem;
	SLIDER_ID = setInterval(function() { slideToImage('next'); }, 3000);
};

$(document).ready(function() {
	$('.sliderscr').hide();
	var totalWidth = $('.slideritem').length * 485;
	$('#sliderinternal').css({'width': totalWidth+'px'});
	$('.slideritem').hover(function() {
		clearInterval(SLIDER_ID);
		$(this).children().eq(1).children().stop(true, true);
		$(this).children().eq(1).children().fadeIn();
	},
	function() {
		$(this).children().eq(1).children().stop(true, true);
		$(this).children().eq(1).children().fadeOut();
		SLIDER_ID = setInterval(function() { slideToImage('next'); }, 3000);
	});
/*	$('#leftarrow img, #rightarrow img').css({'opacity': '0.7'}).hover(function() {
		$(this).animate({'opacity': '1.0'}, 300);
	},
	function() {
		$(this).animate({'opacity': '0.7'}, 300);
	});*/
	$('#leftarrow img').click(function() {
		slideToImage('previous');
	});
	$('#rightarrow img').click(function() {
		slideToImage('next');
	});
	SLIDER_ID = setInterval(function() { slideToImage('next'); }, 3000);
});