////////////////////////////////////////////////////////////////
// Image Slider (It only works on images, used on homepage)
////////////////////////////////////////////////////////////////

scSite.imgSlider = scSite.addComponent('imgSlider', function(comp)
{	
	$.extend(comp,
	{
		defaultOptions:
		{
			//effect: 'fade', // Specify sets like: 'fold,fade,sliceDown'
			effect: 'fade', // Specify sets like: 'fold,fade,sliceDown'
			slices: 15, // For slice animations
			//slices: 1, // For slice animations
			boxCols: 8, // For box animations
			//boxCols: 1, // For box animations
			boxRows: 4, // For box animations
			//boxRows: 1, // For box animations
			animSpeed: ( ( !$.browser.msie || ( $.browser.msie && $.browser.version.substr(0,1) > 7 ) ) ? 375 : 0 ), // Slide transition speed
			pauseTime: 5000, // How long each slide will show
			startSlide: 0, // Set starting Slide (0 index)
			directionNav: true, // Next & Prev navigation
			directionNavHide: true, // Only show on hover
			controlNav: true, // 1,2,3... navigation
			controlNavThumbs: false, // Use thumbnails for Control Nav
			controlNavThumbsFromRel: false, // Use image rel for thumbs
			controlNavThumbsSearch: '.jpg', // Replace this with...
			controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
			keyboardNav: false, // Use left & right arrows
			pauseOnHover: true, // Stop animation while hovering
			manualAdvance: false, // Force manual transitions
			captionOpacity: 0.8, // Universal caption opacity
			prevText: 'Prev', // Prev directionNav text
			nextText: 'Next', // Next directionNav text
			beforeChange: jQuery.noop,
			afterChange: jQuery.noop,
			slideshowEnd: jQuery.noop,
			lastSlide: jQuery.noop,
			afterLoad: jQuery.noop
		},
//		
		init: function()
		{
			if( scSite.browser.isIE7orLess() )
			{
				// Since the slider isn't desinged to work in IE, we'll just show the first slide and be done.
				$('.sc-slider .sc-slide:first img').show();
				return;
			}
			else
			{
				// comp.setupSlider();
				// Without the timer, the slider doesn't alyways display correctly
				setTimeout(comp.setupSlider, 200);
			}
		},
		
		
		setupSlider: function()
		{
			// Find all '.sc-slider' elements and turn them into nivoSliders
			$('.sc-slider').each(function()
			{
				var self = $(this);
				var slider = self.children(':first-child');				
				
				var options1 = {};
				if($('.sc-slide img', slider).size() < 2)
				{
					options1.controlNav = false;
					options1.directionNav = false;
				}
				
				var delay = self.data('sc-slider-delay');
				if( delay )
				{
					options1.pauseTime = delay;
				}
				
				// Combine options on the html element with the default options
				var options2 = {};
				for( var key in comp.defaultOptions )
				{
					var val = slider.data('sc-slider-'+ key);
					if( val != null )
					{
						options2[key] = val;
					}
				}
				
				var options = $.extend({}, comp.defaultOptions, options1, options2)
				slider.nivoSlider(options);
			});
			
			
			
			
			////////////////
			// HTML Captions
			////////////////
			//
			// Decided against doing HTML captions since it would be too hackish but here is part of the code for it
			/*
			
				// Set the caption container
				var captionContainer = $('.sc-caption-container', self)
				if( ! captionContainer.size() )
				{
					captionContainer = $('<div class="sc-caption-container" />').prependTo(self);
				}
				
				// Set the slides
				var slides = [];
				$('.sc-slide', slider)
					.each(function()
					{
						var slide = $(this);

						// Move the caption into the caption container
						var caption = $('.sc-caption', slide).hide().appendTo(captionContainer);

						slides.push(
						{
							elSlide: slide,
							elCaption: caption,
							index: slides.length,
							attached: false
						});
					})
					.hide()
				;
				
				var prevSlide, nivoVars;

				
				// Juggling the events around so that we can have our own right here in addition to the ones passed into options.
				var events =
				{
					beforeChange: options.beforeChange,
					afterChange: options.afterChange,
					slideshowEnd: options.slideshowEnd,
					lastSlide: options.lastSlide,
					afterLoad: options.afterLoad
				};
				options.beforeChange = function()
				{
					prevSlide.elCaption.hide(100, 'fade', function()
					{
						var curSlide = currentSlide();
						curSlide.elCaption.show(100, 'fade');
					});
					events.beforeChange();
				};
				
				options.afterChange = function()
				{
					events.afterChange();
					prevSlide = slides[nivoVars.currentSlide];
				};
				
				options.slideshowEnd = function()
				{
					events.slideshowEnd();
				};
				
				options.lastSlide = function()
				{
					events.lastSlide();
				};
				
				options.afterLoad = function()
				{
					events.afterLoad();
				};
				
				// Prepare the first slide.
				prevSlide = slides[nivoVars.currentSlide];
				prevSlide.elCaption.show();
				
				function currentSlide()
				{
					return slides[nivoVars.currentSlide];
				}			
			
			*/
			// End
			//
			////////////////
			// HTML Captions
			////////////////
			
		}
	});
});


////////////////////////////////////////////////////////////////
// Splash Show (StartTheTimerSplash)
////////////////////////////////////////////////////////////////

scSite.splashShow = scSite.addComponent('splashShow', function(comp)
{
	$.extend(comp,
	{
		hasShow: false,
		
		delay: 10000,
		banners: null,
		curBannerIndex: -1,
		
		init: function()
		{
			if( comp.hasShow )
			{
				comp.startShow();
			}
		},
		
		startShow: function()
		{
			comp.banners = $('div[name="splash"]');
			if(comp.banners.size())
			{
				comp.startLoop();
			}
		},
		
		
		startLoop: function()
		{
			comp.curBannerIndex = (comp.curBannerIndex + 1) % comp.banners.size();
			
			comp.banners.hide();
			comp.banners.filter(':eq('+ comp.curBannerIndex +')').show();
			setTimeout(comp.startLoop, comp.delay)
		}
	});
});

