beginat = 2;	 		//This is the counter that runs the rotator, set it to what image you want the rotator to start on	
timeDelay = 5000 		//This value is for the delay between changing images
$.fadeDelay = 1500 		//This value is for the time the fade between images takes
imageCount = 0;			//It'll get the number os banners from the XML file
timeInterval='';

$(document).ready(function(){
	$.ajax({
		type: 'GET',
		url: 'xml/banners.xml',
		dataType:'xml',
		success: function(xml){
			$('#banner').append('<ul id="jsrimages">');
			$(xml).find('site').each(function(){
				var id = $(this).attr('id');
				var title = $(this).find('title').text();
				var url = $(this).find('url').text();
				var img = $(this).find('img').text();
				//$('#navBox').append('<a id="jsrBtn'+id+'" href="javascript:jumpimages('+id+')">'+id+'</a>'); //Link para os banners
				$('#navBox').append('<span id="jsrBtn'+id+'">&nbsp;</span>');
				if(id>1){
					//$('#jsrimages').append('<li id="jsr'+id+'"><a href="'+url+'" title="'+title+'"><img src="images/slideshow/'+img+'" border="0"/></a></li>');
					$('#jsrimages').append('<li id="jsr'+id+'"><img src="images/slideshow/'+img+'" border="0"/></li>');
				}else{
					$("#jsrBtn"+id).attr('class','over');
					//$("#fade1").append('<a id="'+id+'" href="'+url+'" title="'+title+'"><img src="images/slideshow/'+img+'" border="0"/></a>');
					$("#fade1").append('<img src="images/slideshow/'+img+'" border="0"/>');
					$('#jsrimages').append('<li id="jsr'+id+'"><a href="'+url+'" title="'+title+'"><img src="images/slideshow/'+img+'" border="0"/></a></li>');
				}					
				imageCount = imageCount+1;
			});
			timeInterval = setInterval("swapimages(beginat, imageCount);", timeDelay);
		}
	});
});
function jumpimages(jsrCounter){
	//imageCount=$('#navBox a').length;
	imageCount=$('#navBox span').length;
	if(setInterval){
		clearInterval(timeInterval);
	}
	timeInterval =  setInterval("swapimages(jsrCounter, imageCount);", timeDelay);
	swapimages(jsrCounter, imageCount);
}
function swapimages(jsrCounter, imageCount){
	//imageCount=$('#navBox a').length;
	imageCount=$('#navBox span').length;
	$("#fade2").html($("#fade1").html()).show().fadeOut($.fadeDelay);
	$("#fade1").html($("#jsr" + jsrCounter).html()).fadeIn($.fadeDelay);
	$("[id*=jsrBtn]").removeClass("over")
	$("#jsrBtn" + jsrCounter).addClass("over")
	if(beginat == imageCount){
		beginat = 1;
	 }else{
	 	beginat++;
	};
};
