var defaultManualSpeed = 2000;
var defaultAutoSpeed = 6000;
var defaultAutoSpeedEdge = 3000; // optimal - half of defaultAutoSpeed

function goToPoint1(speed, gearbox, way) {

	if (!speed) speed = defaultManualSpeed;
	if (gearbox != 'auto') showIntroPart('Welcome');
	if (way == 'throughEdge') {

		if (gearbox == 'auto') {

			$('#timeline .inside').animate({
				backgroundPosition: '-7px -42px'
			}, defaultAutoSpeedEdge, function() {
				
				$('#timeline .inside').css({ backgroundPosition: '-990px -42px' });
				$('#timeline .inside').animate({
					backgroundPosition: '-913px -42px'
				}, defaultAutoSpeedEdge, function() {
				
					if (gearbox == 'auto') showIntroPart('Welcome');
				
				});
			});

		} else {

			$('#timeline .inside').animate({
				backgroundPosition: '-7px -42px'
			}, 250, function() {
			
				$('#timeline .inside').css({ backgroundPosition: '-990px -42px' });
				$('#timeline .inside').animate({
					backgroundPosition: '-913px -42px'
				}, 250, function() {
				
					if (gearbox == 'auto') showIntroPart('Welcome');
				
				});
			});

		}
	} else {
		if (!speed) speed = defaultManualSpeed;
		$('#timeline .inside').animate({
			backgroundPosition: '-913px -42px'
		}, speed, function() {
	
			if (gearbox == 'auto') showIntroPart('Welcome');
		});
	}
}
function goToPoint2(speed, gearbox) {

	if (!speed) speed = defaultManualSpeed;
	if (gearbox != 'auto') showIntroPart('Accessibility');

	$('#timeline .inside').animate({
		backgroundPosition: '-709px -42px'
	}, speed, function() {
	
		if (gearbox == 'auto') showIntroPart('Accessibility');
	});

}
function goToPoint3(speed, gearbox) {

	if (!speed) speed = defaultManualSpeed;
	if (gearbox != 'auto') showIntroPart('Performance');
	$('#timeline .inside').animate({
		backgroundPosition: '-505px -42px'
	}, speed, function() {

		if (gearbox == 'auto') showIntroPart('Performance');
	});
}
function goToPoint4(speed, gearbox) {

	if (!speed) speed = defaultManualSpeed;
	if (gearbox != 'auto') showIntroPart('Featured');
	$('#timeline .inside').animate({
		backgroundPosition: '-300px -42px'
	}, speed, function() {

		if (gearbox == 'auto') showIntroPart('Featured');
	});
}
function goToPoint5(speed, gearbox, way) {

	if (!speed) speed = defaultManualSpeed;
	if (gearbox != 'auto') showIntroPart('Community');
	if (way == 'throughEdge') {

		if (gearbox == 'auto') {

			$('#timeline .inside').animate({
				backgroundPosition: '-990px -42px'
			}, defaultAutoSpeedEdge, function() {
			
				$('#timeline .inside').css({ backgroundPosition: '-7px -42px' });
				$('#timeline .inside').animate({
					backgroundPosition: '-97px -42px'
				}, defaultAutoSpeedEdge, function() {
			
					if (gearbox == 'auto') showIntroPart('Community');
				});
			});

		} else {

			$('#timeline .inside').animate({
				backgroundPosition: '-990px -42px'
			}, 250, function() {
				
				$('#timeline .inside').css({ backgroundPosition: '-7px -42px' });
				$('#timeline .inside').animate({
					backgroundPosition: '-97px -42px'
				}, 250, function() {
				
					if (gearbox == 'auto') showIntroPart('Community');
				});
			});

		}

	} else {
		$('#timeline .inside').animate({
			backgroundPosition: '-97px -42px'
		}, speed, function() {
			
			if (gearbox == 'auto') showIntroPart('Community');
		});
	}
}

function introAutoPlay() {
	
	/*if ($('#introNav .nav li.active').size() > 0) {
		var activePointNo = $('#introNav .nav li.active').attr('class').substr(1, 1);
	}*/

	//if (activePointNo < 2) 
	goToPoint2(defaultAutoSpeed, 'auto');
	//if (activePointNo < 3) 
	goToPoint3(defaultAutoSpeed, 'auto');
	//if (activePointNo < 4)
	goToPoint4(defaultAutoSpeed, 'auto');
	//if (activePointNo < 5) 
	goToPoint5(defaultAutoSpeed, 'auto');
	goToPoint1(defaultAutoSpeed, 'auto', 'throughEdge');
	setTimeout(introAutoPlay,5*defaultAutoSpeed);
}



function showIntroPart(part) {

	//if ( $.browser.msie )
//	{
		$('.introPart').hide();
		$('#intro' + part).show();
	//}
//	else
//	{
//		$('.introPart').hide();
//		$('#intro' + part).show();
//	}
}

$(document).ready(function() {

	$('#timeline .inside').css('background-position', '-913px -42px');


});

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

addLoadEvent(function() {
	introAutoPlay();
});
