(function($){

	
	var DPaC = $.DPaC = {};

	
	DPaC.jSlide = (function(){
		
		
		jBound = null;

		
		settings =  {
			'autoStart': true,
			'transDelay': 5000,
			'frameDelay': 600,
			'frameOverlap': 200,
			'startFrame': 0
		};
	
	
		properties = {
			'timer' : false,
			'current' : false
		};
		
		
		methods = {
			
			init: function(options) { 
			
				if (this.length > 1) {
					jBound = this;
					jBound.hide()
					if ( options != undefined) $.extend( settings, options );
					properties.current = settings.startFrame;
					$(jBound.get(settings.startFrame)).show();
					if ( settings.autoStart ) methods.start();
				}
				
				return jBound;
				
			},
			
			animate: function( ) {
				
				if (properties.current === false) return jBound;
			
				var current = properties.current
				, next = ($(jBound.get(current + 1 )).length) ? current + 1 : 0;
				
				$(jBound.get(current)).fadeOut(settings.frameDelay + settings.frameOverlap);
				$(jBound.get(next)).fadeIn(settings.frameDelay);
				
				properties.current = next;
				
				return jBound;
			},
			
			start: function( ) { 
				if (properties.current === false) return jBound;
				properties.timer = setInterval(methods.animate, settings.transDelay);
				return jBound;
			},
			
			stop: function( ) { 
				clearInterval(properties.timer)
				return jBound;
			}
			
		};

		
		return methods;

		
	})($);




	$.fn.DPaC = function(plugin, method) {
		
		var plugin = DPaC[plugin]
		, slice = Array.prototype.slice;
	
		if (plugin && plugin[method] ) {
			return plugin[ method ].apply( this, slice.call( arguments, 2 ));
		} else if ( plugin && typeof method === 'object' || ! method ) {
			return plugin.init.apply( this, slice.call( arguments, 1 ) );
		} else {
			$.error( 'Method ' +  method + ' does not exist on DPaC.' + plugin );
		}
	
	};


	
})(jQuery);



 
$(document).ready(function(){

	var rotatingHeader = $(".rotate img");
	
	if (rotatingHeader.length) {
		rotatingHeader.DPaC('jSlide');
	}

});
