jQuery(document).ready(function($){

/* slideshow stuff in an object  */

	slideShowVar = {
		numImages: $("#first-read img").size(), // set var to equal the number the of banner images
		interval: 6500, // interval between slides
		i: 0, // incrementer for generator tabs
	    f: 0, // fade interval indicator
		startSlideShow: 0,
		numberClicked: 0
	}

	$("#first-read a:eq(0)").before("<ul></ul>"); // tab container

	for ( slideShowVar.i = 1; slideShowVar.i <= slideShowVar.numImages; slideShowVar.i++ ) {
//		$("#first-read ul").append('<li><a href="#banner0'+ slideShowVar.i +'" title="Go To Banner '+ slideShowVar.i +'" class="banner0'+ slideShowVar.i +'">'+ slideShowVar.i +'</a></li>'); //create nav links with classes based on the number of banner images
		$("#first-read ul").append('<li><a href="#banner0'+ slideShowVar.i +'" title="Go To Banner '+ slideShowVar.i +'" class="banner0'+ slideShowVar.i +'">&nbsp;</a></li>'); //create nav links with classes based on the number of banner images
		$("#first-read img:eq("+ (slideShowVar.i-1) +")").attr({ id: "banner0"+slideShowVar.i+"" }); // add matching id's to each of the banner images
	}

	$("#first-read ul li a.banner01").addClass("on");
	$("#first-read a img:eq(0)").css({"display" : "block"});

	function slideFade() {
		if ( slideShowVar.f < (slideShowVar.numImages -1) ) {
			$("#first-read a img:eq("+ slideShowVar.f +")").fadeOut( 1500,
				function() {
					$("#first-read ul li a").removeClass("on");
					$("#first-read ul li a.banner0"+ ( slideShowVar.f + 2) +"").addClass("on");
					$("#first-read a img:eq("+ (slideShowVar.f + 1) +")").fadeIn( 2300 ); //alert(f);
					slideShowVar.f = slideShowVar.f + 1;
				}
			);
		} else if ( slideShowVar.f = (slideShowVar.numImages -1) ) {
			$("#first-read a img:eq("+ slideShowVar.f +")").fadeOut( 2300,
				function() {
					$("#first-read ul li a").removeClass("on");
					$("#first-read ul li a.banner0"+ ( slideShowVar.f + 1) +"").addClass("on");
					$("#first-read a img:eq(0)").fadeIn( 2300 ); //alert(f);
				}
			);
			slideShowVar.f = 0;
		} 	
	}

	slideShowVar.startSlideShow = setInterval( slideFade, slideShowVar.interval );

	$("#first-read ul li a").click( function () {										 
		$("#first-read a img").hide();
//		slideShowVar.numberClicked = $(this).text();
		slideShowVar.numberClicked = $(this).attr("class").substr($(this).attr("class").indexOf("0")+1);
		$("#first-read a img:eq("+ (slideShowVar.numberClicked - 1) +")").fadeIn( 2300 );
		$("#first-read ul li a").removeClass("on");
		$(this).addClass("on"); //alert(f);
		clearTimeout(slideShowVar.startSlideShow);
    });

});
