$(document).ready(function(){
	$('#slideshow li:not(li:last) img').fadeTo(0, 0.7);
	window.slideshow_timer = setInterval("$('#slideshow li:first').next().trigger('click')" , 7500);
	window.slideshow_flag = false;

	$('#slideshow_mask_right').click(function(){
			$('#slideshow li:first').trigger('click');
	}).hover(function(){
			$('#slideshow li:first').trigger('mouseenter');
	},function(){
			$('#slideshow li:first').trigger('mouseleave');
	});

	$('#slideshow li').click(function(){
			if ($(this).hasClass('clickable') && window.slideshow_flag == false) {

					clearInterval(window.slideshow_timer);
					window.slideshow_flag = true;
					var slides = $(this).nextUntil('ul');

					$('#slideshow li').css({width: '106px'});
					$('#slideshow li span').removeClass('active');
					$('#slideshow li').addClass('clickable');

					$(this).find('span').hide();
					$(this).find('img').fadeTo(0, 1.0);
					$(this).removeClass('clickable').animate({width: '659px'}, 1200, function(){
							$(this).find('span').addClass('active').show(0, function(){
									window.slideshow_flag = false;
									window.slideshow_timer = setInterval("$('#slideshow li:first').next().trigger('click')" , 7500);
							});
					});

					$('#slideshow ul').css({right: '-108px'}).animate({right: 0}, 1000,'linear');

					$(this).parent().prepend(slides);
					$('#slideshow li:not(li:last) img').fadeTo(0, 0.7);
			}
	});

	$('#slideshow li').mouseenter(function(){
			$(this).find('img').stop().fadeTo(500, 1.0);
	}).mouseleave(function(){
			if (!$(this).is('li:last-child')) {
					$(this).find('img').stop().fadeTo(500, 0.7);
			}
	});

	window.featuredclients_timer = setInterval("clientSlideshow()" , 4500);
	window.featuredclients_flag = false;

});

function clientSlideshow() {
	if (!window.featuredclients_flag) {
		clearInterval(window.featuredclients_timer);
		window.featuredclients_flag = true;

		$('#featured_clients_slideshow li:last').fadeOut(750, function(){
			$(this).parent().prepend(this);
			$('#featured_clients_slideshow li').show();
			window.featuredclients_flag = false;
			window.featuredclients_timer = setInterval("clientSlideshow()" , 4500);
		});
	}
}
