$(function(){
	// VIP Marquee
	$("#wrap_marquee").marquee('marquee');
 
});

$.fn.extend({
	marquee: function(id) {
		var $el = $("#" + id);
		var $firstChild = $el.children(":first");
		var $secondChild = $el.children(":nth-child(2)");
		var $step = parseFloat($firstChild.css('width')) * -1 - 12;
		
		$el.mouseover(function() {
			$stop = true;
		});

		$el.mouseout(function() {
			$stop = false;
		});
				
		var $left = parseFloat($el.css('left'));
//		$("#test").html("Hi: " + $el.css('left'));
		
		if($left == 0) {
			$firstChild.clone().appendTo($el);
		}
		
		if($left && $left < 0 && $left % $step == 0) {
			$secondChild.clone().appendTo($el);
			$firstChild.remove();
			$left = 0;
		}

		if($stop != true) {
			--$left;
			$el.css('left', $left.toString() + 'px');
		}
		
		window.setTimeout(function() {$("#wrap_marquee").marquee(id);}, 40);
	}	
});

var $stop = false;
