
var scrollUpDown = 
{
	scrollArea:Object, 
	scrollContent:Object, 
	linkNext:Object, 
	linkPrev:Object,
	scrollAreaId:String, 
	scrollContentId:String, 
	linkNextId:String, 
	linkPrevId:String,
	linkNextInactive:Boolean,
	linkPrevInactive:Boolean,
	init : function()
	{
		this.scrollArea = $('#'+this.scrollAreaId);
		this.scrollContent = $('#'+this.scrollContentId);
		this.linkNext = $('#'+this.linkNextId);
		this.linkPrev = $('#'+this.linkPrevId);
		//this.scrollArea.css('position', 'relative');
		//this.scrollContent.css('position', 'absolute');
		this.linkNext.click(scrollUpDown.goNext);
		this.linkPrev.click(scrollUpDown.goPrev);
		scrollUpDown.update();
			
	},
	update : function()
	{
		var contentY = parseInt(this.scrollContent.css('top'));
		if (isNaN(contentY))
		{
			contentY = 0;
		}
		if (this.scrollArea.height()>=this.scrollContent.height())
		{
			this.linkNextInactive=true;
			this.linkPrevInactive=true;			
		}
		else if (contentY==0)
		{
			this.linkNextInactive=false;
			this.linkPrevInactive=true;
		}
		else if (contentY <= (-this.scrollContent.height() + this.scrollArea.height()))
		{
			this.linkPrevInactive=false;
			this.linkNextInactive=true;
		}
		else
		{
			this.linkPrevInactive=false;
			this.linkNextInactive=false;
		}
		if (this.linkPrevInactive==true)
		{
			this.linkPrev.attr('class','inactive');
		}
		else
		{
			this.linkPrev.attr('class','');
		}
		if (this.linkNextInactive==true)
		{
			this.linkNext.attr('class','inactive');
		}
		else
		{
			this.linkNext.attr('class','');
		}
	},
	'goNext' : function(e)
	{
		if (scrollUpDown.linkNextInactive!=true)
		{
			scrollUpDown.scrollDown();
		}
		scrollUpDown.linkNext.blur();
		return false;
		
	},
	'goPrev' : function(e)
	{
		if (scrollUpDown.linkPrevInactive!=true)
		{
			scrollUpDown.scrollUp();
		}
		scrollUpDown.linkPrev.blur();
		return false;
	},
	'scrollUp' : function()
	{
		this.linkNextInactive=true;
		this.linkPrevInactive=true;		
		var contentY = parseInt(this.scrollContent.css('top'));
		if (isNaN(contentY))
		{
			contentY = 0;
		}
		if (contentY < 0)
		{
			this.scrollContent.animate(
				{ 
					top: (contentY+this.scrollArea.height())+'px'
				}, 
				1500,
				null,
				function() {
					scrollUpDown.update();
				}
			);
		}
		else
		{
			
			this.scrollContent.animate(
				{ 
					top: (-this.scrollContent.height() + this.scrollArea.height())+'px'
				}, 
				1500,
				null,
				function() {
					scrollUpDown.update();
				}
			);
		}
		
	},
	'scrollDown' : function()
	{
		this.linkNextInactive=true;
		this.linkPrevInactive=true;		
		var contentY = parseInt(this.scrollContent.css('top'));
		if (isNaN(contentY))
		{
			contentY = 0;
		}
		if (contentY  > -this.scrollContent.height() + this.scrollArea.height())
		{
			this.scrollContent.animate(
				{ 
					top: (contentY-this.scrollArea.height())+'px'
				}, 
				1500,
				null,
				function() {
					scrollUpDown.update();
				}
			);
		}
		else
		{
			this.scrollContent.animate(
				{ 
					top: '0px'
				}, 
				1500,
				null,
				function() {
					scrollUpDown.update();
				}
			);
		}
	}
}
