document.write("<style type='text/css'>#imageS1 {visibility:hidden;}</style>");
//document.write("<style type='text/css'>#imageS2 {visibility:visible;}</style>");

var imgArray = new Array(12);
var intCounter1 = 0;
var intCounter2 = 5;

function initMainImages()
{
	for (var i=0; i<12; i++) {
		imgArray[i] = new Image(150, 150);
		imgArray[i].src = "images/side_img_main" + (i + 1) + ".jpg";
	}	

	fadeInImageSet(1, 0);
}

function initBusSWImages()
{
	for (var i=0; i<12; i++) {
		imgArray[i] = new Image(150, 150);
		imgArray[i].src = "images/side_img_bsw" + (i + 1) + ".jpg";
	}	

	fadeInImageSet(1, 0);
}

function fadeInImageSet(intSet, setSwap) {

	if (setSwap>0) {
		swapImages(intSet);
	}

	imageId = 'imageS' + intSet;
	image = document.getElementById(imageId);
	setOpacity(image, 0);
	image.style.visibility = "visible";
	fadeIn(imageId, 0);

	if (intSet==1)
	{
		intSet = 2;
	}
	else
	{
		intSet = 1;
	}

	setTimeout("fadeOutImageSet(" + intSet + ")", 5000);
}

function fadeOutImageSet(intSet) {

	imageId = 'imageS' + intSet;
	image = document.getElementById(imageId);
	fadeOut(imageId,100);

	setTimeout("fadeInImageSet(" + intSet + ", 1)", 3000);
}

function swapImages(intSet) {

	if (intSet==1)
	{

		intCounter1 = ++intCounter1 % 12;
		
		//imageS1.src = imgArray[intCounter1].src;

		image = document.getElementById("imageS1");
		image.src = imgArray[intCounter1].src;
	}

	if (intSet==2)
	{

		intCounter2 = ++intCounter2 % 12;
		
		//imageS2.src = imgArray[intCounter2].src;

		image = document.getElementById("imageS2");
		image.src = imgArray[intCounter2].src;
	}
	
}

function fadeIn(objId, opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity <= 100) {
			setOpacity(obj, opacity);
			opacity += 10;
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
		}
			
	}
}

function fadeOut(objId, opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity >= 10) {
			setOpacity(obj, opacity);
			opacity -= 10;
			window.setTimeout("fadeOut('"+objId+"',"+opacity+")", 100);
		}
		else {
			setOpacity(obj, 0);
		}
	}
}

function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}

//window.onload = function() {initImages()}
