SlideViewer = function(wrapperId, targetId, prevImgId, nextImgId, direction, viewPixel){
	this.target = YAHOO.util.Dom.get(targetId);
	this.wrapper = YAHOO.util.Dom.get(wrapperId);
	this.windowPixel = 0;
	
	YAHOO.util.Event.addListener(this.target, "resize", this.init, this, true);
	
	this.direction;
	if (direction){
		this.direction = direction;
	}else{
		this.direction = 'HORIZONTAL';
	}
	
	this.viewPixel = viewPixel;
	
	if (this.direction == 'HORIZONTAL'){
		this.windowPixel = parseInt(this.wrapper.clientWidth);
	}else{
		this.windowPixel = parseInt(this.wrapper.clientHeight);
	}
	
	if (!this.viewPixel){
		this.viewPixel = this.windowPixel;
	}
	
	this.nextPixel = 0;
	this.prevPixel = 0;
	this.totalPixel = 0;
	this.prevImg = YAHOO.util.Dom.get(prevImgId);
	this.nextImg = YAHOO.util.Dom.get(nextImgId);
	this.prevImg.style.cursor = 'pointer';
	this.nextImg.style.cursor = 'pointer';
	this.prevImgComplete, this.nextImgComplete;
	
	if (this.prevImg.onclick){
		this.prevImgComplete = this.prevImg.onclick;
		this.prevImg.onclick = null;
	}
	
	if (this.nextImg.onclick){
		this.nextImgComplete = this.nextImg.onclick;
		this.nextImg.onclick = null;
	}
	
	YAHOO.util.Event.addListener(this.prevImg, 'click', this.movePrev, this, true);
	YAHOO.util.Event.addListener(this.nextImg, 'click', this.moveNext, this, true);
	
	if ((this.direction == 'HORIZONTAL' && this.target.offsetWidth == 0) ||
		(this.direction == 'VERTICAL' && this.target.offsetHeight == 0)){
		YAHOO.util.Event.addListener(window, 'load', this.init, this, true);
	}else{
		this.init();
	}
	
	this.handling = false;
}

SlideViewer.prototype.moveNext = function(){
	if (this.handling) return;
	this.handling = true;
	var anim;
	if (this.direction == 'HORIZONTAL'){
		anim = new YAHOO.util.Motion(this.target.id, { left: { to: (this.nextPixel) } }, 0.3);
	}else{
		anim = new YAHOO.util.Motion(this.target.id, { top: { to: (this.nextPixel) } }, 0.3);
	}
	anim.onComplete.subscribe(this.caculatePixel, this, true);
	if (this.nextImgComplete){
		anim.onComplete.subscribe(this.nextImgComplete);
	}
	anim.animate();
}

SlideViewer.prototype.movePrev = function(){
	if (this.handling) return;
	this.handling = true;
	var anim;
	if (this.direction == 'HORIZONTAL'){
		anim = new YAHOO.util.Motion(this.target.id, { left: { to: (this.prevPixel) } }, 0.3);
	}else{
		anim = new YAHOO.util.Motion(this.target.id, { top: { to: (this.prevPixel) } }, 0.3);
	}
	anim.onComplete.subscribe(this.caculatePixel, this, true);
	if (this.prevImgComplete){
		anim.onComplete.subscribe(this.prevImgComplete);
	}
	anim.animate();
}

SlideViewer.prototype.init = function(){
	if (this.direction == 'HORIZONTAL'){
		this.totalPixel = this.target.offsetWidth;
	}else{
		this.totalPixel = this.target.offsetHeight;
	}
	var movePixel = this.totalPixel - this.windowPixel;
	
	if (movePixel >= this.viewPixel){
		this.nextPixel = this.viewPixel * -1;
	}else if(movePixel > 0){
		this.nextPixel = movePixel * -1;
	}else{
		this.nextPixel = 0;
	}
	
	//this.prevImg.style.display = 'none';
	
	//if (this.nextPixel == 0) this.nextImg.style.display = 'none';
	//else this.nextImg.style.display = 'inline';
}

SlideViewer.prototype.caculatePixel = function(){
	var currentPixel;
	if (this.direction == 'HORIZONTAL'){
		currentPixel = parseInt(this.target.style.left);
	}else{
		currentPixel = parseInt(this.target.style.top);
	}
	
	var movePixel = this.totalPixel + currentPixel - this.windowPixel;
	
	var leftPixel = Math.abs(currentPixel);
	if (leftPixel >= this.viewPixel){
		this.prevPixel = currentPixel + this.viewPixel;
	}else if(leftPixel > 0){
		this.prevPixel = 0;
	}
	
	if (movePixel >= this.viewPixel){
		this.nextPixel = (leftPixel+this.viewPixel) * -1;
	}else if(movePixel > 0){
		this.nextPixel = (leftPixel+movePixel) * -1;
	}
	
	//if (currentPixel == 0) this.prevImg.style.display = 'none';
	//else this.prevImg.style.display = 'inline';
	
	//if (movePixel == 0) this.nextImg.style.display = 'none';
	//else this.nextImg.style.display = 'inline';
		
	this.handling = false;
}