$(document).ready(function(){

	$('a.slideClick').click(function(e){
		var id = parseInt($(this).attr('href').replace('#', ''));
		// move the slider
		moveTo = parseInt(percent_per_user * (id-1) + (percent_per_user/2) );
		
		if(id==1){ moveTo = 0 }
		if(id==totalPoints){ moveTo = 100 }
		
		 $( "#slider" ).slider('value', moveTo );
	//	 alert(parseInt(percent_per_user * id) - (percent_per_user/2));
		// do the sliderSlide
		sliderSlide(id);
		e.preventDefault();
	});

  //$('a.lbox').lightBox();
  $("a.cbox").colorbox();



  // a-zs
  $('.alpha-filter').bind('click', function(e){
    var href = $(this).attr('href');    
    var Links = $('#alphafilters a.active');                
    Cufon.replace(Links, {
      color: '#fbe505'            
    });       
    var Links = $('#alphafilters.small a.active');                
    Cufon.replace(Links, {
      color: '#7ac144'            
    });   
     
    $('#alphafilters a.active').removeClass('active');
    $(this).addClass('active');
    
    $('.alphafiltered').hide().removeClass('active');    
    $(href).addClass('active').show();
                
		e.preventDefault();    
  });


});


function handleSliderSlide(e, ui)
{
	var lollyChosen = ui.value;
	//sliderSlide(lollyChosen);
}

function sliderSlide(lollyChosen){
	var imageWidth = 145;
	var resizedWidth = 155;
	var lollyWidth = 150;
	var scrollLeft = (lollyChosen * lollyWidth) - lollyWidth;
	
	// resize the currently-active;
	
	
	scrollLeft = scrollLeft - (lollyWidth * 2);
	
	//$('#amount').html(lollyChosen + ' - ' + scrollLeft);
	
	if(scrollLeft < 0){
		scrollLeft = 0;	
	}
	
  //$("#content-scroll").attr({scrollLeft: (scrollLeft) });  
  //$("#content-scroll").stop().animate({scrollLeft: (scrollLeft) }, 1000);
  
  $('.content-slider-image.current').each(function(){
    //$(this).stop().effect("scale", { percent: 95 }, 1000);
    //$(this).animate(width(145);
    $(this).stop().animate({width: imageWidth }, 1000);
    $(this).removeClass('current');
  });
  
  // largen!
  //$('.content-slider-image-'+lollyChosen).stop().effect("scale", { percent: 105 }, 1000);
  $('.content-slider-image-'+lollyChosen).stop().animate({width: resizedWidth }, 1000);

  // add large class
  $('.content-slider-image-'+lollyChosen).addClass('current');
  
  // swap the text out
  $('.staff-words').each(function(){
  	$(this).addClass('staff-words-hidden');
  });
  $('#staff-words-'+lollyChosen).removeClass('staff-words-hidden');

  
  // replace their content.
  $('.staff-content').each(function(){
  	$(this).addClass('staff-hidden');
  });
  $('#staff-'+lollyChosen).removeClass('staff-hidden');
  
}

function initialSliderChange(pos)
{
  var maxScroll = $("#content-scroll").attr("scrollWidth") - $("#content-scroll").width();
  $("#content-scroll").animate({scrollLeft: pos * (maxScroll / 100) }, 1000);
}

function handleSliderChange(e, ui)
{
  var maxScroll = $("#content-scroll").attr("scrollWidth") - $("#content-scroll").width();
  $("#content-scroll").animate({scrollLeft: ui.value * (maxScroll / 100) }, 1000);
}


function handleSliderSlide(e, ui)
{
  var maxScroll = $("#content-scroll").attr("scrollWidth") - $("#content-scroll").width();
  $("#content-scroll").attr({scrollLeft: ui.value * (maxScroll / 100) });
}

