/*
 * LogoScroller jQuery Plugin
 * @author Botond Szasz (boteeka@gmail.com)
 *
 * @version 0.1 [Jul 2011]
 *
 * @changelog
 * v 0.1        ->      Initial release
 *
 */
(function( $ ) {

	// This is the main component of the scroller
	$.scroller = function(logoScroller_container) {

		return {
			hovered: false,
			doscroll: function() {
				firstchild = logoScroller_container.children(":eq(0)");
				firstchild.animate({
					'margin-left': firstchild.width() * (-1)
				}, 5000, 'linear', function() {
					$(this).appendTo(logoScroller_container).css('margin-left', 0);
					$.scroller(logoScroller_container).doscroll();
				});
			}
		}

	}
	$.scrollerOptions_defaults = {
		pauseOnHover: true
	}

	$.fn.logoScroller = function(options) {

		// Blend the options together
		$.scrollerOptions = $.extend({}, $.scrollerOptions_defaults, options);

		return this.each( function() {
			// Remove the frame before getting the scrollable children
			var frame_left = $(this).find("img.frame_left").clone();
			var frame_right = $(this).find("img.frame_right").clone();
			frame_left.css({
				'position': 'absolute',
				'top': 0,
				'left': 0
			});
			frame_right.css({
				'position': 'absolute',
				'top': 0,
				'right': 0
			});
			$(this).find("img.frame_left, img.frame_right").remove();
			// Get the child elements to scroll
			var elements = $(this).children();
			// Set up the scroll container
			logoScroller_container = $(this)
			.css({
				'overflow': 'hidden',
				'position': 'relative'
			})
			.append("<div class='logoScroller_container' style='width: 200%;' />")
			.find(".logoScroller_container")
			.append(elements);

			// Add the frame
			$(this).append(frame_left);
			$(this).append(frame_right);

			// Start the scrolling after a small delay
			setTimeout( function() {
				$.scroller(logoScroller_container).doscroll();
			},1000);
		});
	};
})( jQuery );
