	jQuery.fn.supersleight = function(settings) {
            	settings = jQuery.extend({
            		imgs: true,
            		backgrounds: true,
            		shim: 'x.gif',
            		apply_positioning: true
            	}, settings);
            	
            	return this.each(function(){
            		if(jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 4){
            			jQuery(this).find('*').andSelf().each(function(i,obj) {
            				var self = jQuery(obj);
            				// background pngs
            				if (settings.backgrounds && self.css('background-image').match(/\.png/i) !== null) {
            					var bg = self.css('background-image');
            					var src = bg.substring(5,bg.length-2);
            					var mode = (self.css('background-repeat') == 'no-repeat' ? 'crop' : 'scale');
            					var styles = {
            						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')",
            						'background-image': 'url('+settings.shim+')'
            					};
            					self.css(styles);
            				};
            				// image elements
            				if (settings.imgs && self.is('img[src$=png]')){
            					var styles = {
            						'width': self.width() + 'px',
            						'height': self.height() + 'px',
            						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + self.attr('src') + "', sizingMethod='scale')"
            					};
            					self.css(styles).attr('src', settings.shim);
            				};
            				// apply position to 'active' elements
            				if (settings.apply_positioning && self.is('a, input') && (self.css('position') === '' || self.css('position') == 'static')){
            					self.css('position', 'relative');
            				};
            			});
            		};
            	});
            };
            
	jQuery.extend({
		random: function(X) {
		    return Math.floor(X * (Math.random() % 1));
		},
		randomBetween: function(MinV, MaxV) {
		  return MinV + jQuery.random(MaxV - MinV + 1);
		}
	});
	
	jQuery.fn.fadeIn = function(speed, callback) {
		return this.animate({opacity: 'show'}, speed, function() {
		if (jQuery.browser.msie)
		this.style.removeAttribute('filter');
		if (jQuery.isFunction(callback))
		callback();
		});
	};
	
	jQuery.fn.fadeOut = function(speed, callback) {
		return this.animate({opacity: 'hide'}, speed, function() {
		if (jQuery.browser.msie)
		this.style.removeAttribute('filter');
		if (jQuery.isFunction(callback))
		callback();
		});
	};
	
	jQuery.fn.fadeTo = function(speed,to,callback) {
		return this.animate({opacity: to}, speed, function() {
		if (to == 1 && jQuery.browser.msie)
		this.style.removeAttribute('filter');
		if (jQuery.isFunction(callback))
		callback();
		});
	};

	$toggle_caption = false;
	
	$(document).ready(function() {		
		$('#homeArea').supersleight();
		
		var min = 1;
		var max = 3;
		var slideSet = $.randomBetween(min, max);
		
		$('#gallery1').hide();
		$('#gallery2').hide();
		$('#gallery3').hide();
		
		
		//Execute the slideShow
		$('.slideShow').show();
		$('#gallery' + slideSet).show();
		slideShow(slideSet);
	
	});
	
	function slideShow(slideSet) {
		
		var cap2 = (slideSet * 2);
		var cap1 = (cap2 - 1);
		
		var gallery = '#gallery' + slideSet;
		var caption1 = '#caption' + cap1;
		var caption2 = '#caption' + cap2;
		
		if (jQuery.browser.msie) { 
			var opacityShow = 'show'; 
			var opacityHide = 'hide'; 
		}
		else { 
			var opacityShow = 0.85; 
			var opacityHide = 0.0; 
		}
		
		//alert('gallery:' + gallery + ' caption1:' + caption1 + ' caption2:' + caption2);
		
		//Set the opacity of all images to 0
		$(gallery + ' a').css({opacity: opacityHide});
		
		//Get the first image and display it (set it to full opacity)
		$(gallery + ' a:first').css({opacity: opacityShow}); 
		
		//Set the caption background to semi-transparent
		$(gallery + ' ' + caption1).css({opacity: opacityShow}); 
		
		//Hide and position secordary caption
		$(gallery + ' ' + caption2).css({opacity: opacityHide});
	
		//Resize the width of the caption according to the image width
		$(gallery + ' ' + caption1).css({width: $(gallery + ' a').find('img').css('width')});
		
		//Get the caption of the first image from REL attribute and display it
		if (jQuery.browser.msie) { 
			var caption = $(gallery + ' a.show').find('img').attr('rel');
			//var captionObj = document.getElementById(caption1);
			$(gallery + ' ' + caption1).css({opacity: opacityShow});
			$(gallery + ' ' + caption1).css({height: '45px'});
			$(gallery + ' ' + caption2).css({opacity: opacityHide});
			$(gallery + ' ' + caption2).css({height: '1px'});
			
			$(gallery + ' ' + caption1 + ' .content').html(caption);
			//captionObj.innerHTML = caption;
			$toggle_caption = false;
			//alert('gallery:' + gallery + ' caption1:' + caption1 + ' caption2:' + caption2);
		}
		else {
			$(gallery + ' ' + caption1 + ' .content').html($(gallery + ' a:first').find('img').attr('rel')).animate({opacity: opacityShow}, 500);
		}
		
		//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
		setInterval('gallery(' + slideSet + ')',6000);
		
	}

	function gallery(slideSet) {
		
		var cap2 = (slideSet * 2);
		var cap1 = (cap2 - 1);
		
		var gallery = '#gallery' + slideSet;
		var caption1 = '#caption' + cap1;
		var caption2 = '#caption' + cap2;
		
		//if no IMGs have the show class, grab the first image
		var current = ($(gallery + ' a.show') ?  $(gallery + ' a.show') : $(gallery + ' a:first'));
	
		//Get next image, if it reached the end of the slideshow, rotate it back to the first image
		var next = ((current.next('a').length) ? ( (current.next().hasClass('content')) ? $(gallery + ' a:first') : current.next() ) : $(gallery + ' a:first'));	
		
		//Get next image caption
		var caption = next.find('img').attr('rel');
		var slide = current.find('img').attr('alt');	
		
		//Set the fade in effect for the next image, show class has higher z-index
		if (jQuery.browser.msie) {
			next.css({opacity: 'hide'})
			.addClass('show')
			.fadeIn(500);
		}
		else {
			next.css({opacity: 0.0})
			.addClass('show')
			.animate({opacity: 0.85}, 500);
		}
		
		//Hide the current image
		if (jQuery.browser.msie) { 
			current.fadeOut(500)
			.removeClass('show');
		}
		else { 
			current.animate({opacity: 0.0}, 500)
			.removeClass('show');
		}
		
		if (caption == "") {
			//Animate the caption
			if ($toggle_caption) {
				//Set the opacity to 0 and height to 1px
				if (jQuery.browser.msie) {
					$(gallery + ' ' + caption2).fadeOut(500);
					$(gallery + ' ' + caption1).css({opacity: 'hide'});
				}
				else {
					$(gallery + ' ' + caption2).animate({opacity: 0.0},500).animate({height: '1px'},500);
					$(gallery + ' ' + caption1).css({opacity: 0.0});
				}
				$(gallery + ' ' + caption1).css({height: '1px'});
				$toggle_caption = false;
			}
			else {
				//Set the opacity to 0 and height to 1px
				//Adjust for IE
				if (jQuery.browser.msie) {
					$(gallery + ' ' + caption1).fadeOut(500);
					$(gallery + ' ' + caption2).css({opacity: 'hide'});
				}
				else {
					$(gallery + ' ' + caption1).animate({opacity: 0.0},500).animate({height: '1px'},500);
					$(gallery + ' ' + caption2).css({opacity: 0.0});
				}
				$(gallery + ' ' + caption2).css({height: '1px'});
				$toggle_caption = true;
			}
		}
		else {
			//Animate the caption
			if ($toggle_caption) {
				//Set the opacity to 0 and height to 1px
				//Adjust for IE
				if (jQuery.browser.msie) {
					$(gallery + ' ' + caption2).fadeOut(500);
					$(gallery + ' ' + caption2).css({opacity: 'hide'});
				}
				else {
					$(gallery + ' ' + caption2).animate({opacity: 0.0},500).animate({height: '1px'},500);
				}
				
				//Animate the caption, opacity to 0.7 and heigth to 45px, a slide up effect
				//$(gallery + ' ' + caption1).animate({opacity: 0.85},500).animate({height: '45px'},500 );
				$(gallery + ' ' + caption1).css({height: '45px'});
				if (jQuery.browser.msie) { 
					$(gallery + ' ' + caption1).fadeIn(500); 
				}
				else { 
					$(gallery + ' ' + caption1).animate({opacity: 0.85},500); 
				}
				
				//Display the content
				$(gallery + ' ' + caption1 + ' .content').html(caption);
				$toggle_caption = false;
			}
			else {
				//Set the opacity to 0 and height to 1px
				//Adjust for IE
				if (jQuery.browser.msie) {
					$(gallery + ' ' + caption1).fadeOut(500);
					$(gallery + ' ' + caption1).css({height: '1px'});
				}
				else {
					$(gallery + ' ' + caption1).animate({opacity: 0.0},500).animate({height: '1px'},500);
				}
				
				//Animate the caption, opacity to 0.7 and heigth to 45px, a slide up effect
				//$(gallery + ' ' + caption2).animate({opacity: 0.85},500).animate({height: '45px'},500 );
				$(gallery + ' ' + caption2).css({height: '45px'});
				if (jQuery.browser.msie) { 
					$(gallery + ' ' + caption2).fadeIn(500); 
				}
				else { 
					$(gallery + ' ' + caption2).animate({opacity: 0.85},500); 
				}
				
				//Display the content
				$(gallery + ' ' + caption2 + ' .content').html(caption);
				$toggle_caption = true;
			}
		}
		
	}