/*=============================================================================

			 	 TITLE:		NetMediaOne - Banner Slideshow System
		  MODIFIED:		2007.09.12
		 AUTHOR(S): 	Graham Wheeler - NetMediaOne - www.netmediaone.com
		  REQUIRES:		NetMediaOne Core 1.2
									jQuery 1.2

=============================================================================*/

(function($) {
								
	//	Generator function
	$.fn.slideshow = function() {
		return this.each(function() {
			new $.slideshow(this);
		});
	};
	
	//	Default Options
	var defaults = {
		transitionSpeed: 1.0,
		transitionInterval: 0,
		useCaption: false
	};

	//	SlideShow Object
	$.slideshow = function(e) {

		this.container = $(e);
		this.options = $.extend({}, defaults, eval("(" + this.container.attr("params") + ")") || {});
		
		var self = this;

		this.images = $("img", this.container);
		this.thinkTimer = "";
		this.cycleTimer = "";
		this.hovered = false;
		
		this.images.hide().click( function() { self.cycle(); });
		
		this.selectedImage = 0;
		var cI = this.images.get(this.selectedImage);
		$(cI).fadeIn("fast");

		$(this.images.get(this.selectedImage)).show();
		if ( this.options.useCaption ) {
			this.overlayBG = $(".OverlayBG", this.container);
			this.overlayBG.fadeTo("fast", .65);
			this.caption = $(".Caption", this.container);
			this.caption.append( $(cI).attr("alt") );
			if( typeof sIFR == "function" && !sIFR.UA.bIsIEMac ) {
				sIFR.replaceElement( named( { sSelector:"#"+this.id+" .Caption", sFlashSrc:"../myriad-condensed.swf", sWmode:"transparent", sColor:"#ffffff", sBgColor:"#000000" } ) );
			}
		}

		if ( this.options.transitionInterval > 0 ) {
			this.cycleTimer = setTimeout( function() { self.cycle(); }, this.options.transitionInterval * 1000 );
		}
		
	};
	
	$.slideshow.fn = $.slideshow.prototype = { slideshow: '1.0.0' };
	$.slideshow.fn.extend = $.slideshow.extend = $.extend;	
	$.slideshow.fn.extend({

		cycle: function() {
			
			clearTimeout( this.cycleTimer );
			if ( this.images.length > 1 ) {
				var self = this;
				var oldImage = this.selectedImage;
				if ( this.selectedImage < this.images.length - 1 ) {
					this.selectedImage++;
				} else {
					this.selectedImage = 0;
				}
				var oI = this.images.get(oldImage);
				var cI = this.images.get(this.selectedImage);
		
				$(oI).fadeOut(this.options.transitionSpeed * 1000);
				$(cI).fadeIn(this.options.transitionSpeed * 1000);
	
				if ( this.options.useCaption ) {
					setTimeout( function() {
						self.caption.empty().append(cI.getAttribute("alt")).removeClass("sIFR-replaced");
						if( typeof sIFR == "function" && !sIFR.UA.bIsIEMac )	{
							sIFR.replaceElement( named( { sSelector:"#"+self.id+" .Caption", sFlashSrc:"../myriad-condensed.swf", sWmode:"transparent", sColor:"#ffffff", sBgColor:"#000000" } ) );
						}
					}, this.options.transitionSpeed * 1000 );	
				}
	
				if ( this.options.transitionInterval > 0 ) {
					this.cycleTimer = setTimeout( function() { self.cycle(); }, this.options.transitionInterval * 1000 );
				}	
			}
		}

	});	
	
})(jQuery);

jQuery( function() { $(".SlideShow").slideshow(); } );

