var header;

( function ( $ ) {
	var
		internal = {
			animated: false, // Whether or not the animation has been started.

			delay: 500, // Delay between steps in milliseconds.
			pixels: -12, // Amount of pixels to move it.
			count: 320, // How many times to do it before resetting.

			original: 0, // Original value.
			current: 0, // Current count.

			object: undefined, // The object to animate.

			animate: function ( ) {
				this.timeout ( );

				if ( ++this.current >= this.count ) {
					this.current = 0;
				}

				$ ( this.object ).css ( 'backgroundPosition', ( this.original + this.current * this.pixels ) + 'px 0' );
			},

			initiate: function ( selector, delay, pixels, count ) {
				var object;

				if ( ! ( object = $ ( selector ) ).length ) {
					return false;
				}

				if ( typeof ( delay ) === 'number' ) {
					this.delay = delay;
				}

				if ( typeof ( pixels ) === 'number' ) {
					this.pixels = pixels;
				}

				if ( typeof ( count ) === 'number' ) {
					this.count = count;
				}

				this.object = object [ 0 ];
				this.original = parseInt ( $ ( this.object ).css ( 'backgroundPosition' ) );

				this.timeout ( );

				return true;
			},

			closure: function ( method, parameters ) {
				// Declare variables.
				var object;

				object = this;

				// Create closure.
				return function ( ) {
					if ( ! $.isArray ( parameters ) ) {
						parameters = arguments;
					}

					return method.apply ( object, parameters );
				};
			},

			timeout: function ( ) {
				setTimeout ( this.closure ( this.animate ), this.delay );
			}
		},

		external = {
			animate: function ( ) {
				if ( this.animated ) {
					return false;
				}

				this.animated = true;

				return this.initiate.apply ( this, arguments );
			}
		};

	var header = { };

	for ( i in external )
	{
		header [ i ] = ( function ( external, internal ) {
			return function ( ) {
				return external.apply ( internal, arguments );
			}
		} ) ( external [ i ], internal );
	}

	window.header = header;

	$ ( document ).ready ( function ( ) {
		try {
			console.log ( 'header: loaded' );
		} catch ( exception ) {
			console = {
				log: function ( ) {
					// Do nothing.
					return null;
				}
			}
		}
	} );
} ) ( jQuery );

