jQuery(function() {
  jQuery('#patternContent a').click(function() {
	var name = jQuery(this).children('img').attr("alt");
	jQuery('.nextImage').removeClass();
	jQuery('#main_image').addClass('firstImage');
	jQuery(this).blur();
	var new_image = "<?php bloginfo('stylesheet_directory'); ?>/images/" + name + ".jpg";
	//alert(new_image);
	jQuery('#header').focus();
	jQuery('#main_image_holder').append('<img class="nextImage" src="/wp-content/themes/aimeewilder/images/' + name + '.jpg" alt="' + name + '" id="main_image"/>');
	/*
	jQuery('.firstImage').fadeOut('5000');
	jQuery('.nextImage').fadeIn('3000', function() {
		jQuery('.firstImage').remove();
	});
	*/
	jQuery('#homeLink').focus().blur();
	jQuery('.firstImage').fadeOut('3000', function() {
	jQuery('.nextImage').fadeIn('3000');
	jQuery('.firstImage').remove();
	});
	return false;
  });
  jQuery('.thumbnail:gt(31)').hide();
  jQuery('#arrowRight').click(function() {
  //alert('right!');
  	var current = jQuery('#arrowHolder .current').text();
  	current = parseInt(current);
  	if ((current + 32) < jQuery('.thumbnail').length)
  	{
  	count = 0;
  	jQuery('.thumbnail:visible').each(function() {
  		if (count < 8)
  		{
  			jQuery(this).fadeOut();
  		}
  		count++;
  	});
  	var new_row = current + 8;
  	//alert(new_row);
  	jQuery('#arrowHolder .current').text(new_row)
  	var count = 0;
  	jQuery('.thumbnail:hidden').each(function() {
  		if ((count >= current) && (count < (current + 8)))
  		{
  			jQuery(this).fadeIn();
  		}
  		count++;
   	});
   	}
   	jQuery(this).blur();
   	return false;
  });
  jQuery('#arrowLeft').click(function() {
  //alert('left');
  	var current = jQuery('#arrowHolder .current').text();
  	current = parseInt(current);
  	if ((current - 8) >= 0)
  	{
  	count = 0;
  	jQuery('.thumbnail:visible').each(function() {
  		if (count > 23)
  		{
  			jQuery(this).fadeOut();
  		}
  		count++;
  	});
  	var new_row = current - 8;
  	//alert(new_row);
  	jQuery('#arrowHolder .current').text(new_row)
  	var count = 0;
  	jQuery('.thumbnail:hidden').each(function() {
  		if ((count < current) && (count >= (current - 8)))
  		{
  			jQuery(this).fadeIn();
  		}
  		count++;
   	});
   	}
   	jQuery(this).blur();
   	return false;
  });
});