igalleryClass = new Class
({

initialize: function(preload,lboxPreload,host,galleryFolder,numPics,thumbContainer,
lboxThumbContainer,thumbTable,lboxThumbTable,desContainer,lboxDesContainer,
largeImgDiv,lboxLargeImgDiv,scrollBoundry,scrollSpeed,
lboxScrollBoundry,lboxScrollSpeed,fade,lboxFade,lightbox,
lightboxWidth,showScrollBar,showLboxScrollBar,desScrollBack,desScrollHandle,
lboxDesScrollBack,lboxDesScrollHandle,thumbScrollBack,thumbScrollHandle,
lboxThumbScrollBack,lboxThumbScrollHandle,thumbVScrollBack,thumbVScrollHandle,
lboxThumbVScrollBack,lboxThumbVScrollHandle,darkDiv,whiteDiv,closeImage,upArrow,
downArrow,leftArrow,rightArrow,lboxUpArrow,lboxDownArrow,lboxLeftArrow,lboxRightArrow,
showUpDown,showLeftRight,lboxShowUpDown,lboxShowLeftRight,magnify,scrollLeftArrow,
scrollRightArrow,scrollUpArrow,scrollDownArrow,lboxScrollLeftArrow,lboxScrollRightArrow,
lboxScrollUpArrow,lboxScrollDownArrow,desUpArrow,desDownArrow,
lboxDesUpArrow,lboxDesDownArrow)
{
	
	
	this.preload = preload;
	this.lboxPreload = lboxPreload;
	this.host = host;
	this.galleryFolder = galleryFolder;
	this.numPics = numPics;
	this.thumbContainer = thumbContainer;
	this.lboxThumbContainer = lboxThumbContainer;
	this.thumbTable = thumbTable;
	this.lboxThumbTable = lboxThumbTable;
	this.desContainer = desContainer;
	this.lboxDesContainer = lboxDesContainer;
	this.largeImgDiv = largeImgDiv;
	this.lboxLargeImgDiv = lboxLargeImgDiv;
	this.scrollBoundry = scrollBoundry;
	this.scrollSpeed = scrollSpeed;
	this.lboxScrollBoundry = lboxScrollBoundry;
	this.lboxScrollSpeed = lboxScrollSpeed;
	this.fade = fade;
	this.lboxFade = lboxFade;
	this.lightbox = lightbox;
	this.lightboxWidth = lightboxWidth;
	this.showScrollBar = showScrollBar;
	this.showLboxScrollBar = showLboxScrollBar;
	this.desScrollBack = desScrollBack;
	this.desScrollHandle = desScrollHandle;
	this.lboxDesScrollBack = lboxDesScrollBack;
	this.lboxDesScrollHandle = lboxDesScrollHandle;
	this.thumbScrollBack = thumbScrollBack;
	this.thumbScrollHandle = thumbScrollHandle;
	this.lboxThumbScrollBack = lboxThumbScrollBack;
	this.lboxThumbScrollHandle = lboxThumbScrollHandle;
	this.thumbVScrollBack = thumbVScrollBack;
	this.thumbVScrollHandle = thumbVScrollHandle;
	this.lboxThumbVScrollBack = lboxThumbVScrollBack;
	this.lboxThumbVScrollHandle = lboxThumbVScrollHandle;
	this.darkDiv = darkDiv;
	this.whiteDiv = whiteDiv;
	this.closeImage = closeImage;
	this.upArrow = upArrow;
	this.downArrow = downArrow;
	this.leftArrow = leftArrow;
	this.rightArrow = rightArrow;
	this.lboxUpArrow = lboxUpArrow;
	this.lboxDownArrow = lboxDownArrow;
	this.lboxLeftArrow = lboxLeftArrow;
	this.lboxRightArrow = lboxRightArrow;
	this.showUpDown = showUpDown;
	this.showLeftRight = showLeftRight;
	this.lboxShowUpDown = lboxShowUpDown;
	this.lboxShowLeftRight = lboxShowLeftRight;
	this.magnify = magnify;
	this.scrollLeftArrow = scrollLeftArrow;
	this.scrollRightArrow = scrollRightArrow;
	this.scrollUpArrow = scrollUpArrow;
	this.scrollDownArrow = scrollDownArrow;
	this.lboxScrollLeftArrow = lboxScrollLeftArrow;
	this.lboxScrollRightArrow = lboxScrollRightArrow;
	this.lboxScrollUpArrow = lboxScrollUpArrow;
	this.lboxScrollDownArrow = lboxScrollDownArrow;
	this.desUpArrow = desUpArrow;
	this.desDownArrow = desDownArrow;
	this.lboxDesUpArrow = lboxDesUpArrow;
	this.lboxDesDownArrow = lboxDesDownArrow;

	
	this.thumbPathsArray = $(this.thumbTable).getElements('img');
	this.imgFileNameArray = new Array();
	
	this.thumbPathsArray.each(function(el,index)
	{
		this.imgPathParts = el.src.split("/");
		this.imgFileName = this.imgPathParts.pop();
		this.imgFileNameArray[index] = this.imgFileName;
	}.bind(this));
	
	if(this.lightbox == 1)
	{	
			this.lboxBehaviors = new addBehaviors(this.lboxThumbContainer,this.lboxScrollBoundry,this.lboxScrollSpeed,
			this.lboxThumbTable,this.lboxFade,false,this.lboxLargeImgDiv,this.host,this.galleryFolder,
			'lightbox',this.imgFileNameArray,this.lightbox,this.lboxDesContainer,
			this.lightboxWidth,this.lboxDesScrollBack,this.lboxDesScrollHandle,this.darkDiv,
			this.whiteDiv,this.closeImage,this.lboxLargeImgDiv,this.lboxPreload,
			this.lboxUpArrow,this.lboxDownArrow,this.lboxLeftArrow,this.lboxRightArrow,
			this.lboxShowUpDown,this.lboxShowLeftRight,this.lboxThumbScrollBack,this.lboxThumbScrollHandle,
			this.lboxThumbVScrollBack,this.lboxThumbVScrollHandle,null,0,
			this.lboxScrollLeftArrow,this.lboxScrollRightArrow,this.lboxScrollUpArrow,
			this.lboxScrollDownArrow,this.lboxDesUpArrow,this.lboxDesDownArrow,this.numPics,
			this.lboxPreload,this.lboxThumbScrollHandle,this.lboxThumbVScrollHandle,this.lboxDesContainer);
		
	}
	
	new Asset.images([this.host + 'images/stories/igallery/' + this.galleryFolder + '/large/' + this.imgFileNameArray[0] ], 
	{
		onComplete: function()
		{
			$(this.largeImgDiv).setHTML('<img src="' + this.host + 'images/stories/igallery/' + this.galleryFolder + '/large/' + this.imgFileNameArray[0] + '" class="large_img" />');
			
			
			
			
			this.mainBehaviors = new addBehaviors(this.thumbContainer,this.scrollBoundry,this.scrollSpeed,
			this.thumbTable,this.fade,true,this.largeImgDiv,this.host,this.galleryFolder,
			'large',this.imgFileNameArray,this.lightbox,this.desContainer,
			this.lightboxWidth,this.desScrollBack,this.desScrollHandle,this.darkDiv,this.whiteDiv,
			this.closeImage,this.lboxLargeImgDiv,this.preload,this.upArrow,this.downArrow,
			this.leftArrow,this.rightArrow,this.showUpDown,this.showLeftRight,this.thumbScrollBack,
			this.thumbScrollHandle,this.thumbVScrollBack,this.thumbVScrollHandle,null,this.magnify,
			this.scrollLeftArrow,this.scrollRightArrow,this.scrollUpArrow,
			this.scrollDownArrow,this.desUpArrow,this.desDownArrow,this.numPics,
			this.lboxPreload,this.lboxThumbScrollHandle,this.lboxThumbVScrollHandle,this.lboxDesContainer);
			
			this.imgToChain = $(this.largeImgDiv).getElement('img');
			this.imgChain = new Fx.Style(this.imgToChain, 'opacity',{duration:200}).start(1,1).chain(function()
			{
				if (this.magnify == 1) 
				{
					this.mainBehaviors.insertMagnify();
				}
				
			}.bind(this));
			
			
			this.firstThumbLink = $(this.thumbTable).getElement('a')
			//this.linkClass = this.firstThumbLink.getProperty('class');
			//this.linkTarget = this.firstThumbLink.getProperty('target');
			
				
			if(this.linkClass == 'picture_link')
			{	
				$(this.largeImgDiv).setStyle('cursor', 'pointer');
				
				$(this.largeImgDiv).removeEvents('click');
				
				$(this.largeImgDiv).addEvent('click', function(e)
				{
					if (this.linkTarget == '_blank') 
					{
						window.open(this.firstThumbLink);
					}
					else
					{
						window.location = this.firstThumbLink;
					}
				}.bind(this));
			}
				
			if(this.lightbox == 1)
			{
				
				if(this.linkClass == 'no_link' )
				{
					$(this.largeImgDiv).removeEvents('click');
					
					$(this.largeImgDiv).setStyle('cursor', 'pointer');
					
					$(this.largeImgDiv).addEvent('click', function(e)
					{	
						this.mainBehaviors.igniteLightBox(0);
						
						this.lboxDesScrollbar = new scrollBarClass(this.lboxDesContainer,this.lboxDesScrollBack,this.lboxDesScrollHandle,'y','vertical','top');
			
						if(this.showLboxScrollBar == 1)
						{
							this.LboxHScrollbar = new scrollBarClass(this.lboxThumbContainer,this.lboxThumbScrollBack,this.lboxThumbScrollHandle,'x','horizontal','left');
							this.LboxVScrollbar = new scrollBarClass(this.lboxThumbContainer,this.lboxThumbVScrollBack,this.lboxThumbVScrollHandle,'y','vertical','top');
						}
					}.bind(this));
				}
			
			}
			
		}.bind(this)
	});
	
	
	this.mainDesScrollbar = new scrollBarClass(this.desContainer,this.desScrollBack,this.desScrollHandle,'y','vertical','top');
	if(this.showScrollBar == 1)
	{
		this.mainThumbHScrollbar = new scrollBarClass(this.thumbContainer,this.thumbScrollBack,this.thumbScrollHandle,'x','horizontal','left');
		this.mainThumbVScrollbar = new scrollBarClass(this.thumbContainer,this.thumbVScrollBack,this.thumbVScrollHandle,'y','vertical','top');
	}
	
}


});//end igallery class

addBehaviors = new Class
({

initialize: function(thumbContainer,scrollBoundry,scrollSpeed,thumbTable,fade,main,
largeImgDiv,host,galleryFolder,imageFolder,imgFileNameArray,lightbox,desContainer,
lightboxWidth,scrollBack,scrollHandle,darkDiv,whiteDiv,closeImage,lboxLargeImgDiv,preload,
upArrow,downArrow,leftArrow,rightArrow,showUpDown,showLeftRight,thumbScrollBack,thumbScrollHandle,
thumbVScrollBack,thumbVScrollHandle,lboxObject,magnify,scrollLeftArrow,
scrollRightArrow,scrollUpArrow,scrollDownArrow,desUpArrow,desDownArrow,numPics,
lboxPreload,lboxTScrollHandle,lboxTVScrollHandle,lboxDesContainer)
{
	
	this.thumbContainer = thumbContainer;
	this.scrollBoundry = scrollBoundry;
	this.scrollSpeed = scrollSpeed;
	this.thumbTable = thumbTable;
	this.fade = fade;
	this.main = main;
	this.largeImgDiv = largeImgDiv;
	this.host = host;
	this.galleryFolder = galleryFolder;
	this.imageFolder = imageFolder;
	this.imgFileNameArray = imgFileNameArray;
	this.lightbox = lightbox;
	this.desContainer = desContainer;
	this.lightboxWidth = lightboxWidth;
	this.desScrollBack = scrollBack;
	this.desScrollHandle = scrollHandle;
	this.darkDiv = darkDiv;
	this.whiteDiv = whiteDiv;
	this.closeImage = closeImage;
	this.lboxLargeImgDiv = lboxLargeImgDiv;
	this.preload = preload;
	this.upArrow = upArrow;
	this.downArrow = downArrow;
	this.leftArrow = leftArrow;
	this.rightArrow = rightArrow;
	this.showUpDown = showUpDown;
	this.showLeftRight = showLeftRight;
	this.thumbScrollBack = thumbScrollBack;
	this.thumbScrollHandle = thumbScrollHandle;
	this.thumbVScrollBack = thumbVScrollBack;
	this.thumbVScrollHandle = thumbVScrollHandle;
	this.lboxObject = lboxObject;
	this.magnify = magnify;
	this.scrollLeftArrow = scrollLeftArrow;
	this.scrollRightArrow = scrollRightArrow;
	this.scrollUpArrow = scrollUpArrow;
	this.scrollDownArrow = scrollDownArrow;
	this.desUpArrow = desUpArrow;
	this.desDownArrow = desDownArrow;
	this.numPics = numPics;
	this.lboxPreload = lboxPreload;
	this.lboxTScrollHandle = lboxTScrollHandle;
	this.lboxTVScrollHandle = lboxTVScrollHandle;
	this.lboxDesContainer = lboxDesContainer;
	
	
	this.thumbScroller = new iScroller(this.thumbContainer, {area: this.scrollBoundry, velocity: this.scrollSpeed,
	thumbTable: this.thumbTable, scrollBack: this.thumbScrollBack, scrollHandle: this.thumbScrollHandle,
	scrollBack: this.thumbScrollBack, scrollHandle: this.thumbScrollHandle, scrollVBack: this.thumbVScrollBack, 
	scrollVHandle: this.thumbVScrollHandle,
		onChange : function(x,y)
		{
			this.scrollBackSizeArray = $(this.options.scrollBack).getSize();
			this.scrollBackWidth = this.scrollBackSizeArray.size.x;
			
			this.scrollBackVSizeArray = $(this.options.scrollVBack).getSize();
			this.scrollBackHeight = this.scrollBackVSizeArray.size.y
			
			this.thumbTableSizeArray = $(this.options.thumbTable).getSize();
			this.thumbTableWidth = this.thumbTableSizeArray.size.x;
			this.thumbTableHeight = this.thumbTableSizeArray.size.y;
			
			
			this.handlescrollX = (x/(this.thumbTableWidth - this.scrollBackWidth) ) * this.scrollBackWidth * 1.25;
			if(this.handlescrollX > (this.scrollBackWidth -14))
			{
				this.handlescrollX = (this.scrollBackWidth -14);
			}
			if(this.handlescrollX < 0)
			{
				this.handlescrollX = 0;
			}
			
			this.handlescrollY = (y/(this.thumbTableHeight - this.scrollBackHeight) ) * this.scrollBackHeight * 1.25;
			if(this.handlescrollY > (this.scrollBackHeight -14))
			{
				this.handlescrollY = (this.scrollBackHeight -14);
			}
			if(this.handlescrollY < 0)
			{
				this.handlescrollY = 0;
			}
			
			this.element.scrollTo(x,y);
			$(this.options.scrollHandle).setStyle('left',this.handlescrollX);
			$(this.options.scrollVHandle).setStyle('top',this.handlescrollY);
	    } 
	});
	$(this.thumbTable).addEvent('mouseenter', this.thumbScroller.start.bind(this.thumbScroller));
	$(this.thumbTable).addEvent('mouseleave', this.thumbScroller.stop.bind(this.thumbScroller));
	
	this.linksArray = $(this.thumbTable).getElements('a');
	
	if(this.preload == 1 && this.main == 1)
	{
		this.counter = 0;
		this.preloaderClass = new preloaderClass(this.host,this.galleryFolder,'large',this.imgFileNameArray,this.numPics);
	}

	
	if(this.showUpDown == 1)
	{
		this.upArrowScrollClass = new addArrowBehaviors(this.upArrow, -150,'vertical',this.thumbContainer,this.thumbVScrollBack,this.thumbVScrollHandle);
		this.downArrowScrollClass = new addArrowBehaviors(this.downArrow, 150,'vertical',this.thumbContainer,this.thumbVScrollBack,this.thumbVScrollHandle);
	}	    
			
	if(this.showLeftRight == 1)
	{
		this.rightArrowScrollClass = new addArrowBehaviors(this.rightArrow, 280,'horizontal',this.thumbContainer,this.thumbScrollBack,this.thumbScrollHandle);
		this.leftArrowScrollClass = new addArrowBehaviors(this.leftArrow, -280,'horizontal',this.thumbContainer,this.thumbScrollBack,this.thumbScrollHandle);
	}
	
	this.rightThumbScrollClass = new addArrowBehaviors(this.scrollRightArrow, 250,'horizontal',this.thumbContainer,this.thumbScrollBack,this.thumbScrollHandle);
	this.leftThumbScrollClass = new addArrowBehaviors(this.scrollLeftArrow, -250,'horizontal',this.thumbContainer,this.thumbScrollBack,this.thumbScrollHandle);
	
	this.upThumbScrollClass = new addArrowBehaviors(this.scrollUpArrow, -250,'vertical',this.thumbContainer,this.thumbVScrollBack,this.thumbVScrollHandle);
	this.downThumbScrollClass = new addArrowBehaviors(this.scrollDownArrow, 250,'vertical',this.thumbContainer,this.thumbVScrollBack,this.thumbVScrollHandle);
	this.upDesScrollClass = new addArrowBehaviors(this.desUpArrow, -250,'vertical',this.desContainer,this.desScrollBack,this.desScrollHandle);
	this.downDesScrollClass = new addArrowBehaviors(this.desDownArrow, 250,'vertical',this.desContainer,this.desScrollBack,this.desScrollHandle);
	
	
	
	this.enlarge = this.magnify;
	
	this.linksArray.each(function(el,index)
	{	
		el.addEvent('click', function(e)
		{	
			e = new Event(e).stop();
			
			if(this.fade == 1)
			{
				if(this.main == true)
				{
					if (this.enlarge == 1) 
					{
						$('magnifygif').remove();
					}
				}
				
				this.imageToFadeOut = $(this.largeImgDiv).getElement('img[class=large_img]');
				this.imageToFadeLeft = this.imageToFadeOut.getLeft();
				this.containerLeft = $(this.largeImgDiv).getLeft();
				this.leftMargin = this.imageToFadeLeft - this.containerLeft;
				
				this.containerTr = $(this.largeImgDiv).getParent();
				this.containerSection = this.containerTr.getParent();
				this.containerTable = this.containerSection.getParent();
			
				this.mainImageTop = this.imageToFadeOut.getTop();
				this.containerTop = this.containerTable.getTop();
				this.topMargin = this.mainImageTop - this.containerTop;
				
				this.imageToFadeOut.setStyles
				({
					position: 'absolute',
					top: this.topMargin,
					left: this.leftMargin
				});
				
				this.imageFadeAway = new Fx.Style(this.imageToFadeOut, 'opacity').start(1,0).chain(function()
				{
					this.imageToFadeOut.remove();
				}.bind(this));
				
				this.imageToFadeIn = new Asset.images([this.host + 'images/stories/igallery/' + this.galleryFolder + '/' + this.imageFolder + '/' + this.imgFileNameArray[index] ], 
				{
					onComplete: function()
					{	
						this.imageToFadeInEl = new Element('img', 
						{
					    	'src': null
						});
						
						this.imageToFadeInEl.setStyle('opacity',0);
						this.imageToFadeInEl.injectTop(this.largeImgDiv);
						this.imageToFadeInEl.setProperty('src', this.host + 'images/stories/igallery/' + this.galleryFolder + '/' + this.imageFolder + '/' + this.imgFileNameArray[index]);
						this.imageToFadeInEl.setProperty('class', 'large_img');
						this.imageFadeIn = new Fx.Style(this.imageToFadeInEl, 'opacity').start(0,1).chain(function()
						{
							if(this.main == true)
							{
								if (this.enlarge == 1) 
								{
									this.insertMagnify();
								}
							}
						}.bind(this));
						
					}.bind(this)
		    	});
			}
			else
			{
				$(this.largeImgDiv).setHTML('<img src="' + this.host + '/components/com_igallery/images/loader.gif" />');
				
	
				new Asset.images([ this.host + 'images/stories/igallery/' + this.galleryFolder + '/' + this.imageFolder + '/' + this.imgFileNameArray[index] ], 
				{
					onComplete: function()
					{
						$(this.largeImgDiv).setHTML('<img src="' + this.host + 'images/stories/igallery/' + this.galleryFolder + '/' + this.imageFolder + '/' + this.imgFileNameArray[index] +  '" />');
						
						this.imgToChain = $(this.largeImgDiv).getElement('img');
						this.imgChain = new Fx.Style(this.imgToChain, 'opacity',{duration:200}).start(1,1).chain(function()
						{
							if(this.main == true)
							{
								if (this.enlarge == 1) 
								{
									this.insertMagnify();
								}
							}
						}.bind(this));
						
					}.bind(this)
		    	});
			}
			
			if (this.main == true)
			{
				
				this.linkClass = el.getProperty('class');
				this.linkTarget = el.getProperty('target');
				if(this.linkClass == 'picture_link')
				{	
					$(this.largeImgDiv).setStyle('cursor', 'pointer');
					$(this.largeImgDiv).removeEvents('click');
					$(this.largeImgDiv).addEvent('click', function(e)
					{
						if (this.linkTarget == '_blank') 
						{
							window.open(el);
						}
						else
						{
							window.location = el;
						}
						
					}.bind(this));
				}
				
				if(this.lightbox == 1 && this.linkClass == 'no_link' )
				{
					$(this.largeImgDiv).removeEvents('click');
					
					$(this.largeImgDiv).setStyle('cursor', 'pointer');
					
					$(this.largeImgDiv).addEvent('click', function(e)
					{	
						this.igniteLightBox(index);
					}.bind(this));
				}
			}

			
			this.descriptionDivs = $(this.desContainer).getElements('div[class=des_div]');
			
			this.descriptionDivs.each(function(el,index)
			{
				el.setStyle('display', 'none');
			});
			
			
			$(this.desContainer).scrollTo(0,0);
			this.descriptionDivs[index].setStyle('display', 'block');
			this.desScrollbar = new scrollBarClass(this.desContainer,this.desScrollBack,this.desScrollHandle,'y','vertical','top');
					
		}.bind(this));
	}.bind(this));
},


insertMagnify : function()
{
	this.mainImage = $(this.largeImgDiv).getElement('img');
	this.mainImageLeft = this.mainImage.getLeft();
	this.containerLeft = $(this.largeImgDiv).getLeft();
	this.leftMargin = this.mainImageLeft - this.containerLeft;
	
	this.imgSizeArray = this.mainImage.getSize();
	this.imgWidth = this.imgSizeArray.size.x;
	this.imgHeight = this.imgSizeArray.size.y;
	
	this.containerTr = $(this.largeImgDiv).getParent();
	this.containerSection = this.containerTr.getParent();
	this.containerTable = this.containerSection.getParent();

	this.mainImageTop = this.mainImage.getTop();
	this.containerTop = this.containerTable.getTop();
	this.mainImageTopMargin = this.mainImageTop - this.containerTop;
	
	this.magnifyMarginLeft = this.leftMargin + this.imgWidth - 27;
	this.magnifyMarginTop = this.imgHeight + this.mainImageTopMargin - 20;
	
	
	this.magnify = new Asset.images([this.host + 'components/com_igallery/images/magnify.gif' ], 
	{
		onComplete: function()
		{
			this.magnify[0].injectTop(this.largeImgDiv).setStyles
			({
				position: 'absolute',
				top: this.magnifyMarginTop,
				left: this.magnifyMarginLeft,
				'z-index': 1020,
				opacity: 0
			});
			this.magnify[0].setProperty('id', 'magnifygif');
			
			if (this.fade == 1) 
			{
				this.magnifyFadeIn = new Fx.Style(this.magnify[0], 'opacity').set(0.5);
			}
			if (this.fade == 0)
			{
				this.magnifyFadeIn = new Fx.Style(this.magnify[0], 'opacity').set(0.5);
			}
		}.bind(this)
	});
},

igniteLightBox : function(index)
{
	if(this.lboxPreload == 1)
	{
		this.counter = 0;
		this.lboxPreloaderClass = new preloaderClass(this.host,this.galleryFolder,'lightbox',this.imgFileNameArray,this.numPics);
	}
	
	$(this.lboxTVScrollHandle).setStyle('top', 0);
	$(this.lboxTScrollHandle).setStyle('left', 0);
	
	this.bodyTag = document.getElementsByTagName("body").item(0);
	this.scrolledDown = Window.getScrollTop();
	this.totalScrollHeight = Window.getScrollHeight();
	this.totalWidth = Window.getWidth();
	this.whiteDivLeftMargin = (this.totalWidth/2) - ( (this.lightboxWidth)/2);
	
	
	$(this.whiteDiv).injectTop(this.bodyTag);
	
	$(this.whiteDiv).setStyles
	({
		'top': this.scrolledDown + 30,
        'left': this.whiteDivLeftMargin,
        'opacity': '0',
		'display': 'block',
		'z-index': 1040
	});
	
	this.scrolledDown = Window.getScrollTop();
	this.totalScrollHeight = Window.getScrollHeight();
	this.totalWidth = Window.getWidth();
	$(this.darkDiv).injectTop(this.bodyTag);
	
	$(this.darkDiv).setStyles
	({
		'width': this.totalWidth,
        'height': this.totalScrollHeight + 30,
        'top': '0px',
        'left': '0px',
        'opacity': '0',
		'display': 'block',
		'z-index': 1030
	});
	
	this.darkDivFadeIn = new Fx.Style($(this.darkDiv), 'opacity').start(0,.7);
	this.whiteDivFadeIn = new Fx.Style($(this.whiteDiv), 'opacity').start(0,1);
	
	this.lboxImageToFadeIn = new Asset.images([ this.host + 'images/stories/igallery/' + this.galleryFolder + '/lightbox/' + this.imgFileNameArray[index] ], 
	{
		onComplete: function()
		{
			this.lboxImageToFadeIn[0].injectTop(this.lboxLargeImgDiv).setStyles('opacity: 0;');
			this.lboxImageFadeIn = new Fx.Style(this.lboxImageToFadeIn[0], 'opacity').start(0,1);
			this.lboxImageToFadeIn[0].setProperty('class', 'large_img');
		}.bind(this)
	});
	
	this.lboxDescriptionDivs = $(this.lboxDesContainer).getElements('div[class=des_div]');
	this.lboxDescriptionDivs.each(function(el,index)
	{
		el.setStyle('display', 'none');
	});
	$(this.lboxDesContainer).scrollTo(0,0);
	this.lboxDescriptionDivs[index].setStyle('display', 'block');
	
	$(this.closeImage).addEvent('click', function(e)
	{
		this.darkFadeOut = new Fx.Style($(this.darkDiv), 'opacity').start(0.7,0).chain(function()
		{
			$(this.darkDiv).setStyle('display','none');
		}.bind(this));
		
		this.whiteFadeOut = new Fx.Style($(this.whiteDiv), 'opacity').start(1,0).chain(function()
		{
			$(this.lboxLargeImgDiv).setHTML('');
			$(this.whiteDiv).setStyle('display','none');
			
		}.bind(this));
		
	}.bind(this));
	
	
}

});//end addBehaviors class

addArrowBehaviors = new Class
({
    initialize: function(arrow, pixels, mode, container, scrollBack, handle)
    {
    	this.arrow = arrow;
    	this.pixels = pixels;
        /*  this.pixels = 280;*/
    	this.mode = mode;
		this.container = container;
		this.scrollBack = scrollBack;
		this.handle = handle;
		
		this.arrowScroller = new Fx.Scroll(this.container);
		
		$(this.arrow).addEvent('click', function(e)
		{
			this.containerSizeArray = $(this.container).getSize();
			this.currentScrollX = this.containerSizeArray.scroll.x;
			this.currentScrollY = this.containerSizeArray.scroll.y;
			this.contentWidth = this.containerSizeArray.scrollSize.x;
			this.contentHeight = this.containerSizeArray.scrollSize.y;
			
			if (this.mode == 'horizontal') 
			{
				this.arrowScroller.scrollTo(this.currentScrollX + this.pixels, this.currentScrollY);
			}
			
			if (this.mode == 'vertical') 
			{
				this.arrowScroller.scrollTo(this.currentScrollX, this.currentScrollY + this.pixels);
			}
			
			if (this.mode == 'horizontal') 
			{
				this.scrollBackSizeArray = $(this.scrollBack).getSize();
				this.scrollBackWidth = this.scrollBackSizeArray.size.x;
			}
			
			if (this.mode == 'vertical') 
			{
				this.scrollBackSizeArray = $(this.scrollBack).getSize();
				this.scrollBackHeight = this.scrollBackSizeArray.size.y;
			}
			
			if (this.mode == 'horizontal') 
			{
				this.handlescrollX = ((this.currentScrollX + this.pixels) / (this.contentWidth - this.scrollBackWidth)) * this.scrollBackWidth;
				if (this.handlescrollX > this.scrollBackWidth) 
				{
					this.handlescrollX = this.scrollBackWidth - 14;
				}
				if (this.handlescrollX < 0) 
				{
					this.handlescrollX = 0;
				}
				
				$(this.handle).setStyle('left', this.handlescrollX);
			}
			if(mode == 'vertical') 
			{
				this.handlescrollY = ( (this.currentScrollY + this.pixels) / (this.contentHeight - this.scrollBackHeight)) * this.scrollBackHeight;
				
				if (this.handlescrollY > this.scrollBackHeight) 
				{
					this.handlescrollY = this.scrollBackHeight -14;
				}
				if (this.handlescrollY < 0) 
				{
					this.handlescrollY = 0;
				}
				$(this.handle).setStyle('top', this.handlescrollY);
			}
			
	    }.bind(this));
    }
});

scrollBarClass = new Class
({
    initialize: function(container,scrollBarBack,handle,xy,mode,topLeft)
    {
        this.container = container;
        this.scrollBarBack = scrollBarBack;
        this.handle = handle;
        this.mode = mode;
        this.xy = xy;
        this.topLeft = topLeft;
        
        this.containerTd = $(this.scrollBarBack).getParent();
		this.containerTr = this.containerTd.getParent();
		this.containerSection = this.containerTr.getParent();
		this.containerTable = this.containerSection.getParent();
		
        this.SizeArray = $(this.container).getSize();
        
        if(this.xy == 'y')
        {
            this.ScrollLength = this.SizeArray.scrollSize.y;
            this.BoxLength = this.SizeArray.size.y;
		}
        
        if(this.xy == 'x')
        {
            this.ScrollLength = this.SizeArray.scrollSize.x;
            this.BoxLength = this.SizeArray.size.x;
        }
        
		if(this.ScrollLength > this.BoxLength)
		{
			
			$(this.containerTable).setStyle('display', 'block');
			
			this.ScrollBarSlider = new Slider(this.scrollBarBack, this.handle, 
			{
				steps: 100,
				offset: 0,
				mode: this.mode,
			 
			    onChange: function(step)
			    {
			    	if(this.mode == 'vertical')
        			{
        				
			    		$(this.container).scrollTo(0,step * ( (this.ScrollLength - this.BoxLength) /100) );
			    	}
			    	
			    	if(this.mode == 'horizontal')
        			{
			    		$(this.container).scrollTo(step * ( (this.ScrollLength - this.BoxLength) /100),0 );
			    	}
			    	
        		}.bind(this),
			    
			    onTick: function(pos)
			    {
					this.knob.setStyle(this.Topleft, pos);
			    }.bind(this)
		    
			});
		}
		else
		{
			this.containerTable.setStyle('display', 'none');
		};
	}
    
});

preloaderClass = new Class
({
    initialize: function(host,galleryFolder,imageFolder,imgFileNameArray,numPics)
    {
    	this.host = host;
    	this.galleryFolder = galleryFolder;
    	this.imageFolder = imageFolder;
    	this.imgFileNameArray = imgFileNameArray;
    	this.numPics = numPics;
    	
    	this.counter = 0;
    	this.preloaderVar = this.preloaderFunction.periodical(750, this);
    },
    
    preloaderFunction : function()
	{
    	new Asset.images([this.host + 'images/stories/igallery/' + this.galleryFolder + '/' + this.imageFolder + '/' + this.imgFileNameArray[this.counter] ],
		{
		    onComplete: function()
		    {
				
		    }
		});
		
		this.counter++;
		if(this.counter == this.numPics)
		{
			$clear(this.preloaderVar);
		}
		
    }
    
});


var iScroller = new Class({

	options: 
	{
		area: 20,
		velocity: 1,
		thumbTable: null,
		scrollBack: null,
		scrollHandle: null,
		scrollVBack: null,
		scrollVHandle: null,
		onChange: function(x, y)
		{
			this.element.scrollTo(x, y);
		}
	},

	initialize: function(element, options){
		this.setOptions(options);
		this.element = $(element);
		this.mousemover = ([window, document].contains(element)) ? $(document.body) : this.element;
	},

	start: function(){
		this.coord = this.getCoords.bindWithEvent(this);
		this.mousemover.addListener('mousemove', this.coord);
	},

	stop: function(){
		this.mousemover.removeListener('mousemove', this.coord);
		this.timer = $clear(this.timer);
	},

	getCoords: function(event){
		this.page = (this.element == window) ? event.client : event.page;
		if (!this.timer) this.timer = this.scroll.periodical(50, this);
	},

	scroll: function(){
		var el = this.element.getSize();
		var pos = this.element.getPosition();

		var change = {'x': 0, 'y': 0};
		for (var z in this.page){
			if (this.page[z] < (this.options.area + pos[z]) && el.scroll[z] != 0)
				change[z] = (this.page[z] - this.options.area - pos[z]) * this.options.velocity;
			else if (this.page[z] + this.options.area > (el.size[z] + pos[z]) && el.scroll[z] + el.size[z] != el.scrollSize[z])
				change[z] = (this.page[z] - el.size[z] + this.options.area - pos[z]) * this.options.velocity;
		}
		if (change.y || change.x) this.fireEvent('onChange', [el.scroll.x + change.x, el.scroll.y + change.y]);
	}

});

iScroller.implement(new Events, new Options);	
