(function($) {
	$.fn.jakes_first_read = function( settings ){

		settings = {
			interval : settings.interval || 6000
		} 

		var thisID = $(this).attr("id");
		var numberOfBanners = parseFloat( $("#"+thisID+" a").size() );
		var intialize = 0;

		//alert(numberOfBanners);

		$("#"+thisID+" a").addClass("banner")
		$("#"+thisID+" a:eq(0)").addClass("on")
        $("#"+thisID+" a:eq(0)").css("display", "inline");
		
		$.each( $("#"+thisID+" > a") , function(i){
			$("#banners-nav").append('<li><a title="Banner '+( i + 1 )+'">&bull;</a></li>\n');
			$("a:eq("+i+").banner").addClass("bn0"+( i + 1 )+"")
		});
		$("#banners-nav li:eq(0) a").addClass("on");


		function startRotation(){
	
			if ( intialize < ( numberOfBanners - 1 ) ) {
				$("#"+thisID+" > a:eq("+intialize+")").fadeOut( 200,
					function(){
						$(this).removeClass("on");
						$(this).css("display", "none");
						
						$("#"+thisID+" > a:eq("+( intialize + 1 )+")").addClass("on");
						
						$("#"+thisID+" > a:eq("+( intialize + 1 )+")").fadeIn( 450 );
						$("#"+thisID+" #banners-nav li:eq("+intialize+") a").removeClass("on");
						$("#"+thisID+" #banners-nav li:eq("+( intialize + 1 )+") a").addClass("on");
						intialize++
					}
				);
					
			} else if (  intialize >= ( numberOfBanners - 1 ) ) {	
	
				$("#"+thisID+" > a:last").fadeOut( 200,
					function(){
						$(this).removeClass("on");
						$("#"+thisID+" > a:eq(0)").addClass("on");

						$("#"+thisID+" > a:eq(0)").fadeIn( 450 );
						$("#"+thisID+" #banners-nav li:last a").removeClass("on");
						$("#"+thisID+" #banners-nav li:eq(0) a").addClass("on");
					}
				);	
				intialize = 0
			}



		}

		var start = setInterval ( startRotation, settings.interval );

		$("#"+thisID+" #banners-nav li a").click(function(){
			clearInterval(start);
			var thisPosition =  $(this).attr("title").slice(6);
			if ( $(this).hasClass("on") ) {
				return false
			} else {
				$("#"+thisID+" #banners-nav li a").removeClass("on");
				$(this).addClass("on");
				$(this).css("display", "inline");
				$("#"+thisID+" > a.on").fadeOut( 200 , function(){
					$(this).removeClass("on");
					$(this).css("display", "none");
					$("#"+thisID+" > a:eq("+( thisPosition - 1 )+")").fadeIn( 300 ).addClass("on");
				});
			}
		});


		$("#banners-nav li a").hover(
			function(){
				if( $(this).hasClass("on") ) { return false } else { $(this).css({ "cursor" : "pointer" }) }
			},
			function(){
				if( $(this).hasClass("on") ) { return false } else { $(this).css({ "cursor" : "auto" }) }	
			}
		);

		$("#"+thisID+" a:eq(0)").fadeIn()

//<div id="banner_navigation">\n<a href="javacript:void(0)" title="Previous" class="button previous">Previous</a> <a href="javacript:void(0)" title="Next" class="button next">Next</a>\n</div>\n

	}

})(jQuery);
