//Thanks to Ragulan Rajaratnam for most of the code to this
//http://ragulan.co.uk/articles/view/30

$(function() { 
objImage =
  {
    index : 1,
	
    // an array of images
    images : ["slide1.jpg", "slide2.jpg", "slide3.jpg", "slide4.jpg", "slide5.jpg", "slide6.jpg"],
	
    // function to increase the index value, and reset it if we are at the end of the array
    inc_index : function() {
      this.index++; 
      
      if (this.index == this.images.length) {
        this.index = 0;
      }
    },
	
    // getting function to return the current index
    get_index : function() { return this.index; },
	
    // function  to fade out, swap the image, increase the index and fade in the image
    swap : function() {
		//set the background image to the enclosing div
		$("#image-holder").css("background-image", "url(/media/slide/" + 
          objImage.images[objImage.index] + ")");
      // first fade the image out
      $("#image-yard").fadeOut(2000, function() {
        
        // change the image
        $("#image-yard").attr("src", "/media/slide/" + 
          objImage.images[objImage.index]);
        
        // fade the image back in
        $("#image-yard").fadeIn(2000);
        
       // increase the index
       objImage.inc_index();
      });
    }
  };

  // swap the image every n seconds
  setInterval(objImage.swap, 7000);
  
		   });
