var slideshow2 = function(selector){
	var cur = this;
	var mainContainer = $('.jquery-slideshow');
	if(selector != null && selector != 'undefined'){
		mainContainer = $(selector);
	}
	var largeImgCnt = mainContainer.parent().find('.large-img-cnt');
	var innerContainer = mainContainer.find('.thumb-container');
	var list = innerContainer.find('.thumb-list');
	var items = list.find('li');
	var size = list.find('li').length;
	var buttonsWidth = 50;
	var buttonsHeight = 8;
	var buttonTop = base+'images/ssarrowt.png';
	var buttonSpacingTop = 5;
	var buttonBottom = base+'images/ssarrowb.png';
	var buttonSpacingBottom = 5;
	var totHeight = 0;
	this.stop = false;
	var initCallback = enlargethumb4slide;
	
	var x;
	var maxX;
	var wpi;
	var hpi;
	
	tlcounter = 0;
	this.init = function(){
		if(items.size() > 0){


			totHeight = size*57;
			list.height(totHeight);
			
			list.css('top', '0px');
			maxX = list.height()-innerContainer.height();				
			var tb = $('<div style="width:'+52+'px;line-height:10px;" class="anim-button anim-top"><img width="'+buttonsWidth+'px" height="'+buttonsHeight+'px" src="'+buttonTop+'" /></div>');
			tb.insertBefore(innerContainer);
			var bb = $('<div style="width:'+52+'px;line-height:10px;" class="anim-button anim-bottom"><img width="'+buttonsWidth+'px" height="'+buttonsHeight+'px" src="'+buttonBottom+'" /></div>');
			bb.insertAfter(innerContainer);
		
			tb.click(function(){ list.stop(); cur.stepRight(); });
			tb.mouseenter(function(){ cur.stop=false; cur.animateRight(); });
			tb.mouseleave(function(){ cur.stop=true;  });
			bb.click(function(){ list.stop(); cur.stepLeft(); });
			bb.mouseenter(function(){ cur.stop=false; cur.animateLeft(); });
			bb.mouseleave(function(){ cur.stop=true;  });
			$(items).each(function(){
				var myc = $(this).find('.thumb').wrap($('<li class=""></li>')).parent();
				$(this).find('.enlarged').appendTo(myc);
				myc = myc.appendTo(largeImgCnt);
				
				//var E = new enlarge(myc);
				//if(lastE != null){
				//	lastE.setNext(E);
				//	E.setPrev(lastE);
				//}
				//lastE = E;
				
			});
			$(items).click(function(){
				var i = items.index(this);
				$(largeImgCnt).find('li').removeClass('active');
				$(largeImgCnt).find('li').eq(i).addClass('active');
				
			});
			$(items).eq(0).click();
			//if(initCallback != null){
			//	initCallback(list);
			//}
		}

	}
	
	this.animateLeft = function(){
		if(parseInt(list.css('top').replace('px', '')) != -(maxX)){
			$(list).css('top', (parseInt(list.css('top').replace('px', ''))-3)+'px');
			if(cur.stop == false && (parseInt(list.css('top').replace('px', ''))-3) > -(maxX)){
				setTimeout(function(){ cur.animateLeft(); }, 10);
			}
			else if(cur.stop == false){
				setTimeout(function(){ $(list).css('top', -(maxX)+'px'); }, 10);
			}
		}
	}
	
	this.animateRight = function(){
		if(parseInt(list.css('top').replace('px', '')) != 0){
			$(list).css('top', (parseInt(list.css('top').replace('px', ''))+3)+'px');
			if(cur.stop == false && (parseInt(list.css('top').replace('px', ''))+3) < 0){
				setTimeout(function(){ cur.animateRight(); }, 10);
			}
			else if(cur.stop == false ){
				setTimeout(function(){ $(list).css('top',0+'px'); }, 10);
			}				
		}				
	}
	
	this.stepLeft = function(){	
		var ntm = this.getNtm();
		if((parseInt(list.css('top').replace('px', '')) - (ntm*wpi)) > -(maxX)){
			list.animate({
				top: parseInt(list.css('top').replace('px', '')) - (ntm*wpi)
			}, 500);
		}
		else{
			setTimeout(function(){ $(list).css('top', -(maxX)+'px'); }, 10);
		}
	}
	
	this.stepRight = function(){
		var ntm = this.getNtm();
		if((parseInt(list.css('top').replace('px', '')) + (ntm*wpi)) < 0){
			list.animate({
				top: parseInt(list.css('top').replace('px', '')) + (ntm*wpi)
			}, 500);
		}
		else{
			setTimeout(function(){ $(list).css('top', '0px'); }, 10);
		}
	}

	this.getNtm = function(){
		var ntm;
		if(size >= Math.round(innerContainer.height()/hpi)){
			ntm = Math.round((innerContainer.height()/hpi)/2);
		}
		else{
			ntm = size;
		}					
		var curmod = Math.abs((parseInt(list.css('top').replace('px', ''))%wpi));
		if(curmod > wpi/2){
			ntm++;
		}
		return ntm;
	}
	this.init();
}
