var ZSlideShowTimer = false;
var ZSlideShow;
var ZSlide = function(){
	this.current = 0;
	this.$thumbs = $('#filmstrip div');
	this.$thumbs_j = [];
	this.$panels = $('#banners div');
	this.$panels_j = [];
	this.cnt = this.$thumbs.size();
	this.dont = false;
	this.pointer = $("#pointer");

	for(var i = 0, to = this.cnt; i < to; i++)
	{
		var $thumb = $(this.$thumbs[i]);
		this.$thumbs_j.push($thumb);
		$thumb.attr('num', i);
		if(this.current !== i) $thumb.css({opacity: 0.5});
		$thumb.css({cursor: 'pointer'});
	}
	for(var i = 0, to = this.$panels.size(); i < to; i++)
	{
		var $panel = $(this.$panels[i]);
		$panel.css({
			position: 'relative',
			left: 0,
			top: -(i * 389)
		});
		this.$panels_j.push($panel);
		$panel.attr('num', i);
		if(this.current !== i) $panel.css({opacity: 0});
	}

	this.pointer.css({top: (this.current * 86)});


	this.init = function(){
		for(var i = 0; i < this.cnt; i++)
		{
			this.$thumbs_j[i].click((function(i){
				return function(){
					ZSlideShow.set(i);
				}
			})(i));
		}
	}

	this.init();

	this.set = function(i)
	{
		if(this.dont) return false;
		if(this.current == i) return true;
		else if(this.current > (this.cnt - 1) || this.current < 0) return false;

		this.dont = true;


		this.$thumbs_j[this.current].animate({opacity: 0.5}, 400);
		this.$panels_j[this.current].animate({opacity: 0}, 400);

		this.pointer.animate({top: (i * 86)}, 400);

		this.$thumbs_j[i].animate({opacity: 1}, 400);
		this.$panels_j[i].animate({opacity: 1}, 400, function(){
			ZSlideShow.dont = false;
		});
		this.current = i;
		return true;
	}

	this.next = function ()
	{
		var n = this.current >= (this.cnt - 1) ? 0 : (this.current + 1);
		ZSlideShow.set(n);
	}

	this.setTimer = function(){
		ZSlideShowTimer = setInterval(function(){
			ZSlideShow.next();
		}, 8000);
	}
	this.setTimer();

	this.clearTimer = function(){
		if(ZSlideShowTimer) clearInterval(ZSlideShowTimer);
	}

}
$(function(){
	ZSlideShow = new ZSlide();
	$("#gallery").mouseover(function(){
		ZSlideShow.clearTimer();
	});
	$("#gallery").mouseout(function(){
		ZSlideShow.setTimer();
	});


});
