		//Custom slide function by Alex Richter
		
var active = 0;
var changer;
var scroller;
var timer;
		
		
//Actual plugin
jQuery.fn.ar_slide = function (fn_scroller) {
    //Set individual id for each link

    changer = $(this);
    scroller = fn_scroller;

    var fn_rand = Math.floor(Math.random() * 3); // random number between 0 - 2

    var height = 0;

    for (i = 0; i <= 2; i++) {
        //Give unique id so we can tell what they clicked.
        scroller.find("img:eq(" + i + ")").attr("id", "slide" + i);

        // find the largest height and set it generically to stop flickering
        if (changer.eq(i).height() > height) {
            height = changer.eq(i).height();
        }

        // Hide all but randomly generated offset
        if (i != fn_rand) {
            changer.eq(i).hide();
        } else {
            active = fn_rand;
            changer.eq(i).show();
            scroller.find("img:eq(" + fn_rand + ")").attr("src", "/Images/hp/scroller/active.png");
        }
    }

    // find the largest height and set it generically to stop flickering
    $(".hp_fix").css("min-height", height);

    // Set timer
    timer = setTimeout("change_auto();", 6000);

    // Bind click to change
    scroller.find("img").bind('click', function () {
        changer.stop(true, true); // Stop all existing...
        var id = $(this).attr("id").substring(5, 6); // Get ID
        change(id); // init change
    });

    return $(this);
}
		
						
//Change visible slide.
function change(id){	
	clearTimeout(timer);	// stop timeout 	
	if (id > 2) {
	    id = 0 // loop round if at end.
    }
				 
	changer.eq(active).fadeOut(1000, function() {
		changer.eq(id).fadeIn(1000); // Show ID
	});  // Hide Active
				
	scroller.find("img:eq(" + active + ")").attr("src", "/Images/hp/scroller/inactive.png"); // Change to inactive button
	scroller.find("img:eq(" + id + ")").attr("src", "/Images/hp/scroller/active.png"); // Change to active button
	active  = id; // Set ID as active.		 
	timer = setTimeout("change_auto();", 6000); //reset timer
}	
		
//Function to auto change.
function change_auto(){
	change(parseInt(active) + 1 );
}
