var $CrCh = jQuery.noConflict();

$CrCh(document).ready(function(){

	var disp = $CrCh.cookie('swap_cookie'),
	cState = null;

	$CrCh("a.switch_thumb").click(function(){
		
		cState = $CrCh.cookie('swap_cookie');
		
		if( cState === 'display' ) {
			
			swapView('thumb');
			
		} else {
			
			swapView('display');	
		}
		
		return false;
	  
	});
	
	
	var swapView = function( disp ) {
		
		var a = $CrCh("a.switch_thumb"),
		ul = $CrCh("ul.display");
		
		if( disp === 'thumb' ) {
			
			a.addClass("swap"); 
			ul.fadeOut("fast", function() {

				$CrCh(this).fadeIn("fast").addClass("thumb_view"); 
			});
			$CrCh.cookie('swap_cookie', 'thumb', { path: '/', expires: 99} );
			
		} else if( disp === 'display' || disp == null ) {
				
			if( cState !== disp || cState !== null) {
				a.removeClass("swap");
				ul.fadeOut("fast", function() {
											
					$CrCh(this).fadeIn("fast").removeClass("thumb_view");
				});
			}
			$CrCh.cookie('swap_cookie', 'display', { path: '/', expires: 99} );
			
		}  
	} // eo swapView

	swapView( disp );
});

