function ImageRotator(divGallery)
{
	this._divGallery = divGallery;
	this._slides = null;
	this._currentSlideIdx = 0;
	this._timeDelay = 4000;
	
	this.setup();
}

ImageRotator.prototype.setup = function()
{
	this._slides = $(this._divGallery).children("a");
	
	$(this._slides).lightBoxClone({fixedNavigation:true, });
	
	this._divGallery.height(this._divGallery.height());
	this._divGallery.width(this._divGallery.width());

	this._divGallery.css("position", "relative");
	$(this._divGallery).children("a").css("position", "absolute");
				
	var pos = $(this._divGallery).children("a").position();
	$(this._divGallery).children("a").css("left", pos.left);
	$(this._divGallery).children("a").css("top", pos.top);
	
	$(this._divGallery).append("<div class='slideIdx quiet'></div>");
	// console.log($(this.di))
	$(this._divGallery).children(".slideIdx")
		.css("position", "absolute")
		.css("bottom", "-25px")
		.css("right", "0px")
		.html("Image " + (this._currentSlideIdx+1) + " of " + this._slides.length);
		
	var thisObj = this;
	$(this._divGallery).append("<img class='zoom_img' src='images/search_48.png' width=48px height=48px />");
	$(this._divGallery).children(".zoom_img")
		.css("position", "absolute")
		.css("right", "10px")
		.css("top", "10px")
		.css("border", "0")
		.css("opacity", "0.5")
		.mouseover(function(){
			$(this).css("opacity", "1.0");
		})
		.mouseout(function(){
			$(this).css("opacity", "0.5");
		})
		.click(function(){
			$(thisObj._slides[thisObj._currentSlideIdx]).click();
		});
	
	
	$(this._divGallery).mouseover(function(){thisObj.stopSlideShow()});
	$(this._divGallery).mouseleave(function(){thisObj.resumeSlideShow()});
	
	this.startSlideShow();
}

ImageRotator.prototype.startSlideShow = function()
{
	var thisObj = this;
	$(this._divGallery).oneTime(this._timeDelay, function(){thisObj.changeSlide()});
}

ImageRotator.prototype.stopSlideShow = function()
{
	$(this._divGallery).stopTime();
}

ImageRotator.prototype.resumeSlideShow = function()
{
	this.startSlideShow();
}

ImageRotator.prototype.changeSlide = function()
{
	var currentSlide = this._slides[this._currentSlideIdx]
	
	if (this._currentSlideIdx == this._slides.length - 1)
		this._currentSlideIdx = 0;
	else
		this._currentSlideIdx++;
	
	var nextSlide = this._slides[this._currentSlideIdx];
	
	$(currentSlide).fadeOut();
	$(nextSlide).fadeIn();
	
	$(this._divGallery).children(".slideIdx").html("Image " + (this._currentSlideIdx+1) + " of " + this._slides.length);
	
	this.startSlideShow();
}

$(function(){

	$("#sidebar").mouseenter(function(){
		$(this).fadeTo("fast", 1.0);
	})
	.mouseleave(function(){
		$(this).fadeTo("fast", 0.5);
	});
	
	$("#menu li a").mouseover(function(){
	    if (!$(this).parent().hasClass("here"))
            $(this).animate({color: "#F0A830"});
	})
	.mouseleave(function(){
	    if (!$(this).parent().hasClass("here"))
    	    $(this).animate({color: "#78C0A8"});
	});
});
