Slideshow = function(settings)
				{
					this.settings = jQuery.extend({
												  		slideTimeout: 4000,
														animationTimeout: 500,
														animationDelay: 200,
														slides: ['img/slides/slide1.jpg', 'img/slides/slide2.jpg', 'img/slides/slide3.jpg', 'img/slides/slide4.jpg', 'img/slides/slide5.jpg', 'img/slides/slide6.jpg', 'img/slides/slide7.jpg', 'img/slides/slide8.jpg', 'img/slides/slide9.jpg', 'img/slides/slide10.jpg', 'img/slides/slide11.jpg', 'img/slides/slide12.jpg', 'img/slides/slide13.jpg', 'img/slides/slide14.jpg'],
														animationSlidesSelector: '#Content .AnimationLayer',
														animationSlideOffset: 540,
														maskLayerSelector:  '#Content .MaskLayer',
														contentLayerSelector:  '#Content .ContentLayer',
														mainSlideshowArea: '#Content'
												  }, settings);
					this.currentSlide = 0;
					this.animationSlides = null;
					this.maskLayers = null;
					this.contentLayers = null;
					this.timers = {};
					this.off = false;
					
					this.init = function(flag)
								{
									this.getAnimationSlides();
									this.getMaskLayers();
									this.getContentLayers();;
									this.setContentLayersEvents();
									if(flag != 'stopped')
										this.preloadSlidesAndStart();
								}
								
					this.getAnimationSlides = function()
												{
													this.animationSlides = jQuery(this.settings.animationSlidesSelector);
												}
					this.getMaskLayers = function()
												{
													this.maskLayers = jQuery(this.settings.maskLayerSelector);
													this.maskLayers.css('opacity', 0.6)
												}
												
					this.showMaskLayers = function(idx)
												{
													if (idx != null)
														this.maskLayers.filter(':eq('+ idx + ')').css('visibility', 'visible')
													else
														this.maskLayers.css('visibility', 'visible')
												}
												
					this.hideMaskLayers = function()
												{
													this.maskLayers.css('visibility', 'hidden')
												}
												
					this.getContentLayers = function()
												{
													this.contentLayers = jQuery(this.settings.contentLayerSelector);
													this.contentLayers.find('.InnerContent').css('opacity', 0.9);
												}

					this.showContentLayer = function(index)
												{
													this.contentLayers.eq(index).addClass('expanded');
												}
												
					this.hideContentLayers = function()
												{
													this.contentLayers.removeClass('expanded');
												}
												
					this.preloadSlidesAndStart = function()
													{
														var total = this.settings.slides.length;
														var counter = 1;
														
														var preloaderCounter = jQuery('<span></span>');
														preloaderCounter.text(counter + '/' + total);
														
														var preloader = jQuery('<div class="preloader"></div>');
														preloader.css({
																		position: 'absolute',
																		left: '50%',
																		top: '50%',
																		width: '200px',
																		height: '30px',
																		lineHeight: '30px',
																		textAlign: 'center',
																		background: '#FFF',
																		marginLeft: '-100px',
																		marginTop: '40px',
																		zIndex: 2000
																	})
																.text('loading slide ');
																
														preloader.append(preloaderCounter);
														preloader.appendTo(this.settings.mainSlideshowArea);

														for(var i = 0; i<total; i++)
														{
														 var newImg = jQuery("<img>");
														 newImg.load(function()
																		{
																			counter = counter + 1;
																			preloaderCounter.text(counter + '/' + total);
																			if(counter == total)
																			{
																				preloader.remove();
																				TIslideshow.start();
																			}
																		});
														 newImg.attr("src", TIslideshow.settings.slides[i]).css('display', 'none').appendTo('body');
														}
														
													}
												
					this.start = function()
									{
										this.hideMaskLayers();
										this.timers['slideshow'] = setTimeout('TIslideshow.rotateSlides()', this.settings.slideTimeout);
									}
					this.stop = function()
								{
									for (var i in this.timers)
										clearTimeout(this.timers[i]);
									this.animationSlides.stop()
											.css('height', '0px');
								}
					this.terminate = function()
										{
											if (!this.off)
											{
												this.stop();
												this.contentLayers.parent().addClass('NoAnimation');
												this.off = true;
											}
										}
					this.rotateSlides = function()
										{
											this.stop();
											if (this.currentSlide < this.settings.slides.length - 1)
												this.loadSlide(this.currentSlide + 1, true);
											else
												this.loadSlide(0, true);											
										}
										
					this.loadSlide = function(slideNo, rotateAfterComplete)
										{
											this.currentSlide = slideNo;
											this.animationSlides.each(function(i)
																		{
																			TIslideshow.timers['cell' + i] = setTimeout('TIslideshow.animateSlide('+slideNo+', '+i+', ' + rotateAfterComplete + ')', i*TIslideshow.settings.animationDelay);
																			})
										}
							
					this.animateSlide = function(slideNo, slideCell, rotateAfterComplete)
										{
											this.animationSlides.eq(slideCell)
																	.css('backgroundImage', 'url(' + TIslideshow.settings.slides[slideNo] + ')')
																	.animate({
																					height:  TIslideshow.settings.animationSlideOffset + 'px'
																				 },
																				 TIslideshow.settings.animationTimeout,
																				 'easeInOutQuad',
																				 function(){
																					var animationLayer = jQuery(this);
																					var contentLayer = animationLayer.parent();
																					contentLayer.css('backgroundImage', animationLayer.css('backgroundImage'));
																					animationLayer.css({
																										backgroundImage: 'none',
																										height: '0px'
																									   });
																					if ((rotateAfterComplete) && (slideCell == TIslideshow.animationSlides.size() - 1))
																						TIslideshow.start();
																				 })	   
										}
										
						this.restart = function(i)
										{
												if (!this.contentLayers.eq(i).hasClass('expanded'))
												{
													TIslideshow.hideContentLayers();
													TIslideshow.start();
												}
										}
										
						this.setContentLayersEvents = function()
													{
														this.contentLayers
																.each(function(index)
																	{
																		var contentLayer = jQuery(this);
																		
																		contentLayer.hover(function()
																							{
																								jQuery(this).parent().addClass('expanded');
																								TIslideshow.showMaskLayers(index);
																								if(!TIslideshow.off)
																								{
																									TIslideshow.stop();
																									if(TIslideshow.currentSlide != index)
																									{
																										//TIslideshow.showMaskLayers(index);
																										TIslideshow.loadSlide(index);
																									}
																									TIslideshow.hideContentLayers();
																									TIslideshow.showContentLayer(index);
																								}
																							},
																						function()
																						{
																							//TIslideshow.stop();
																							TIslideshow.hideMaskLayers();
																							jQuery(this).parent().removeClass('expanded');
																							jQuery(this).removeClass('expanded');
																							if (!TIslideshow.off)
																								TIslideshow.timers['content' + index] = setTimeout('TIslideshow.restart(' + index + ')', 500);
																						});
																		
																	})
													}
}