(function($) {

	// fake console
	if (typeof window.console == "undefined") {
		window.console = {
			log : function() {
			}
		};
	}

	/**
	 * php.js implode
	 */
	var implode = function(glue, pieces) {
		var i = '', retVal = '', tGlue = '';
		if (arguments.length === 1) {
			pieces = glue;
			glue = '';
		}
		if (typeof (pieces) === 'object') {
			if (pieces instanceof Array) {
				return pieces.join(glue);
			} else {
				for (i in pieces) {
					retVal += tGlue + pieces[i];
					tGlue = glue;
				}
				return retVal;
			}
		} else {
			return pieces;
		}
	}

	/**
	 * 
	 * @Name ZoomCountdown
	 * @description Given
	 * 
	 */
	var ZoomCountdown = function(elem, options) {

		var defaults = {
			fontSize : 33,
			fontSizeZoomFactor : 2.5,
			zoomSpeed : 500
		};

		options = $.extend({}, defaults, options);
		// console.log(options);
		var root = elem;
		var remaining = parseInt(elem.attr('data-remaining'), 10); // seconds
		// remaining
		// before time
		// is up
		var fragments = {
			hour : "",
			minute : "",
			second : ""
		}; // all the different time element data
		var fragElems = {
			hour : root.find('.frag-hour'),
			minute : root.find('.frag-minute'),
			second : root.find('.frag-second')
		}; // all the different time dom elements
		var fontSize = {}; // backup font-size for all the time dom elements

		// loop through all the elements, and backup their current font-sizes
		$.each(fragElems, function(name, elem) {
			fontSize[name] = options.fontSize + 'px'; /* elem.css('fontSize'); */
		}); // doesn't seem to catch the right value
		/**
		 * 
		 */
		var change = function(fragment, value, animate) {
			animate = animate ? true : false;
			if (value < 10) {
				value = '0' + value.toString();
			}
			if (fragments[fragment] != value) {
				var fragDom = fragElems[fragment];
				fragments[fragment] = value;
				fragDom.html(fragments[fragment]);
				var curFontSize = fontSize[fragment];
				fragDom.css('fontSize', parseInt(curFontSize, 10) * options.fontSizeZoomFactor + 'px').animate({
					fontSize : curFontSize
				}, options.zoomSpeed);
			}
		};

		var calculateFragments = function() {
			var remainder;
			var hour = Math.floor(remaining / (60 * 60));
			remainder = remaining % (60 * 60);
			var minute = Math.floor(remainder / 60);
			var second = remainder % (60);

			change('hour', hour);
			change('minute', minute);
			change('second', second);
		};

		var ticker;
		var decrement = function() {
			remaining--;
			calculateFragments();
			if (remaining <= 0) {
				window.clearInterval(ticker);
			}
		};
		window.clearInterval(ticker);
		window.clearInterval(this.ticker);
		ticker = this.ticker = window.setInterval(decrement, 1000);

	};

	$.fn.zoomCountdown = function(options) {
		this.each(function(i, elem) {
			new ZoomCountdown($(elem), options);
		});
	}

	/**
	 * Real class used by topListWidget jquery plugin
	 * 
	 * @var list The ROOT element
	 */
	var ListMaker = function(list) {

		var autoPilotInterval = 8000;
		var autoPilotWaitReset = 15000;

		var root = $(list);
		var auctionContainer = root.find('.auctions-container');
		var auctions = auctionContainer.children('.auctions');
		var upBtn = root.find('a.button.up');
		var downBtn = root.find('a.button.down');
		var auto;
		auctions.find('.timer .value').simpleCountdown();

		var height = auctionContainer.outerHeight(true);
		var curPane = this.curPane = 1;
		var totalPanes = this.totalPanes = Math.floor(auctions.height() / height);

		$('.timer .message').colorize([ 'red', 'orange', 'blue', 'purple', 'black' ], 250);

		auctions.children().each(function(i, elem){
			var auction = $(elem);
			var link = auction.find('a.name').attr('href');
//			console.log(link);
			auction.click(function(){
				window.location = link;
			});			
		}) ;

		var totalHeight = auctions.height();
		var checkButtons = function() {
			if (curPane >= totalPanes) {
				downBtn.addClass('disabled');
			} else {
				downBtn.removeClass('disabled');
			}
			if (curPane <= 1) {
				upBtn.addClass('disabled');
			} else {
				upBtn.removeClass('disabled');
			}
		}

		var scroll = function($trigger, direction) {
			if (auctions.is(':animated') || $trigger.is('.disabled')) {
				return;
			}

			var sign = direction === 'up' ? '+=' : '-=';
			// console.log(auctions);
			auctions.stop().animate({
				top : sign + height + 'px'
			}, 500);
			curPane += direction === 'up' ? -1 : 1;
			checkButtons();
		}

		var autoPilotDirection = 'up';
		var autoPilot = function() {
			if (autoPilotDirection == 'up' && upBtn.is('.disabled')) {
				autoPilotDirection = 'down';
			} else if (autoPilotDirection == 'down' && downBtn.is('.disabled')) {
				autoPilotDirection = 'up';
			}
			if (autoPilotDirection === 'up') {
				scroll(upBtn, 'up');
			} else {
				scroll(downBtn, 'down');
			}
		}

		/**
		 * clears the autopilot timer, and set the "wait" timer that will renable
		 * the autopilot everytime a pager button is clicked, both the autopoilot
		 * reset timer will reset also.
		 */
		var clearAndWait = function() {
			clearInterval(auto);
			auto = setTimeout(function() {
				auto = setInterval(autoPilot, autoPilotInterval);
				autoPilot();
			}, autoPilotWaitReset);
		}

		/**
		 * 
		 */
		downBtn.click(function() {
			scroll($(this), 'down');
			clearAndWait();
		});
		upBtn.click(function() {
			scroll($(this), 'up');
			clearInterval(auto);
			clearAndWait();
		});

		root.mouseover(function() {
			clearInterval(auto);
		}).mouseout(function() {
			clearAndWait();
		});

		checkButtons();
		auto = setInterval(autoPilot, autoPilotInterval);
	};

	$.fn.topListWidget = function() {

		return this.each(function(i, list) {
			var list = window.test = new ListMaker(list);
		});

	};

	/**
	 * jQuery plugin for setting the source an a img dom element from it's
	 * data-src attribute
	 * 
	 * @var property The attribute to grab the source from, defaults to data-src
	 * 
	 */
	$.fn.setImgSrc = function(property) {
		if (property == null) {
			property = 'data-src';
		}
		return this.each(function(i, img) {
			var $this = $(this);
			$this.attr('src', $this.attr(property));
		});
	};

	/**
	 * Real quote ticker class for the quoteTicker jquery plugin
	 * 
	 * @var eleme Root element
	 */
	var quoteTicker = function(elem, options) {

		var defaults = {
			scrollSelect : '.quote-ticker-scroll',
			duration : 8000,
			animationTime : 1000
		};
		if (typeof options == 'undefined') {
			options = {};
		}
		options = $.extend({}, defaults, options);

		var root = $(elem);
		var scroll = root.children(options.scrollSelect);

		// console.log(root, scroll, options.scrollSelect);

		// console.log('adjusted', options);

		var childHeight = scroll.children().outerHeight(true);
		if ($.browser.msie && $.browser.version < 8 && options.scrollPadding) {
			childHeight += options.scrollPadding;
		}
		var move;
		var timeout;
		move = function() {
			var top = parseInt(scroll.css('top'), 10);
			if (Math.abs(top) + childHeight >= scroll.height()) {
				scroll.css('top', childHeight);
			}
			scroll.animate({
				top : '-=' + childHeight + 'px'
			}, options.animationTime, 'linear', function() {
				clearTimeout(timeout);
				timeout = setTimeout(move, options.duration);
			});
		};

		timeout = setTimeout(move, options.duration);
	};

	/**
	 * text scroller
	 */
	var textScroller = function(elem, options) {
		// console.log('in', options);
		var defaults = {
			scrollSelect : '.quote-ticker-scroll',
			easing : 'linear',
			duration : 3500
		};
		if (typeof options == 'undefined') {
			options = {};
		}
		options = $.extend({}, defaults, options);
		// console.log('out', options);

		var root = $(elem);
		var scroll = root.children(options.scrollSelect);

		var perItemDuration;
		if (perItemDuration = root.attr('data-per-item-duration')) {
			options.duration = perItemDuration * scroll.children().length;
		}

		// due to the way the animation is triggered, we need to recalculate the
		// duration
		// based on the current state of the scroller
		var calculateDuration = function() {
			var cur = Math.abs(parseInt(scroll.css('top'), 10));
			var targetDistance = scroll.height();
			var rate = options.duration / targetDistance;
			var duration = (targetDistance - cur) * rate;
			// console.log(duration, targetDistance, cur, rate);
			return duration;
		}

		var scrollUp;
		scrollUp = function(reset) {
			if (reset === true) {
				scroll.css({
					top : root.height()
				});
			}
			scroll.animate({
				top : '-' + scroll.height() + 'px'
			}, calculateDuration(), options.easing, function() {
				scrollUp(true);
			});
		};

		scrollUp(true);
		root.mouseover(function() {
			scroll.stop(false, false);
		}).mouseout(scrollUp);
	};

	$.fn.textScroller = function(options) {
		var self = this[0];
		var $self = $(self);
		var obj = $self.data('quoteScroller');
		if (!obj) {
			obj = new textScroller(self, options);
			$self.data('quoteScroller', obj);
		}
		return obj;
	};

	/**
	 * QuoteTicker jQuery plugin
	 */
	$.fn.quoteTicker = function(options) {

		options = $.extend({
			scrollPadding : 0
		}, options);

		var self = this[0];
		var $self = $(self);
		var obj = $self.data('quoteTicker');
		if (!obj) {
			obj = new quoteTicker(self, options);
			$self.data('quoteTicker', obj);
		}
		return obj;
	};

	/**
	 * slide show tabable class
	 * 
	 * @var elem Root element
	 */
	var slideShowTab = function(elem) {

		var root = $(elem);
		var contentList = root.find('.tab-content').each(function() {
			$(this).css('opacity', '0').hide();
		});
		var activeTrigger = root.find('.banner-tab.active');
		var lastTrigger = activeTrigger;
		var triggers = root.find('.banner-tab');
		var reset = function() {
			activeTrigger = root.find('.banner-tab:first-child');
		}
		if (activeTrigger.length <= 0) {
			reset();
		}

		var gotoNext = this.next = function() {
			lastTrigger = activeTrigger;
			activeTrigger = activeTrigger.next();
			if (activeTrigger.length <= 0) {
				reset();
			}
			activate.call(activeTrigger);
		};

		var timeout;
		this.stop = function() {
			clearTimeout(timeout);
		}

		var activate = function(initial) {

			activeTrigger = $(this);
			var trigger = $(this);
			var anchor = trigger.children('a');
			var id = anchor.attr('data-target');
			triggers.removeClass('active');
			trigger.addClass('active');

			if (lastTrigger[0] != activeTrigger[0] || initial == true) {
				contentList.stop(true, false).animate({
					opacity : 0
				}, 250, null, function() {
					$(this).hide();
				});
				$('#' + id).stop(true, false).css({
					opacity : 0
				}).show().animate({
					opacity : 1
				}, 250);
			}

			clearTimeout(timeout);
			if (arguments.length <= 0 || initial == true) {
				timeout = window.setTimeout(gotoNext, parseInt(anchor.attr('data-wait'), 10));
			}
			lastTrigger = activeTrigger;
		}

		triggers.click(activate);
		activate.call(activeTrigger, true);
	};

	/**
	 * Slideshowtab jquery plugin
	 */
	$.fn.slideShowTab = function() {
		var self = this[0];
		var $self = $(self);
		var obj = $self.data('slideShowTab');
		if (!obj) {
			obj = new slideShowTab(self);
			$self.data('slideShowTab', obj);
		}
		return obj;
	};

	/**
	 * font zoom jquery plugin
	 */
	$.fn.fontZoom = function(min, max, interval, wait) {

		if (wait == null) {
			wait = 0;
		}
		if (typeof wait == 'number') {
			wait = {
				value : wait,
				loop : 1
			};
		}

		if (typeof min == 'number') {
			min = {
				fontSize : min
			};
		}
		if (typeof max == 'number') {
			max = {
				fontSize : max
			};
		}

		return this.each(function(i, elem) {
			var $elem = $(elem);
			var zin, zout;
			var iteration = 0;

			zin = function() {
				$elem.animate(min, interval, 'linear', zout);
			}

			zout = function() {
				var waitTime = 0;
				if (++iteration % wait.loop == 0) {
					waitTime = wait.value;
				}
				setTimeout(function() {
					$elem.animate(max, interval, 'linear', zin);
				}, waitTime);
			}

			zin();
		});
	};

	/**
	 * An effect that causes
	 */
	$.fn.randomNumberFX = function(options) {

		if (options == null) {
			options = {};
		}
		var defaults = {
			width : 8,
			charWait : 8
		};
		options = $.extend({}, dafaults, options);

		return this.each(function(i, elem) {
			var $elem = $(elem);
			var chars = $elem.text();
			$elem.empty();
			var left = 0;
			$.each(chars, function(i, char) {
				var $char = $('<div class="fontZoomCascade char">' + char + '</div>');
				$elem.append($char);
				$char.css('left', left += options.width);
				setTimeout(function() {
					$char.randomNumberSet(char, 50, 100, 10000);
				}, options.charWait * i * 1.5);
			});
		});
	};

	$.fn.fontZoomCascade = function() {

		var options = {};
		options.width = 8;
		options.charWait = 200;

		return this.each(function(i, elem) {
			var $elem = $(elem);
			var chars = $elem.text();
			$elem.empty();
			var left = 0;
			$.each(chars, function(i, char) {
				var $char = $('<div class="fontZoomCascade char">' + char + '</div>');
				$elem.append($char);
				$char.css('left', left += options.width);
				setTimeout(function() {
					$char.randomNumberSet(char, 50, 100, 10000);
				}, options.charWait * i * 1.5);
			});
		});
	};

	/**
	 * random number generator
	 * 
	 * @var min Minimum value, inclusive
	 * @var max Maximum value, inclusive
	 * @return number
	 */
	$.random = function(min, max) {
		if (max == null) {
			max = min;
			min = 0;
		}
		return min + Math.floor(Math.random() * max + 1);
	}

	/**
	 * random number setter
	 */
	$.fn.randomNumberSet = function(realValue, interval, changes, loopTime) {

		return this.each(function() {
			var $elem = $(this);
			var change = function(value) {
				if (value == null) {
					value = $.random(0, 9);
					$elem.addClass('rolling');
				} else {
					$elem.removeClass('rolling');
				}
				$elem.html(value);
			};
			var reset = function() {
				change(realValue);
			}
			var animate = function() {
				for ( var i = 0; i < changes; i++) {
					setTimeout(change, interval * i);
				}
				setTimeout(reset, interval * changes + 1);
			};

			setInterval(animate, loopTime);
			animate();
		});

	};

	var simpleCountdown = function($elem) {

		var hour = 3600000; // 1 hour in milliseconds
		var minutes = 60000; // 1 minute
		var seconds = 1000; // 1 second
		var last = new Date(); // last refresh date
		var timeRemaining;

		/**
		 * constructor
		 */
		var initialize = function() {
			timeRemaining = parseInt($elem.html(), 10) * 1000;
			// console.log($elem.html());
		};

		initialize();

		/**
		 * returns the the number of hours/minutes/seconds/milliseconds left as
		 * discrete alues
		 */
		var getFragments = function() {
			var tr = timeRemaining;
			var fragments = {};
			fragments.h = Math.floor(tr / hour);
			tr = tr % hour;
			fragments.m = Math.floor(tr / minutes);
			tr = tr % minutes;
			fragments.s = Math.floor(tr / seconds);
			// fragments.ms = Math.floor((tr % seconds) / 100);

			return fragments;
		};

		/**
		 * convert values less than 9 to a string with a '0' padding
		 */
		var padZero = function($value, pad) {
			if (pad === false) {
				return $value;
			}
			return $value < 10 ? '0' + $value : $value;
		}
		var set = function($elem, first, second, third) {

			var s = "";
			for ( var i = 1; i < arguments.length; i++) {
				if (i != 1) {
					s += ':';
				}
				s += padZero(arguments[i]);
			}
			$elem.html(s);
		}

		/**
		 * millsecond version
		 */
		var aMilli = function(f) {
			$elem.parent().addClass('hurry');
			set($elem, f.m, f.s);
		}

		/**
		 * hourly version
		 */
		var noMilli = function(f) {
			set($elem, f.h, f.m, f.s);
		}

		/**
		 * update routine
		 */
		this.update = function() {
			var now = new Date();
			var elapsed = last - now;
			last = now;
			timeRemaining -= elapsed;

			var f = getFragments();
			if (timeRemaining < hour * 5) {
				aMilli(f);
			} else {
				noMilli(f);
			}
		}

	}

	$.fn.simpleCountdown = function() {

		var self = this;
		var timers = [];
		var refresh = 1000;

		this.each(function(i, elem) {
			var $this = $(this);
			timers.push(new simpleCountdown($this));
		});

		var updater = function() {
			$.each(timers, function(i, countdown) {
				countdown.update();
			})
		};

		setInterval(updater, refresh);

		return this;

	}

	/**
	 * font colorizer
	 */
	$.fn.colorize = function(colors, interval) {
		return this.each(function(i, elem) {
			var $elem = $(elem);
			var counter = 0;
			var set;
			set = function() {
				var nextColor = colors[counter % colors.length];
				if (counter % 2 == 0) {
					fontSize = '-=2px';
				} else {
					fontSize = '+=2px';
				}
				$elem.css({
					color : nextColor
				});
				counter++;
			};
			setInterval(set, interval);
		});
	};

	$.fn.bidBlink = function() {
		var bgTransform = '#DCEEFF';
		var fontTransform = 'black';

		var getTen = function(value) {
			if (value < 10) {
				return 1;
			} else if (value < 100) {
				return 2;
			} else if (value < 1000) {
				return 3;
			} else if (value < 10000) {
				return 4;
			} else {
				return 5;
			}
		}

		this.each(function(i, elem) {
			var $this = $(this);
			var $value = $this.find('.value');
			var $parent = $this.parents('.membersPreviewItem');
			// console.log($value);
			var original = $value.html();
			var value = parseInt(original.replace('$', ''));
			var ten = getTen(value);
			var min = Math.pow(10, ten - 1);
			var max = Math.pow(10, ten) - 1;

			// console.log(value, min, max);

			var cssSet = function(bg, color, miscProps) {
				var props = $.extend({}, miscProps, {
					backgroundColor : bg,
					color : color
				});
				return function() {
					$this.css(props);
				}
			}
			var blink, randomBlink;

//			if (i < 1 ) { window.x = $parent; console.log($this.parents('.membersPreviewItem'), $this.parents('.membersPreviewItem').is('.sold')); }
			blink = function() {
				if ($this.parents('.membersPreviewItem').is('.sold')) {
					clearTimeout(randomBlinkInterval);
					return;
				}
				var changer = setInterval(function() {
					var random = $.random(min, max);
//					$value.html('$' + random + '.00');
				}, 50);

				setTimeout(cssSet(bgTransform, fontTransform), 0);
				setTimeout(cssSet('transparent', 'black'), 400);
				setTimeout(function() {
					clearInterval(changer);
//					$value.html(original);
				}, 100);
				randomBlink();
			};

			
			var randomBlinkInterval;
			randomBlink = function() {
				var time = $.random(5000, 6000);
				randomBlinkInterval = setTimeout(blink, time);
			}

			randomBlink();

		});

	};

	$.fn.hoverAnimate = function(hoverIn, hoverOut, animationTime) {

		return this.each(function(i, elem) {
			var $elem = $(elem);
			$elem.stop(true, false).mouseover(function() {
//				console.log('hover');
				$elem.animate(hoverIn, animationTime);
			}).mouseout(function() {
//				console.log('hover out');
				$elem.stop(true, false).animate(hoverOut, animationTime);
			})
		})
	};

	$.fn.relativeDate = function(sourceSelect, targetSelect) {

		var minute = 60 * 1000;
		var hour = minute * 60;
		var day = hour * 24;

		var dateMsg = function(diff) {

			if (diff > 5 * day) {
				return "more than 5 days ago";
			} else if (diff >= 2 * day) {
				return Math.floor(diff / day) + ' Days Ago';
			} else if (diff > day) {
				return "Yesterday";
			} else if (diff > minute * 60) {
				return Math.floor(diff / hour) + ' Hours Ago';
			} else {
				return Math.floor(diff / minute) + ' Minutes Ago';
			}

		}

		return this.each(function(i, elem) {
			var $this = $(this);
			var $source = $this.find(sourceSelect);
			var $target = $this.find(targetSelect);
			var date;
			eval('date = ' + $source.html());
			var now = new Date;
			date = Date.UTC(date.year, date.month, date.day, date.hour, date.minute, date.second);
			date += now.getTimezoneOffset();
			var diff = now - (new Date(date));
			var message = "Won Auction " + dateMsg(diff);
			$target.html(message);
		});

	};

	$.fn.hoverTip = function() {
		var error = function() {
		};
		var complete = function() {
		};
		var popWait = 500; // 1/100 second

		return this.each(function(i, elem) {

			var $elem = $(elem);
			var $parent = $elem.parents('.membersPreviewItem');
			var loaded = false;
			var auction = $(elem).attr('data-auction');
			var containerId = "hover-tip-container-" + auction;
			var $container = $("<div id='auction-container-" + auction + "' class='auction-preview-container'/>");
			$container.hide();
			$('body').append($container);
			var hoverIn, hoverOut;
			var hoverState = false;

			var initContent = function() {

				var $preview = $container.find('.preview-target');
				var $triggers = $container.find('.thumbs img');

				$triggers.each(function(i, img) {
					var $img = $(img);
					$img.attr('src', $img.attr('data-src'));
				});

				$triggers.click(function() {
					var $this = $(this);
					$triggers.removeClass('active');
					$this.addClass('active');
					$preview.attr('src', $this.attr('src'));
				});

				if ($triggers.length > 0) {
					$($triggers[0]).click();
				}
			};

			var show = function() {
				if (!openInterval) {
					openInterval = setTimeout(open, popWait);
				}
			};

			var open = function() {

				clearTimeout(openInterval);
				openInterval = null;
				if (hoverState === false) {
					return;
				}
				var scrollOffset = $(document).scrollTop();

				var props = $parent.offset();
				props.top = props.top - $container.height() / 2 + $parent.height() / 2;
				props.left = props.left + $parent.width();
				if (props.top < scrollOffset) {
					props.top = scrollOffset;
				} else if (props.top + $container.height() > scrollOffset + $(window).height()) {
					props.top = $(window).height() + scrollOffset - $container.height();
				}

				if (props.left + $container.width() > $(window).width()) {
					props.left = $parent.offset().left - $container.width();
				}

				$container.show().css(props);
			};

			var closeInterval;
			var openInterval;
			var close = function() {
				if (hoverState === false) {
					$container.hide();
					clearInterval(closeInterval);
				}

			};

			var request = function() {

				if (loaded === true) {
					show();
					return;
				}

				loaded = true;
				var url = '/widget-helper/?action=front.ajax';
				var request = $.ajax({
					complete : complete,
					success : function(data) {
						$container.append($(data));
						initContent();
						show();
						$container.find('.thumbs img').load(open);
					},
					error : error,
					data : {
						id : auction
					},
					dataType : 'html',
					url : url
				});
			};

			hoverIn = function() {
				hoverState = true;
				request();
				setInterval(close, 100);
			};

			hoverOut = function() {
				hoverState = false;
			}

			$elem.mouseover(hoverIn).mouseout(hoverOut);
			$container.mouseover(hoverIn).mouseout(hoverOut);
		});

	};

	if ($.fn.jFav == null) {
		$.fn.jFav = function() {
		};
	}

	$.fn.cornerMessageSwitch = function() {

		var threshold = 3600000;
		var watchSoldThreshold = 5 * 60 * 1000;

		return this.each(function(i, elem) {

			var $root = $(elem);
			var $timer = $root.find('span.auction-timer');
			
			try {
				var data;
				var h, m, s, ms;
				
				if (data =$timer.html().match(/(\d\d):(\d\d):(\d\d)/)) {
					h = parseInt(data[1], 10);
					m = parseInt(data[2], 10);
					s = parseInt(data[3], 10);
					ms = 0;
				} else if (data =$timer.html().match(/(\d\d):(\d\d)\.(\d)/)) {
					h = 0;
					m = parseInt(data[1], 10);
					s = parseInt(data[2], 10);
					ms = parseInt(data[3], 10);
				}

				if (data) {
					var remaining = h * 60 * 60 * 1000 + m * 60 * 1000 + s * 1000 + ms;	
					setTimeout(function(){
						$root.addClass('hurry');
					}, remaining - threshold > 0 ? remaining - threshold : 0 );
					
					setTimeout(function(){
						$root.removeClass('hurry').addClass('sold');
					}, remaining > 0 ? remaining : 1 );					
				}
			} catch (e) {  }
			
		});

	}

})(jQuery);

