
function EKCSlide ()
{
	this.id = "";
	this.left = 0;
	this.width = 0;
	this.index = -1
	
	this.SlideIn = function() {};
	this.SlideOut = function () {};
	this.Initialize = function () {};
}


/********************************************************/

function EKCScroller ()
{
	this.scrolling = false;	
	this._slidesHash = new EKCHashTable();
	this._slidesIndex = new Array();
	
	this.divContent = null;
	this.divViewer = null;
	this.imgLeftFlap = null;
	this.imgRightFlap = null;
	this.imgBackTip = null;
	this.imgNextTip = null;
	this.tabBackTip = null;
	this.tabNextTip = null;
	
	this.OnScroll = function() {};
	
	
	this.sepparatorWidth = 0;
	this.LogScrolling = false;
	
	
	this.pageSize = 641;
	this.speed = 0.5;
	this._currentSlide = null;
	this._initialized = false;
	
	
	this.Initialize = function()
	{
		if (!this._initialized)
		{
			for(var i=0; i<this._slidesIndex.length; i++)
			{
				slide = this._slidesIndex[i];
				slide.Initialize();
			}
			this._initialized = true;

			/*				
			new Effect.Fade(this.imgBackTip, {duration:0});
			new Effect.Fade(this.imgNextTip, {duration:0});
			this.imgBackTip.style.visibility = "visible";
			this.imgNextTip.style.visibility = "visible";
			this.ShowTips(0.5);
			*/
		}
	}
	
	Event.observe(window, "onload", this.Initialize.bindAsEventListener(this));
	
	
	this.ScrollToID = function(id)
	{
		if ((this._currentSlide == null) ||
			(this._currentSlide.id != id))
		{
		
			slide  = this._slidesHash.getItem(id);
			this.ScrollToSlide(slide);
			
		}
	}
	
	this.ScrollToIndex = function(index)
	{
		if ((this._currentSlide == null) ||
			(this._currentSlide.index != index))
		{
			slide  = this._slidesIndex[index];
			this.ScrollToSlide(slide);
		}
	}
	
	this.ScrollToSlide = function(slide)
	{
	
		if ((slide != null) && (this.divViewer) && (this.divContent))
		{
		
			
			//Rearrange the transparent side flaps (hot spots to browse)
			//And the next and back tips
			flapWidth = 
				parseFloat(this.divViewer.style.width)/2 
				- slide.width/2
				- this.sepparatorWidth;
			if (slide.index == 0)	
			{		
				this.imgLeftFlap.style.width = "0px";
				this.tabBackTip.style.left = "-1000px";
			}
			else	
			{
				this.imgLeftFlap.style.width = (flapWidth + "px");
				this.tabBackTip.style.left = ((parseFloat(this.divViewer.style.width) - slide.width - this.sepparatorWidth)/2 -1) + "px";
			}
				
			if (slide.index == (this._slidesIndex.length - 1))
			{
				this.imgRightFlap.style.width = "0px";
				this.imgRightFlap.style.left = this.divViewer.style.width;
				this.tabNextTip.style.left = "1000px";
			}
			else
			{
				this.imgRightFlap.style.width = (flapWidth + "px");
				this.imgRightFlap.style.left = (parseFloat(this.divViewer.style.width) - flapWidth) + "px";
				this.tabNextTip.style.left = ((parseFloat(this.divViewer.style.width) + slide.width)/2 +1) + "px";
			}
		
		
			//Move the slider		
			x =
				- slide.left 
				+ parseFloat(this.divViewer.style.width)/2 
				- slide.width/2;
			
			if (this._currentSlide != null)
				this._currentSlide.SlideOut();
			else
			{
			/*
				auxSlide = this.GetSlideByOffset(slide, -1);
				if (auxSlide != null)
					auxSlide.SlideOut();
				auxSlide = this.GetSlideByOffset(slide, 1);
				if (auxSlide != null)
					auxSlide.SlideOut();
					*/
			}

			this.ScrollToX(x);
			this._currentSlide = slide;		
			this._currentSlide.SlideIn();
			
			

			
			//Move the tips
			
			
			
		}
	}
	
	this.LaunchOnScroll = function()
	{
		if (this.OnScroll != null)
			this.OnScroll();
		//Set_Cookie('UserHasScrolled', 'true', 1000, '/','','');  
		if (this.LogScrolling == true)
			ReportAction("scroll");
	}
	
	this.ScrollBackward = function()
	{
		this.ScrollToOffset(-1);			
		this.LaunchOnScroll();
	}	

	this.ScrollForward = function()
	{
		this.ScrollToOffset(1);			
		this.LaunchOnScroll();
	}
	
	this.ScrollToOffset = function(offset)
	{
		if (this._currentSlide == null)
			index = 0;
		else
			index = this._currentSlide.index + offset;
		this.ScrollToIndex (index);
	}
	
	this.ScrollToX = function(x)
	{
		if (!this.scrolling)
		{
			this.FlagScrolling(true);
			if (this.divContent)
			{
				currentX = parseFloat(this.divContent.style.left);

				this.imgBackTip.style.display = "none";
				this.imgNextTip.style.display = "none";
				new Effect.Opacity(this.imgBackTip, {duration:0, from:1, to:0});
				new Effect.Opacity(this.imgNextTip, {duration:0, from:1, to:0});
				
				new Effect.Move(this.divContent, 
								{ x: x, 
								  y: 0, 
								  mode:'absolute',
								  transition: SmoothTransition,
								  duration: this.speed,
								  delay: 0.1,
								  afterFinish: this.FlagScrolling(false)
								 } );

				//if (this._initialized)
				//{
					this.ShowTips(0.5);
				//}
								  
								  
			}
		}
	}
	
	
	this.FlagScrolling = function(flag)
	{
		this.scrolling=flag
	}
	
	this.ShowTips = function(delay)
	{
		new Effect.Opacity(this.imgBackTip, {duration:0, from:0, to:0.01});
		new Effect.Opacity(this.imgNextTip, {duration:0, from:0, to:0.01});
	
	
		
		new Effect.Appear(this.imgBackTip, 
						{ from:0, 
						  to:1, 
						  duration:0.5,
						  delay: delay });
						  
		new Effect.Appear(this.imgNextTip, 
						{ from:0, 
						  to:1, 
						  duration:0.5,
						  delay: delay});
						  
		new Effect.Fade(this.imgBackTip, 
						{ from:1, 
						  to:0.2, 
						  duration:0.5,
						  delay: delay + 0.5 });
						  
		new Effect.Fade(this.imgNextTip, 
						{ from:1, 
						  to:0.2, 
						  duration:0.5,
						  delay: delay + 0.5 });
						  
	}
	
	this.AddSlide = function(slide)
	{
		i = this._slidesIndex.length;
		
		if (slide.id == "")
			slide.id = "SLIDE-" + i;
		
		this._slidesHash.setItem(slide.id, slide);
		this._slidesIndex[i] = slide;
		slide.index = i;
	}
}








