// following two functions kindly provided by Jonathan Howard
$.fn.pause = function(milli,type) {
	milli = milli || 1000;
	type = type || "fx";
	return this.queue(type,function(){
		var self = this;
		setTimeout(function(){
			$(self).dequeue();
		},milli);
	});
};

$.fn.clearQueue = $.fn.unpause = function(type) {
	return this.each(function(){
		type = type || "fx";
		if(this.queue && this.queue[type]) {
			this.queue[type].length = 0;
		}
	});
};
/////////// 
 
var numpics;
$(document).ready(function(){
numpics = $('.fadepic').length;

$('.fadepic').hide();	

$('.rolloverimage').fadeTo(1, 0.5);		
  $(".rolloverimage").hover(
	function () {
		$(this).fadeTo(1, 0.999);	
	},function(){
		$(this).fadeTo(1, 0.5);             
  	}
  );
      // trigger off the fading
	 setTimeout("fade()", 2);

 });	 
	
var random = 0;	
function fade(){
	var timeperpic = 3600;
	setTimeout('fade()', timeperpic * 2);

	if (random < numpics) {
		random++;
	}
	if (random >= numpics) {
		random = 1;	
	}
	$('#pic' + random).fadeIn(timeperpic).pause(timeperpic).fadeOut(timeperpic);
}
