BASIK_VSHomePage = function(autopushes)
{
}

var proto = BASIK_VSHomePage.prototype;

// Handle the animated sub features.
//
//original
proto.wrapFeatures			= true;		// If true the features are endless.
proto.slideOnHoldButtons	= false;	// If true the features slide while the buttons are held down.
proto.autoPlay				= false;	// If true the features slide by themselves when the mouse is not over them.
proto.autoPush				= true;		// If true and autoPlay is false then the left arrow will auto-click after 4 seconds of inactivity.

proto.autoPlayLeft 			= true;
proto.buttonIsDown 			= false;
proto.isMouseOverFeatures 	= false;
proto.autoPushIntervalId 	= null;
proto.overLeftArrow 		= false;
proto.overRightArrow 		= false;
proto.maxAutoPushes			= 4;
proto.pushDelay				= 8000;
proto.moveInterval			= 1;
proto.abTestMode			= "";

proto.subFeaturesWidth 			= 864;		// Corrected in initialize ( ) to be the actual width of ALL the sub-features content.
proto.subFeatureRightMargin		= 3;
proto.subFeatureWidth			= 286;
proto.subFeatureContainerWidth	= 864;

// Called after the page is loaded. Initializes some callbacks
// and determines the rendered with of the features.
//

proto.initialize = function (abtestmode)
{
	if (abtestmode != undefined) {
		this.abTestMode = abtestmode;
		if (abtestmode == "B") {
			this.maxAutoPushes = 4;
		}
		if (abtestmode == "C") {
			this.wrapFeatures			= true;		// If true the features are endless.
			this.slideOnHoldButtons		= true;		// If true the features slide while the buttons are held down.
			this.autoPlay				= true;		// If true the features slide by themselves when the mouse is not over them.
			this.autoPush				= false;	// If true and autoPlay is false then the left arrow will auto-click after 4 seconds of inactivity.
			this.moveInterval			= 6;
			this.overLeftArrow 			= true;
			this.overRightArrow 		= true;
		}
	}
	var element = document.getElementById ( 'entries' );
	this.subFeaturesWidth = 0;
	
	for ( var index = 0; index < element.childNodes.length; index++ )
	{
		var featureWidth = element.childNodes [ index ].offsetWidth;
		
		if ( ! isNaN ( featureWidth ) && featureWidth > 0 )
		{
			// Add in the right margin.
			//
			
			this.subFeaturesWidth += featureWidth + this.subFeatureRightMargin;
		}
	}
	
	// IE 6 needs a fudge factor I believe because the HTML comment tags get
	// out of order during the wrap process and then rendering gets thrown off.
	//
	
	element.style.width = ( this.subFeaturesWidth + 6 ) + 'px';
	
	// Subtract for the last right margin.
	//
	
	this.subFeaturesWidth -= this.subFeatureRightMargin;
	
	// Opera 7 has troubles with the feature wrapping function
	// so do a test and turn it off is we get an error.
	//
	
	if ( this.wrapFeatures )
	{
		try
		{
			var child = element.removeChild ( element.lastChild );
			element.appendChild ( child );
		}
		catch ( e )
		{
			this.wrapFeatures = false;
		}
	}
	
	if ( this.autoPlay || this.autoPush )
	{
		if ( document.captureEvents )
		{
			document.captureEvents ( Event.MOUSEMOVE );
		}
		
		document.onmousemove = this.checkForSubFeatureRollOver;
	}
		
	if ( this.autoPlay )
	{
		this.autoPlaySubFeatures ( null );
	}
	else if ( this.autoPush )
	{
		this.autoPushSubFeatures ( true );
	}
	
	// On every mouse down event see if the email sign 
	// up form should be reset.
	//
	
	if ( document.captureEvents )
	{
		document.captureEvents ( Event.MOUSEDOWN );
	}
	
	document.onmousedown = this.resetSignUpForEmailInput;
}

// Starts sliding the sub-features.
//

proto.autoPlaySubFeatures = function ( event )
{
	// The sub-features move has completed. If autoplay is on
	// and the mouse is not over the area then restart.
	//

	var delta = bsk.subFeatureWidth + bsk.subFeatureRightMargin;
	bsk.moveSubFeatures ( bsk.autoPlayLeft ? - delta : delta, bsk.buttonIsDown ? .75 : 6, '', false );
	document.getElementById ( 'entries' ).basikMoveTween.onMotionFinished = bsk.autoPlaySubFeatures;
}
	
// Auto-push the left button every 4 seconds.
//

proto.autoPushSubFeatures = function ( startInterval, delay )
{
	if ( this.autoPushIntervalId != null )
	{
		window.clearInterval ( this.autoPushIntervalId );
		this.autoPushIntervalId = null;
	}
	
	if ( startInterval && ( this.maxAutoPushes == null || this.maxAutoPushes > 0 ) )
	{
		if (this.abTestMode == "C") {
			this.autoPushIntervalId = window.setInterval ( "bsk.handleSubFeatureButtonPress ( true )", 4000 );
		} else {
			this.autoPushIntervalId = window.setInterval ( "bsk.handleSubFeatureButtonPress ( false, true )", ! delay ? this.pushDelay : delay );
		}
	}
}

// Called whenever the mouse moves to see if the is over the
// sub-features. If so, the sub-features are stopped if they are
// currently auto-playing.
//

proto.checkForSubFeatureRollOver = function ( event )
{
	event = bsk.normalizeEvent ( event );
	
	var subFeatures = document.getElementById ( 'subFeatures' );
	var featuresPosition = bsk.findPos ( subFeatures );
	
	var subFeaturesContainer = document.getElementById ( 'subFeaturesContainer' );
	var featuresContainerPosition = bsk.findPos ( subFeaturesContainer );
	
	// Light up the arrows when we're over the sub-
	// features.
	//
	
	var rightArrow = document.getElementById ( 'right' );
	var leftArrow = document.getElementById ( 'left' );
	
	if ( event.x >= featuresContainerPosition [ 0 ] && event.x <= featuresContainerPosition [ 0 ] + subFeaturesContainer.offsetWidth && event.y >= featuresContainerPosition [ 1 ] && event.y < featuresContainerPosition [ 1 ] + subFeaturesContainer.offsetHeight )
	{
		if ( ! bsk.overRightArrow )
		{
			//rightArrow.src = '/images/common/pagenav/feature_arrow_right_over.gif';
		}
		
		if ( ! bsk.overLeftArrow )
		{
			//leftArrow.src = '/images/common/pagenav/feature_arrow_left_over.gif';
		}
	}
	else
	{
		if ( ! bsk.overRightArrow )
		{
			//rightArrow.src = '/images/common/pagenav/feature_arrow_right.gif';
		}
		
		if ( ! bsk.overLeftArrow )
		{
			//leftArrow.src = '/images/common/pagenav/feature_arrow_left.gif';
		}
	}
	
	if ( event.x >= featuresPosition [ 0 ] && event.x <= featuresPosition [ 0 ] + subFeatures.offsetWidth && event.y >= featuresPosition [ 1 ] && event.y < featuresPosition [ 1 ] + subFeatures.offsetHeight )
	{
		if ( bsk.autoPlay )
		{
			if ( ! bsk.buttonIsDown && ! bsk.isMouseOverFeatures )
			{
				bsk.isMouseOverFeatures = true;
				bsk.moveSubFeatures ( -10, 1, null, false );
			}
		}
		else if ( bsk.autoPush )
		{
			bsk.autoPushSubFeatures ( false );
		}
	}
	else
	{
		if ( bsk.autoPlay )
		{
			if ( bsk.buttonIsDown )
			{
				bsk.handleSubFeatureButtonHold ( bsk.autoPlayLeft, false );
			}
			
			if ( bsk.isMouseOverFeatures )
			{
				bsk.isMouseOverFeatures = false;
				bsk.autoPlaySubFeatures ( null );
			}
		}
		else if ( bsk.autoPush )
		{
			if ( bsk.autoPushIntervalId == null )
			{
				bsk.autoPushSubFeatures ( true );
			}
		}
	}
	
	return true;
}

// The left or right nav button was clicked. This only does
// something if slideOnHoldButtons is false.
//

proto.handleSubFeatureButtonPress = function ( isLeft, isAutoPush )
{
	var delta = this.subFeatureContainerWidth + bsk.subFeatureRightMargin;
	
	if (this.abTestMode == "C") {
		if ( ! this.slideOnHoldButtons )
		{
			this.moveSubFeatures ( isLeft ? delta : - delta, null, null, true );
		}
	
		if ( this.autoPush )
		{
			this.autoPushSubFeatures ( true );
		}
	} else {
	//old
		if ( isAutoPush )
		{
			this.maxAutoPushes--;
		}
		else
		{
			// The person clicked the button so disable the auto-push feature.
			//
		
			this.autoPush = false
			this.autoPushSubFeatures ( false );
		}
	
		if ( ! this.slideOnHoldButtons )
		{
			this.moveSubFeatures ( isLeft ? delta : - delta, null, null, true );
		}
	
		if ( this.autoPush )
		{
			this.autoPushSubFeatures ( true );
		}
	}
}

// The left or right nav arrow was pressed or released. This
// only does anything if slideOnHoldButtons is true in which
// case it slides the sub-features quickly while the button is
// pressed.
//

proto.handleSubFeatureButtonHold = function ( isLeft, isHold )
{
	if ( this.slideOnHoldButtons )
	{
		if ( isHold )
		{
			this.autoPlayLeft = ! isLeft;
			this.buttonIsDown = true;
			this.autoPlaySubFeatures ( null );
		}
		else
		{
			this.autoPlayLeft = true;
			this.buttonIsDown = false;
			this.moveSubFeatures ( isLeft ? 90 : -90, 1, null, false );
		}
	}
}

// This actually moves the sub-features.
//

proto.moveSubFeatures = function ( delta, time, easingFunction, synch )
{
	time = time == null ? 1 : time;
	//time = this.moveInterval;
	
	var minMove = -1 * ( this.subFeaturesWidth - this.subFeatureContainerWidth );
	var maxMove = 0;
	
	var element = document.getElementById ( 'entries' );
	var currentPosition = this.styleToNumber ( element.style.left, 0 );
	var targetPosition = currentPosition + delta;
	
	if ( synch )
	{
		// Make sure we're moving to the edge of a sub-feature.
		//
		
		var synchPoint = this.subFeatureWidth + this.subFeatureRightMargin;
		
		var nearPosition = Math.floor ( targetPosition / synchPoint ) * synchPoint;
		var farPosition = Math.ceil ( targetPosition / synchPoint ) * synchPoint;
		
		if ( Math.abs ( nearPosition - currentPosition ) < Math.abs ( farPosition - currentPosition ) )
		{
			delta = nearPosition - currentPosition;
		}
		else
		{
			delta = farPosition - currentPosition;
		}
	}
	
	if ( this.wrapFeatures )
	{
		// If we are about to go beyond the end of the content
		// re-order the sub features.
		//
		
		while ( targetPosition < minMove || targetPosition > maxMove )
		{
			// Move the first child to the end of the list or
			// the last child to the beginning.
			//
			
			element.style.visibility = "hidden";
			
			var child;
			
			while ( true )
			{
				if ( targetPosition < minMove )
				{
					child = element.removeChild ( element.firstChild );
					element.appendChild ( child );
				}
				else
				{
					child = element.removeChild ( element.lastChild );
					element.insertBefore ( child, element.firstChild );
				}
				
				if ( child.nodeName.toLowerCase ( ) == "div" )
				{
					break;
				}
			}
			
			if ( targetPosition < minMove )
			{
				currentPosition += child.offsetWidth + this.subFeatureRightMargin;
				targetPosition += child.offsetWidth + this.subFeatureRightMargin;
			}
			else
			{
				currentPosition -= child.offsetWidth + this.subFeatureRightMargin;
				targetPosition -= child.offsetWidth + this.subFeatureRightMargin;
			}
			
			element.style.left = currentPosition + 'px';
			element.style.visibility = "visible";
		}
	}
	
	this.moveElement ( 'entries', 'left', delta, minMove, maxMove, time, easingFunction, true );
}
				
proto.resetSignUpForEmailInput = function ( event )
{
	event = event == null ? window.event : event;
	
	var isOutsideInput = true;
	var signUpForEmailInput = document.getElementById ( 'signUpForEmailInput' );
	
	var scan = event.target;
	
	if ( ! scan && event.srcElement )
	{
		scan = event.srcElement;
	}
	
	if ( scan.nodeType == 3 ) // defeat Safari bug (http://www.quirksmode.org/js/events_properties.html#target)
	{
		scan = scan.parentNode;
	}
	
	while ( scan != null )
	{
		if ( scan == signUpForEmailInput )
		{
			isOutsideInput = false;
			break;
		}
		
		scan = scan.parentNode;
	}

	if ( isOutsideInput )
	{
		document.getElementById ( 'signUpForEmailText' ).value = 'Sign up for Email';
	}
}

// Workaround for IE issue of embedding ActiveX controls in a disabled state.
//

proto.documentWrite = document.write;
proto.documentWriteLn = document.writeln;
proto.embedSrc;

proto.captureWrites = function ( )
{
	this.embedSrc = '';
	document.write = function ( string ) { bsk.embedSrc += string; };
	document.writeln = function ( string ) { bsk.embedSrc += string + "\n"; };
}

proto.releaseWrites = function ( )
{
	document.write = this.documentWrite;
	document.writeln = this.documentWriteLn;
	document.write ( this.embedSrc );
	this.embedSrc = '';
}

//
// End of IE workaround code.

// Macromedia stuff to do image swapping on rollover.
//

proto.swapImgRestore = function () {
	var i,x,a=document.sr; 
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) {
		x.src=x.oSrc;
	}
}

proto.findObj = function (n, d) {
	var p,i,x;  
	if(!d) d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=this.findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

proto.swapImage = function () {
	var i,j=0,x,a=arguments; // swapImage.arguments
	document.sr=new Array;
	for(i=0;i<(a.length-2);i+=3)
	if ((x=this.findObj(a[i]))!=null){
	document.sr[j++]=x;
	if(!x.oSrc) {
		x.oSrc=x.src;
	}
	x.src=a[i+2];}
}

//
// End of Macromedia rollover code.

// Helper to preload a list of images.
//

proto.preloadImageList = function ( )
{
	if ( this.iL )
	{
		var d = document; 
		
		if ( d.images )
		{ 
			if ( ! d.p )
				d.p = new Array ( );

			var i, j = d.p.length;

			for ( i = 0; i < this.iL.length; i++ )
			{
				if ( this.iL [ i ].indexOf ( "#" ) != 0 )
				{ 
					d.p [ j ] = new Image; 
					d.p [ j++ ].src = this.iL [ i ];
				}
			}
		}
	}
}

// Find the position of an element in the browser.
//
// http://www.quirksmode.org/js/findpos.html
//

proto.findPos = function (obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

// Find the position of the mouse in the browser.
//

proto.normalizeEvent = function ( event )
{
	var myEvent = new Object ( );
	
	myEvent.x = 0;
	myEvent.y = 0;

	event = event == null ? window.event : event;
	
	if ( event.pageX || event.pageY )
	{
		myEvent.x = event.pageX;
		myEvent.y = event.pageY;
	}
	else if ( event.clientX || event.clientY )
	{
		myEvent.x = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		myEvent.y =event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
	
	return myEvent;
}

// The remaining code does the DHTML sliding. fading and revealing animations.
//
// Requires Tween.js
//

proto.styleToNumber = function ( style, defaultValue )
{
	var value = defaultValue;
	
	if ( style != null && style.length )
	{
		var found = style.match ( /^(-?\d+)/ );
		value = found != null && found.length > 0 ? Number ( found [ 0 ] ) : defaultValue;
	}

	return value;	
}

proto.moveElement = function ( elementId, style, delta, moveMin, moveMax, time, easingFunction, resetTarget )
{
	var atLimit = false;
	
	if ( delta == null || delta == 0 )
	{
		return atLimit;
	}
	
	var element = document.getElementById ( elementId );
	
	if ( element.basikMoveTween != null )
	{
		element.basikMoveTween.stop ( );
	}
	
	var currentPosition = this.styleToNumber ( element.style [ style ], 0 );
	
	if ( resetTarget )
	{
		element.basikTarget = currentPosition + delta;
	}
	else
	{
		if ( element.basikTarget == null )
		{
			element.basikTarget = currentPosition;
		}
		
		element.basikTarget += delta;
	}
	
	if ( element.basikTarget <= moveMin )
	{
		element.basikTarget = moveMin;
		atLimit = true;
	}
	
	if ( element.basikTarget >= moveMax )
	{
		element.basikTarget = moveMax;
		atLimit = true;
	}
	
	element.basikMoveTween = new Tween ( element.style, style, easingFunction == null ? Tween.strongEaseOut : easingFunction, currentPosition, element.basikTarget, time == null ? .5 : time, 'px' );
	
	element.basikMoveTween.start ( );
	
	return atLimit;
}

bsk = new BASIK_VSHomePage ( );


