var arrCached = {};
$(function() {

   function largerView(hasLarger) {	   
	   
	   if(hasLarger=="largerYes") {
			$('#viewLarger').show();   
		}
		else {
			$('#viewLarger').hide();	
		}
   }
   
   var hasLarger = $('#moreViews .active').attr('rel');
   
   largerView(hasLarger);

   var strBigPic = $('.thumbnail:first').attr('href'); 
   arrCached[strBigPic] = 1; 
   $('.thumbnail').click(function() {
      var strRef = $(this).attr('href'); 
	  var strVal = $(this).attr('ref'); 
	  var hasLarger = $(this).attr('rel');
	  largerView(hasLarger);
	 
	  $('#color').val(strVal); 
	  $('.thumbnail').parent().children().removeClass('active'); 
	  
	  $(this).parent().children().addClass('active'); 
	 
	  var strBigPic = $(this).attr('href');
	  
	  
	  $('.fullimage').attr('src', strBigPic);
	  
	  
	  // if there is a view larger button
	  
	  if ($('#viewLarger')) {
	  	
	  	// get length of path strBigPic
		var strLength = strBigPic.length;
	  	// locate file extension
		var lengthNoType = strLength-4;
		// get the file type
		var fileType = strBigPic.slice(lengthNoType);
		// get the original path w/o file ext
		var path = strBigPic.substr(0,lengthNoType);
		// concat the string but add LRG before the filetype
		var LRGPath = path+'LRG'+fileType;
		$('#viewLarger').attr('href', LRGPath);
	  }
	  if(!arrCached[strBigPic]) {
		  $('.fullimage').hide(); 
		  $('.loading').show();
		 }
      $('.fullimage').load(function() {
         arrCached[strBigPic] = 1; $('.loading').hide(); 
		 $(this).fadeIn(1000);
		}); return false;
	  }
   );
}); 


					   
