// Slideshow Functions
function ncSlideshow(container,flair) {

	// Create reference for THIS instance
	var me = this;

	// Find the CONTAINER
	this.container = ($('#' + container).length) ? $('#' + container) : $('.' + container);
	if(!this.container.length) return false;

	// Get the IMAGES
	this.images = this.container.find('img');
	if(this.images.length < 2) return false;

	// Get the Collection, Loader, Content
	this.collection = ($('#' + container + '-images').length) ? $('#' + container + '-images') : $('.' + container + '-images');
	this.loader = ($('#' + container + '-loader').length) ? $('#' + container + '-loader') : $('.' + container + '-loader');
	this.captions = ($('#' + container + '-captions').length) ? $('#' + container + '-captions') : $('.' + container + '-captions');

	// Set the Delay
	this.delay = (!this.collection.attr('delay') || isNaN(this.collection.attr('delay'))) ? 3000 : this.collection.attr('delay');

	// Load jQuery UI
	if(flair && !jQuery.ui){$('<script/>',{type:'text/javascript',src:'/js/jquery/jquery-ui.js'}).appendTo('head');}

	// Slide In & Out
	this.action = function(){

		// Get CURRENT Frame
		var jC = me.images.filter(':visible');

		// Get NEXT or FIRST Frame
		var jN = (!jC.next().length) ? me.images.filter(':first') : jC.next(); 

		// Toggle Animation
		jC.add(jN).fadeToggle(1000);

	}

	// Initialize 
	this.timer = setInterval(this.action,this.delay);

}

// Go!
$(window).load(function(){
	hS = new ncSlideshow('global-header-showcase',true);
});
