
var nInterval = 5000; // ms = 5 seconds
var intervalID = 0;
var nPngIndex = 0;
var mPngIndex = 0;
var rotation1 = true;
var elem = 0;
var isPlay = true;
var mainDiv = "url(png/main1.png)";

function theRotator() {
	//Set the opacity of all images to 0
	$('div.ImageRotator ul li').css({opacity: 0.0});

	//Get the first image and display it (gets set to full opacity)
	$('div.ImageRotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	rotation1 = false;
	intervalID = setInterval('rotate()',nInterval);
}

function rotate2img(img2load) {	
	var lastImageDot = "current" + nPngIndex;
	updateBackgroundImageById(lastImageDot, "url(png/ImageSlider/button_slider_off.png)");

        clearInterval(intervalID);

	elem = 'div.ImageRotator ul li#slide' + img2load;
	nPngIndex = img2load;

	//Set the opacity of all images to 0
	$('div.ImageRotator ul li').css({opacity: 0.0});
	$('div.ImageRotator ul li').removeClass('show');
	
	//Get the image and display it (gets set to full opacity)
	$(elem).css({opacity: 1.0});

	var currentImageDot = "current" + nPngIndex;
	updateBackgroundImageById(currentImageDot, "url(png/ImageSlider/button_slider_on.png)");

	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	rotation1 = true;
	intervalID = setInterval('rotate()',nInterval);
};

function rotate() {	
	var lastImageDot = "current" + nPngIndex;
	updateBackgroundImageById(lastImageDot, "url(png/ImageSlider/button_slider_off.png)");
	if( nPngIndex < mPngIndex - 1 ) { ++nPngIndex; }
	else { nPngIndex = 0; }
        
	if (rotation1) { 
		var current = $(elem);
		if ( current.length == 0 ) current = $('div.ImageRotator ul li:first');
		var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.ImageRotator ul li:first') : current.next()) : $('div.ImageRotator ul li:first'));
		rotation1 = false;
	}
	else {
		//Get the first image
		var current = ($('div.ImageRotator ul li.show')?  $('div.ImageRotator ul li.show') : $('div.ImageRotator ul li:first'));

		if ( current.length == 0 ) current = $('div.ImageRotator ul li:first');

		//Get next image, when it reaches the end, rotate it back to the first image
		var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.ImageRotator ul li:first') : current.next()) : $('div.ImageRotator ul li:first'));
	}

	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	next.addClass('show')
	next.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	current.removeClass('show');

	var currentImageDot = "current" + nPngIndex;
	updateBackgroundImageById(currentImageDot, "url(png/ImageSlider/button_slider_on.png)");
};

function playPauseImageSlider(overRide)
{
	if(isPlay || overRide)	{
		clearInterval(intervalID);
		isPlay = false;
		updateBackgroundImageById("btnPlayPause", "url(png/ImageSlider/button_play.png)");
	}
	else  {
		isPlay = true;
		updateBackgroundImageById("btnPlayPause", "url(png/ImageSlider/button_pause.png)");
		rotate2img(nPngIndex);
	}
}

function updateBackgroundImageById(ElementById, Url)
{
	mainDiv = document.getElementById(ElementById);
	mainDiv.style.background = Url;
	mainDiv.style.backgroundRepeat = "no-repeat";
	mainDiv.style.backgroundPosition = "center center";
}

var sindex = 0;
var sstring = "";
function scrolltext()
{
   var stext = 'New ECU Tuning for Hayabusa and GSXR 1000';
   sstring = stext + '   //----->   ';
   sindex = sstring.length;
   intervalID = setInterval('scroller()',100);
}

function scroller()
{
   var snewtext = sstring.substring (1,sstring.length) + sstring.substring (0,1);
   var scrolldiv = document.getElementById('scrolltextid');
   scrolldiv.innerHTML = snewtext;
   //scrolldiv.style.wordWrap="break-word";
   scrolldiv.style.wordBreak="break-all";
   sstring = snewtext;
}

$(document).ready(function() {		
	mPngIndex = $('div.ImageRotator ul li').length;
	//Load the slideshow
	theRotator();
   scrolltext();
	$('div.ImageRotator').fadeIn(1000);
	$('div.ImageRotator ul li').fadeIn(1000); // tweek for IE
});




