function tab1(that)
{
	$('scollerContainer2').style.display='none';		
	$('pmTab').style.backgroundColor='#fff';	
	$('pmTab').style.color='#000';	
	$('pmTab').style.backgroundImage='none';
	$('pmTab').style.paddingBottom='9px';
	
	$('paygTab').style.color='#ddd';
	$('paygTab').style.backgroundColor='#666';
	$('paygTab').style.backgroundImage='url(/vm/media/images/home/scrollerbuttonunselected.jpg)';
	$('paygTab').style.backgroundRepeat='repeat-x';
	$('paygTab').style.paddingBottom='8px';
	
	that.blur();
	return false;
}

function tab2(that)
{
	$('scollerContainer2').style.display='block';	
	$('paygTab').style.backgroundColor='#fff';
	$('paygTab').style.color='#000';
	$('paygTab').style.backgroundImage='none';
	$('paygTab').style.paddingBottom='9px';
	
	$('pmTab').style.color='#ddd';
	$('pmTab').style.backgroundColor='#666';
	$('pmTab').style.backgroundImage='url(/vm/media/images/home/scrollerbuttonunselected.jpg)';
	$('pmTab').style.backgroundRepeat='repeat-x';
	$('pmTab').style.paddingBottom='8px';	
	

	
	that.blur();
	return false;
}

var scroller = function (name,el,indie,indieOffColor,phoneCount,contextPath)
{
	this.speed 			=	15;
	this.distance 		=	25;
	this.distanceNormal	=	25;
	this.direction 		=	-1;
	this.pos 			=	0;
	this.phoneCount		=	phoneCount
	this.phoneWidth		=	179;
	this.innerWidth 	=	this.phoneWidth * 3;
	this.outerWidth 	=	(this.phoneWidth * phoneCount) - this.innerWidth;
	this.timer 			=	null;
	this.point 			=	0;
	this.name			= 	name;
	this.el 			=	$(el);
	//this.el.style.left	=	'0px';
	this.indie			=	indie;
	this.indiePos		=	1;
	this.targetPos		=	0;
	this.moveCount		=	0;
	this.sindieOffColor	=	indieOffColor;
	this.contextPath	= 	contextPath;
	
	this.setupIndie();
	
	this.indieImgOn		=	$(indie+'1').src;
	this.indieImgOff	=	$(indie+'2').src;
	
	number				= 	this.name.charAt(this.name.length-1);
	this.leftArrow		=	'scrollLeftArrow'+number;
	this.rightArrow		=	'scrollRightArrow'+number;
	
	this.start();
}

scroller.prototype.start = function()
{
	this.el.style.left =  '600';
	this.el.style.visibility = 'visible';
	this.pos = 600;
	this.distance =	50;
	$(this.leftArrow).src  = this.contextPath + '/media/images/home/vm_arrows_left.gif';
	$(this.rightArrow).src = this.contextPath + '/media/images/home/vm_arrows_right.gif';
	this.moveTo(1);
}

scroller.prototype.stop = function()
{
	this.distance = this.distanceNormal; //slow speed down after first scroll in.
	if (0 == this.pos) //far left
	{
		$(this.leftArrow).className = 'disabled';
	}
	else if (this.outerWidth == -(this.pos)) //far right
	{
		$(this.rightArrow).className = 'disabled';
	}
}

scroller.prototype.mouseOver = function(el)
{
	if ('disabled' != el.className)
		el.className = 'hover';
}

scroller.prototype.mouseOut = function(el)
{
	if ('disabled' != el.className)
		el.className = '';
}

scroller.prototype.setupIndie = function()
{
	var outStr ='<img id="'+this.indie+'1" class="first" onclick="'+this.name+'.moveTo(1)" src="'+this.contextPath+'/media/images/home/scrollIndicator.gif" />';
	var i = Math.ceil(this.phoneCount/3)+1;
	
	for (var j=2 ; j!=i ; j++)
		outStr+='<img id="'+this.indie+j+'" onclick="'+this.name+'.moveTo('+j+')" src="'+this.contextPath+'/media/images/home/scrollOff'+this.sindieOffColor+'.gif" />';
	
	$(this.indie).innerHTML = outStr + ' ' + $(this.indie).innerHTML;	
}
		
scroller.prototype.move = function()
{
	var stop = false;
	
	this.pos += this.distance * this.direction;
		
	 if ((1==this.direction && -(this.pos) < this.targetPos+this.distance) || (-1==this.direction && -(this.pos) > this.targetPos+this.distance))
	 {
		this.pos=-(this.targetPos);
		stop=true;
	 }
	 
	this.el.style.left =  '' + this.pos + 'px';
		
	if (this.point == this.pos || this.pos == 0)
		stop=true;

	var i = Math.ceil(-1*this.pos/this.innerWidth)+1;
	this.updateIndie(i);
		
	if (true!=stop) // Work out indicator pos
		this.timer =  setTimeout(''+this.name+'.move()',this.speed);
	else
		this.stop();

}

scroller.prototype.setTarget = function(tPos)
{
	var targetPos = (tPos-1)*this.innerWidth;
	
	if (targetPos > this.outerWidth)
	{
		targetPos = this.outerWidth;
	}	
	this.targetPos = targetPos;
}


scroller.prototype.updateIndie = function(newPos)
{
	if (newPos!=this.indiePos)
	{
		if ($(this.indie+this.indiePos)) 
			$(this.indie+this.indiePos).src = this.indieImgOff;
			
		this.indiePos=newPos;
		
		if ($(this.indie+this.indiePos))
			$(this.indie+this.indiePos).src = this.indieImgOn;
		//else //we've gone off the end, so step back a little
			//this.left();
	}
}

scroller.prototype.moveTo = function (point)
{
	clearTimeout (this.timer);
	$(this.leftArrow).className = '';
	$(this.rightArrow).className = '';
	this.point = (-(point * this.innerWidth))+this.innerWidth;
	this.direction = this.point < this.pos ? -1 : 1;
			
	this.moveCount = 0;

	this.setTarget(point);
	this.updateIndie(point);
	this.move();
}
		
scroller.prototype.left = function(overRide)
{
	clearTimeout (this.timer);
	if (0 != this.pos || true == overRide)
	{
		$(this.rightArrow).className = '';
		this.point+=this.innerWidth;
		this.direction = 1;
		this.moveCount = 0;
	
		this.setTarget(this.indiePos-1);
		this.updateIndie(this.indiePos-1);
		this.move();
	}
}
		
scroller.prototype.right = function()
{
	clearTimeout (this.timer);
	if (this.outerWidth >= -(this.pos-this.phoneWidth))
	{
		$(this.leftArrow).className = '';
		this.point-=this.innerWidth;
		this.direction = -1;
	
		this.setTarget(this.indiePos+1);
		this.updateIndie(this.indiePos+1);
		this.move();
	}
}
	
function scrollerWrapper()
{
	scroll1.move();
}