// 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 Collection, Loader, Content
	this.collection = ($('#' + container + '-slides').length) ? $('#' + container + '-slides') : $('.' + container + '-slides');
	this.slides = ($('#' + container + '-slide').length) ? $('#' + container + '-slide') : $('.' + container + '-slide');
	this.loader = ($('#' + container + '-loader').length) ? $('#' + container + '-loader') : $('.' + container + '-loader');

	if(this.slides.length < 2) return false;

	// Set the Delay
	this.delay = (!this.container.attr('delay') || isNaN(this.container.attr('delay'))) ? 3000 : this.container.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.slides.filter(':visible');

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

		// Toggle Animation
		jC.hide('slide',{direction:'right'},2000);
		jN.show('slide',{direction:'left'},2000);

	}

	// Initialize 
	if(this.loader.length){this.collection.add(this.loader).fadeToggle();}
	this.timer = setInterval(this.action,this.delay);

	// Cancel Animation on HOVER
	if(this.captions.length){
		this.captions.hover(function(i){
			if(i.type == 'mouseenter'){clearInterval(me.timer);}
			else{me.timer = setInterval(me.action,me.delay);}
		});
	}

}

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