$(document).ready(function() {
	
	var total_logos_width = 0;
	var width_array = new Array();
	var max_left = 0;
	var left_index = 0;
	var outer_container_width = 0;
	var current_left = 0;
	var index = 0;
	
	//find out the total width
	$('.logo_scroller img').load(function() {
		// need to do it this as Chrome sometimes triggers document.ready before it's ready
		current_img_width = $(this).innerWidth();
		width_array[index] = current_img_width;
		total_logos_width = total_logos_width + current_img_width;
		index++;
	});
	// note: not setting the width of .logo_scroller as it seems fine without
	outer_container_width = $('.scroling_logo_container').innerWidth();
	max_left = total_logos_width - outer_container_width;	
	
	/*
	$('.logo_scroller img').each(function(index) {
		current_img_width = $(this).innerWidth();
		width_array[index] = current_img_width;
		total_logos_width = total_logos_width + current_img_width;
	});
	
	//set the withd of the scrolling container
	$('.logo_scroller').css('width', total_logos_width+"px");
	outer_container_width = $('.scroling_logo_container').innerWidth();
	max_left = total_logos_width - outer_container_width;
	left = $('.scroling_logo_container').scrollLeft();
	*/
	
	$('.home_left_arrow img').click(function() {
		if(left_index > 0){
			$('.scroling_logo_container').animate({scrollLeft: '-=' + width_array[left_index] + 'px'}, 1000, 'easeInOutBack');
			left_index--;
			//left = $('.scroling_logo_container').scrollLeft();
			//$('.qsearch').html('LEFT INDEX: '+left_index+'<br/>SCROLL LEFT'+left+'<br/>IMAGE WIDTH: '+width_array[left_index]);
		}else{
			//alert('no more');
			//left = $('.scroling_logo_container').scrollLeft();
			//$('.qsearch').html('LEFT INDEX: '+left_index+'<br/>SCROLL LEFT'+left+'<br/>IMAGE WIDTH: '+width_array[left_index]);
		}
		
	});
	
	$('.home_right_arrow img').click(function() {
		left = $('.scroling_logo_container').scrollLeft();
		if(max_left != left){
			$('.scroling_logo_container').animate({scrollLeft: '+=' + width_array[left_index] + 'px'}, 1000, 'easeInOutBack');
			left_index++;
			
			//$('.qsearch').html('LEFT INDEX: '+left_index+'<br/>SCROLL LEFT'+left+'<br/>IMAGE WIDTH: '+width_array[left_index]);
		}else{
			//alert('no more');
			//$('.qsearch').html('LEFT INDEX: '+left_index+'<br/>SCROLL LEFT'+left+'<br/>IMAGE WIDTH: '+width_array[left_index]);
		}
	});
	
});

