var currentBg;
var bgFadeSpeed= 500;
var bgShowSpeed = 10000;
var bgTimer;

function initShow() {	
	var bgTimer = window.setInterval("doIt();", bgShowSpeed);
	currentBg = $("#imageWrapper").children().first();

}
function showTurnOffOthers(){
	// turn off all image layers in slideshow except 1st for IE
	// call this before doc ready
	$.each($("#imageWrapper").children(), function (i,item){
		$("#"+item.id).fadeTo(0, 0); // turn off all items
	});
	
	$("#imageWrapper").children().first().fadeTo(0, 1);
}
function swapBg(nextBg){
	//console.log("current "+ currentBg.attr("id") + " next:" + nextBg.attr("id"));
	if(currentBg.attr("id") != nextBg.attr("id")){
				
		currentBg.stop(true,true);
		currentBg.fadeTo(bgFadeSpeed,0); //fade current
		//console.log("the id >"+currentBg.attr("id"));
		currentBg = nextBg;
		currentBg.fadeTo(bgFadeSpeed,1, function(e){
			//fade callback...
		});	
	}
}


function doIt(){
	
		if(currentBg.next().attr("id") != undefined){
			swapBg(currentBg.next());
		}else{
			swapBg(currentBg.parent().children().first());
		}

}



