(function($) {
	$.fn.imageScript = function(options){
		// default configuration properties
		var defaults = {			
			speed: 800,
			thumbID: 'thumbID'
		}; 
		
		var options = $.extend(defaults, options); 
		
		this.each(function(){
			var obj = $(this);
			var tobj = $('#'+ options.thumbID);
			var total = $("img", obj).length;
			var w = $("li", obj).width;
			var h = $("li", obj).height;
			
			var i = 0;
			
			var currentID = $("li:first", obj).attr('id');
			
			$("li", obj).css({
				"position": 'absolute',
				"display": "none",
				"opacity": 0,
				"left": 0,
				"top": 0,
				"z-index": 1
			});

			$("li:first", obj).css({
				"opacity": 1,
				"display": "block"
			});
			$("li:first", tobj).addClass('t_up');
			tobj.find('li').css('position','relative');
			
			$("img:first", tobj).addClass('current').css({
				"position": "relative",
				"top": -10
			});
			
			$('#'+options.thumbID).find("img").css("position","relative").click(function(){
				var imgid = $(this).attr("rel");
				showImage(imgid);							   
			});
			
			function showImage(id){
				if(id != currentID){
					var img1w = $('#'+id+' img').width();
					var img2w = $('#'+currentID+' img').width();
					
					$('#'+currentID).css("z-index","1");
					
					$('#'+id).css({
						"display": "block",
						"z-index": 2
					});
					
					tobj.find('img').removeClass();
					$('#thumb'+id).addClass('current');
					
					if(img1w != img2w){
						$('#'+currentID).stop().animate({
							'opacity': 0						 
						},options.speed);
					}
					
					$('#'+id, obj).stop().animate({
						'opacity': 1			 
					},options.speed,function(){
						$('#'+currentID, obj).css("opacity",0);
						currentID = id;
					});
					
					tobj.find('img').css("top",0);
					$('#thumb'+id).stop().animate({
						"top": -10				   
					},100);
				}
			}
		});
	}
})(jQuery);
