/*
 *  $Id$
 */
(function($){  
	$.fn.thumbSize = function(imagedir, defaultThumbsize) {
		// $(this) is the html element 
		var currSize = defaultThumbsize;
											
		// restore cookie
		storedSize = getCookie('thumb_size');
		if (storedSize!=null){			
			currSize = setThumbsize(this, storedSize); // update layout									
		}else{			
			currSize = setThumbsize(this, currSize);
		}		
		$(this).live('click',function(event){			
			event.preventDefault();
			currSize = setThumbsize(this, this.rel);	
		});
	
		function setThumbsize(element, size) {
			currSize = size;
			$("input[name=thumb_size]").val(size);
			$(".cam_element").removeClass('small mid big');
			$(".cam_element_size").removeClass('picsmall picmid picbig');
			$(".cam_overlay").removeClass('overlaysmall overlaymid overlaybig');
												
			$(".cam_element").addClass(size);
			$(".cam_element_size").addClass('pic'+size);
			$(".cam_overlay").addClass('overlay'+size);
			
			setCookie('thumb_size', size);
			
			// reset all items
			$(".thumbsize a").each(function() {
				$("img", this).attr("src",imagedir+"icon_" + $(this).attr('rel') + ".jpg");
			});
			
			// mark the new selection		
			$(element).each(function() {
				if ($(this).attr('rel') == size)
					$("img", this).attr("src",imagedir+"icon_"+size+"_active.jpg");
			});
	
			return size;
		} 			  
	};
})(jQuery);	

