jQuery.fn.extend({
	bringToFront: function() {
		return this.each(function() { $(this).css("z-index","15"); });
	},
	sendToBack: function() {
		return this.each(function() { $(this).css("z-index","1"); });
	}
});

function initSlider(images, pause) {
	if (images.length > 0) {
		var imagesPreloaded = [];
		for(var i = 0;i<images.length;i++) {
			//imagesPreloaded[i] = $("<img />").attr({src:images[i],class:"slideImg",id:"slideImg"+(i+1),style:"z-index:1;"});
			imagesPreloaded[i] = $("<img />").attr({src:images[i],className:"slideImg",id:"slideImg"+(i+1)}).css({zIndex:"1"});
		}
	}
	
	// start slider
	count = 0;
	if (imagesPreloaded.length > 0) {
		setInterval(function() {
			countNext = count == (imagesPreloaded.length-1) ? 0 : count+1;
			
			// send current image to front
			$('#slideImg'+(count+1)).bringToFront();
			
			// insert new image under
			$('#feature').append(imagesPreloaded[countNext]);
			
			// set css attributes for new image
			$('#slideImg'+(countNext+1)).css({zIndex:'1',display:'block'});
			
			// fade away current image
			$('#slideImg'+(count+1)).fadeOut("slow",function(){
				// remove current image
				$(this).remove();
			});
			
			count = count == (imagesPreloaded.length - 1) ? 0 : count+1;
		}, pause);
	}	
}
