var timeId;
var profileIndex = 0;
var profilePauseTime = 6500;
var scrollerSlideOffset = 179;
var scrollerSlideSpeed = 700;
var scrollerCanClick = true;


jQuery(document).ready(function(){

	home_scroller_checkButtons();

	/* Client Box Controller */
	$('#ClientScroller .ScrollRight').click(
		function(){
			// Add one from the end
			if(scrollerCanClick&&!$(this).hasClass('Disabled')){
				scrollerCanClick = false;
				var newLeft = parseInt($('#ClientScroller .Inner ul').css('left')) - scrollerSlideOffset;
				$('#ClientScroller .Inner ul').animate({left: newLeft}, scrollerSlideSpeed, 'linear',
					function(){
						scrollerCanClick = true;
						home_scroller_checkButtons();
					}
				);
			}
			
		}
	);
	
	$('#ClientScroller .ScrollLeft').click(
		function(){
		
			if(scrollerCanClick&&!$(this).hasClass('Disabled')){
				scrollerCanClick = false;
				var newLeft = parseInt($('#ClientScroller .Inner ul').css('left')) + scrollerSlideOffset;
				$('#ClientScroller .Inner ul').animate({left: newLeft}, scrollerSlideSpeed, 'linear',
					function(){
						scrollerCanClick = true;
						home_scroller_checkButtons();
					
					}
				);
			}
		
		}   
	);
	
	
	/* Partner Profiles */
	$('#PartnerProfiles ul li').not('#PartnerProfiles ul li:lt(1)').hide();
	$('#PartnerProfiles').hover(
		function(){
			clearTimeout(timeId);
		},
		function(){
			clearTimeout(timeId);
			timeId = setTimeout(home_nextProfile, profilePauseTime);
		}
								
	);
	timeId = setTimeout(home_nextProfile, profilePauseTime);
	
	colHeights();
	/* Set Column Heights */
	//home_setCols();
	
	
});

function home_scroller_checkButtons(){
	var leftPos = parseInt($('#ClientScroller .Inner ul').css('left'));
	var scrollerWidth = $('#ClientScroller .Inner').width();
	scrollerWidth *= -1;
	if(leftPos + scrollerSlideOffset > 0){
		$('#ClientScroller .ScrollLeft').addClass('Disabled');
	}else{
		$('#ClientScroller .ScrollLeft').removeClass('Disabled');
	}
	if(leftPos <  scrollerWidth){
		$('#ClientScroller .ScrollRight').addClass('Disabled');
	}else{
		$('#ClientScroller .ScrollRight').removeClass('Disabled');
	}
}

function home_nextProfile(){
	$('#PartnerProfiles ul li:eq(' + profileIndex + ')').slideUp('slow',function(){
			profileIndex++;
			if(profileIndex > $('#PartnerProfiles ul li').length -1){
				profileIndex = 0;	
			}
			$('#PartnerProfiles ul li:eq(' + profileIndex + ')').slideDown('slow',function(){clearTimeout(timeId), timeId = setTimeout(home_nextProfile, profilePauseTime)});
	});

}