// 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()", 10);
   
 });
	 
	
var lastnumber = 1;	

function fade()
{
	
	 var timeperpic = 1500;
	
	setTimeout('fade()', timeperpic * 2);
 
	
	var random = Math.ceil(Math.random() * numpics);
	
	if (random == lastnumber) {
		random++;	
	}
	
	if (random > numpics) {
		random = 1;
	}
	
	 lastnumber = random;
	
	$('#pic' + random).fadeIn(timeperpic).pause(timeperpic).fadeOut(timeperpic);
	//alert(random);
	 
	
	/* var randompic = Math.floor((Math.random() * 7) + 1);
 	
	$('#sidepic').html('<img   src="images/sidepic' + randompic + '.gif" />');
	$('#sidepic').pause(40).fadeIn(1500); */
	 

}
	

