(function($) {
	$.fn.blink = function(delay) {
		if (!delay)
			delay = 150;
			
		return this
			.animate(
				{ opacity : 0.8 }, 
				{ duration : delay, 
				  complete : 
					function () { 
						$(this).animate({opacity : 1}, { duration : delay }); 
					}
				});
	};
})(jQuery);
(function($){
	$.fn.resizer = function() {
		//width = $(this).width();
		//$(this).height()
		function resize () {
			
		};
		return this
			.mousedown(function (event) {
				p = $(this).offset();
				br = {
					left : p.left + $(this).width(),
					top  : p.top  + $(this).height()
				};
			
				//$('h1', this).text( event.clientY + " vs " + $(this).height());
				if (
					(event.pageX >= br.left - 15) && 
					(event.pageY >= br.top  - 15)
					) {
						//DumperAlert(br);
						$(this).data('original', { 
							width	: $(this).width(), 
							height	: $('.chat-msgs', this).height()
						});
						$('body')
							.data('last', { x : event.pageX, y : event.pageY })
							.data('resize', this)
							.mousemove(function (event) {
								el = $( $(this).data('resize') );
								delta = {
									x : event.pageX - $('body').data('last')['x'],
									y : event.pageY - $('body').data('last')['y'] };
								$(this).data('last', { x : event.pageX, y : event.pageY });
									
								w = $(el).width() + delta.x;
								if (w < 420)
									w = 420;
								if (w > 660)
									w = 660;
									
								h = $('.chatLog', el).height() + delta.y;
								if (h < 100)
									h = 100;
								if (h > 250)
									h = 250;
									
								$(el).width(w);
								$('.chat-msgs', el).height(h);
								cl = $('.chat-msgs', el);
								cl[0].scrollTop = cl[0].scrollHeight;
								
								//$('.chatLog', el).text(Dumper(delta));
							})
							.mouseup(function (event) {
								$(this)
									.unbind('mouseup')
									.unbind('mousemove');
							})
					
						return false;
					}
			});
	};
})(jQuery);
(function($) {
	$.fn.flipClock = function() {
		var clock = this;
		var endTime = null;
		
		function set (name, number) {
			number = number.toString(10);
			
			digit = $('.digit[name=' + name + ']', clock);
			if ($(digit).hasClass('double')) {
				if (number.length < 2)
					number = "0" + number;
					
				$('.sub', digit).each(function (i) {
					value = number.substring(i, i+1);
					if ($(this).data('value') != value) {
						// Record the NEW value
						$(this).data('value', value);
						
						// Flag the old <img /> tags
						$('.up img, .down img', this)
							.addClass('old');
							
						// Setup the new <img />s
						if ($(this).hasClass('left')) {
							$('.up', this)
								.append('<img class="new" src="/images/flip-clock/Single/Up/' + value + '.png" />');
							$('.down', this)
								.append('<img class="new" src="/images/flip-clock/Single/Down/' + value + '.png" />');
						} else {
							$('.up', this)
								.append('<img class="new" src="/images/flip-clock/Single/Up/' + value + '.png" />');
							$('.down', this)
								.append('<img class="new" src="/images/flip-clock/Single/Down/' + value + '.png" />');
						}
					}
				});
			}
			
			$('.up img.old')
				.animate({ height : '0px', top : '16px' }, { duration : 200 });
			setTimeout(function () { 
				$('.down img.new')
					.css({ height : '0px' })
					.animate({ height : '16px' }, { duration : 200 });
				}, 180);
			
			setTimeout(function () {
				// Clear flags
				$('img.old', clock).remove();
				$('img.new', clock).removeClass('new');
			}, 500);
		};
		
		function countDownIteration () {
			timeLeft = endTime - new Date();
			
			if (timeLeft < 0)
				throw "Auction has ended";
			hours = Math.floor(timeLeft / (1000 * 60 * 60));
			timeLeft = timeLeft - (hours * 1000 * 60 * 60);
			
			mins = Math.floor(timeLeft / (1000 * 60));
			timeLeft = timeLeft - (mins * 1000 * 60);
			
			secs = Math.floor(timeLeft / 1000);
			
			/*DumperAlert({
				hours : hours,
				mins : mins,
				secs : secs });*/
				
			set('hours', hours);
			set('minutes', mins);
			set('seconds', secs);
		}
		
		function countDown (end) {
			endTime = end;
			countDownIteration();
			
			if (endTime - new Date() > 0)
				setInterval(countDownIteration, 900);
		};
		
		return {
			set : set,
			countDown : countDown
		};
	};
})(jQuery);

if (typeof console == "undefined") {
	window.console = {
		log : function () {}
	};
}

function FindAuction (id) {
	for (var i=0; i<LiveHaggleData.length; i++) {
		if (LiveHaggleData[i]['AuctionID'] == id) {
			return LiveHaggleData[i];
		}
	}
	return null;
};

$(function () {
	var LiveHaggleMarkup = null;
	for (var i=0; i<LiveHaggleData.length; i++) {
		LiveHaggleData[i]['ServerStartTime'] = LiveHaggleData[i]['AuctionDateTimeStart'];
		
		if (LiveHaggleData[i]['AuctionStartsIn'] && LiveHaggleData[i]['AuctionStartsIn']) {
			LiveHaggleData[i]['AuctionDateTimeStart'] = new Date();
			LiveHaggleData[i]['AuctionDateTimeStart'].addSeconds(parseInt(LiveHaggleData[i]['AuctionStartsIn'], 10));
			
			LiveHaggleData[i]['AuctionDateTimeEnd'] = new Date();
			LiveHaggleData[i]['AuctionDateTimeEnd'].addSeconds(parseInt(LiveHaggleData[i]['AuctionEndsIn'], 10));
			
			if (LiveHaggleData[i]['AuctionDateTimeEnd'] <= new Date())
				LiveHaggleData[i]['status'] = "closed";
				
			else if (LiveHaggleData[i]['AuctionDateTimeStart'] <= new Date())
				LiveHaggleData[i]['status'] = "live";
			
			if (LiveHaggleData[i]['AuctionID'] == '1') {
				console.log(LiveHaggleData[i]['AuctionEndIn'] + ': ', parseInt(LiveHaggleData[i]['AuctionEndsIn'], 10));
			}
		} else {
			var timeStart = new Date(LiveHaggleData[i]['AuctionDateTimeStart']);
			timeStart.setSeconds(timeStart.getSeconds() + (ServerTimeDelta / 1000));
			
			var timeEnd = new Date(timeStart);
			timeEnd.setMinutes( timeEnd.getMinutes() + parseInt(LiveHaggleData[i].AuctionDuration, 10) );
			
			LiveHaggleData[i]['AuctionDateTimeStart'] = timeStart;
			LiveHaggleData[i]['AuctionDateTimeEnd'] = timeEnd;
			
			if (LiveHaggleData[i]['AuctionDateTimeEnd'] - serverTime <= 0)
				LiveHaggleData[i]['status'] = "closed";
		}
	};
	
	SB.LH = {};
	SB.LH.Base = baseChatWidget;
	SB.LH.BasicDemo = FrontPageLH;
	
	function SwapChannel (auctionID) {
		console.log('Swaping Channel on: ', auctionID);
		
		if (typeof apeClient.core == "undefined") {
			return;
		}
		
		// Join the Chat + Bids channel
		apeClient.core.join('*lh' + auctionID);
		
		// Leave the bids only channel
		var pipes = apeClient.core.pipes.getValues();
		for (i=0; i<pipes.length; i++) {
			if (pipes[i].name == '*lh' + auctionID + 'b') {
				apeClient.core.left( pipes[i].getPubid() );
			}
		}
	}
	
	function baseChatWidget (auctionID, fnCallback) {
		if ($('#LH' + auctionID).length > 0) {
			return $('#LH' + auctionID);
		}
		
		if (LiveHaggleMarkup === null) {
			var Args = arguments;
			$.ajax({
				url			: '/inc/snippets/livehaggle-widget.html',
				dataType	: 'text',
				success		: function (d) { 
					LiveHaggleMarkup = d;
					baseChatWidget.apply(window, Args);
				}
			});
			
			return;
		}
		
		if (!FindAuction(auctionID).dump && !FindAuction(auctionID).chat) {
			var Args = arguments;
			$.ajax({
				url			: '/ajax/chat.php',
				type		: 'POST',
				dataType	: 'json',
				data		: { aid : auctionID },
				success		: 	function (j) { 
									if (j.status == "ok") {
										FindAuction(auctionID).dump=j;
										baseChatWidget.apply(window, Args);
									}
								},
				error	: function (r, m, e) { alert(m); }
			});
			
			return;
		}
		
		var auctionData = FindAuction(auctionID);
		
		var	userBid = null,
			highBid = null,
			bidCount = 0,
			onDisplay = false, // when true we will animate certin updates. 
			dom = $(LiveHaggleMarkup);
		
		dom.attr('id', 'LH' + auctionID);
		
		var	
			// UI Elements
			bidPrice 	= $('.bid-price', dom).text('Loading..'),
			bidBidder 	= $('.bid-bidder',dom).empty(),
			bidTotal 	= $('.bid-total', dom).empty(),
			biddersCount= $('.bidders-count', dom).empty(),
			yourBid		= $('.your-bid span', dom).text('$0.00').css('color', 'rgb(37,37,37)');
		var chatLog = $('.chat-msgs', dom).empty();
		
		// initialize and blank out the loaded dom
		$('.item-thumb img', dom).attr('src', 'http://items.static.stuffbuff.com.s3.amazonaws.com/' + zeroPad(parseInt(auctionData.ItemID, 10).toString(16), 8) + ".jpg");
		$('.item-title h1 a', dom).text(auctionData.title.substr(0,18));
		//$('.seller-link', dom).attr({href:'/browse.html?id=' + auctionData.dump.seller}).text(auctionData.dump.sellerName);
		//$('.details-link', dom).attr({href:'/item-detail.html?id=' + auctionData.dump.seller + '&item_id=' + auctionData.ItemID});
		$('.audio-controls', dom).remove(); // not implemented yet.
		$('.bid-share button', dom).click(EmbedCode);
		///// Do Callback
		
		function EmbedCode () {
			function genCode (aid, gid) {
				//return "&lt;object width=\'380\' height=\'400\' id=\'stuffbuff\' classid=\'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\'&gt;&lt;param name=\'allowScriptAccess\' value=\'always\' /&gt;&lt;param name=\'allowFullScreen\' value=\'false\' /&gt;&lt;param name=\'movie\' value=\'http://files2.gigya.s3.amazonaws.com/stuffbuff/livehaggle_loader.swf?gid=" + gid + "&auction_id=" + aid + "\'/&gt;&lt;embed src=\'http://files2.gigya.s3.amazonaws.com/stuffbuff/livehaggle_loader.swf?gid=" + gid + "&auction_id=" + aid + "\'  width=\'380\' height=\'400\' name=\'stuffbuff\' allowScriptAccess=\'always\'  FlashVars=\'gig_lt=1265826338296&gig_pt=1265826348813&gig_g=2\'/&gt;&lt;/embed&gt; &lt;param name=\'FlashVars\' value=\'gig_lt=1265826338296&gig_pt=1265826348813&gig_g=2\' /&gt;&lt;/object&gt;";
				return "<object width='380' height='400' id='stuffbuff' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'><param name='allowScriptAccess' value='always' /><param name='allowFullScreen' value='false' /><param name='movie' value='http://files2.gigya.s3.amazonaws.com/stuffbuff/livehaggle_loader.swf?gid=" + gid + "&auction_id=" + aid + "'/><embed src='http://files2.gigya.s3.amazonaws.com/stuffbuff/livehaggle_loader.swf?gid=" + gid + "&auction_id=" + aid + "'  width='380' height='400' name='stuffbuff' allowScriptAccess='always' wmode='transparent' FlashVars='gig_lt=1265826338296&gig_pt=1265826348813&gig_g=2'/></embed> <param name='FlashVars' value='gig_lt=1265826338296&gig_pt=1265826348813&gig_g=2' /><param name='wmode' value='transparent' /></object>";
			}
		
			var code = $('<div />')
				.addClass('lh-dialog')
				.css({
					opacity			: 0,
					width			: '100%',
					height			: $('.lh-pad', dom).height() + 'px'
				})
				.animate({
					opacity			: 0.9
				}, 100);
				
			var codeText = $('<textarea style="margin : 10px; padding : 4px; border : 1px solid rgb(0,0,0);" />')
				.css({
					width : (parseInt($('.lh-pad', dom).width(), 10) - 10) + 'px',
					height : '200px',
					backgroundColor : 'rgb(255,255,255)'
				})
				.text(genCode(auctionID, LoginID))
				.focus(function () { this.select(); })
				.appendTo(code);
			
			var buttons = $('<div />')
				.css({ textAlign : 'center' })
				.appendTo(code);
			
			$('<button />')
				.text('Dismiss')
				.click(function () { code.remove(); })
				.appendTo(buttons);
				
			$('.lh-pad', dom)
				.css({ position : 'absolute', left : '0px', top : '0px' });
				
			$('.lh-main', dom)
				.css({ position : 'relative' })
				.prepend( code );
		}
		
		function NewBid (data) {
			if (onDisplay) {
				auctionData.dump.bids.push(data);
			}
			
			if (highBid == null || data.BidPrice > highBid.BidPrice) {
				highBid = data;
			}
			UpdateHighBid();
			
			if (data.UserID == LoginID && (userBid == null || data.BidPrice > userBid.BidPrice)) {
				userBid = data;
			}
			UpdateUserBid();
		}
		
		function NewChat (chat) {
			if (onDisplay) {
				auctionData.dump.chat.push(chat);
			}
			
			var date;
			var months = ["Jan", 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
			if ((date = chat.fullTime.match(/(\d{4})-(\d{2})-(\d{2})\s(\d+):(\d{2}):(\d{2})/)) && date != null) {
				date = new Date(months[date[2] - 1] + ' ' + date[3] + ' ' + date[1] + ' ' + date[4] + ':' + date[5] + ':' + date[6] + ' EST');
			} else {
				date = new Date(unescape(chat.fullTime));
			}
			console.log('Raw Chat:', chat);
			var bid = chat.BuyerBidPrice ? '<br />Bid: $' + unescape(chat.BuyerBidPrice) : '';
			
			/*cl = $('.chatLog', chatArea)
				.append('<p><a href="javascript:void(0);" class="infotip"><strong class="bidder-01">' + unescape(chat.name) + '</strong><span>' + humanTime(date) + bid + '</span></a>:<br />' + unescape(chat.ChatText) + '</p>');
			cl[0].scrollTop = cl[0].scrollHeight;*/
			
			$('<p><a class="infotip"><strong class="bidder-01">' + unescape(chat.name) + '</strong><span>' + humanTime(date) + bid + '</span></a>:<br />' + unescape(chat.ChatText) + '</p>')
				.appendTo(chatLog);
			chatLog[0].scrollTop = chatLog[0].scrollHeight;
		};
		
		function UpdateUserBid () {
			if (userBid === null)
				return;
				
			$(yourBid).text(userBid.BidPrice);
			if (onDisplay) {
				$(yourBid)
					.stop()
					.animate({
						color	: (highBid.BidPrice == userBid.BidPrice ? 'rgb(39,137,0)' : 'rgb(137,39,0)'),
						opacity	: 1
					}, 200);
			}
		}
		
		function UpdateHighBid () {
			if (highBid == null) {
				$(bidBidder).html('High Bidder:<br />n/a');
				$(bidPrice).text('$--.--');
			} else {
				$(bidBidder).html('High Bidder:<br />' + highBid.Username);
				$(bidPrice).text('$' + highBid.BidPrice);
			}
			try {
				var bidders = auctionData.bidders ? auctionData.bidders : auctionData.dump.bidders;
				$(biddersCount).text(bidders + ' Bidders');
			} catch (e) {}
		}
		
		function FadeBid () {
			$(yourBid)
				.stop()
				.animate({color:'rgb(0,0,0)',opacity:0.4}, 200);
		}
		
		function Dock () {
			var target = $('.lhMenu');
			target = { 
					top : $(target).offset()['top'] + 'px',
					left : $(target).offset()['left'] + 'px',
					//width : $(target).width() + 'px',
					//height : $(target).height() + 'px'
					width : '30px',
					height : '10px'
					};
			
			mv = $('<div style="border : 1px solid rgb(30,30,30); position : absolute;" />')
				.css({
					top : $(dom).css('top'),
					left : $(dom).css('left'),
					width : $(dom).width(),
					height : $(dom).height(),
					zIndex : $(dom).css('zIndex') - 1 })
				.appendTo('body');
			
			$(dom).remove();
			$(mv).animate(target, { duration : 200, complete : function () { $(this).remove(); } });
		}
		
		function AuctionEnd () {
			auctionData['status'] = "closed";
			
			var stats = $('.auction-stats', dom)
				.empty();
				
			if (auctionData['bids'] == 0 || typeof auctionData['bids'] == "undefined") {
				if (auctionData['SellerID'] == LoginID) {
					$(stats)
						.append('There were no bids.')
						//#{"item_id":"241687","title":"Nikon D90 DX 12.3MP Digital SLR Camera with 18-105mm f\/3.5-5.6G ED AF-S VR DX Ni ..."}
						.append( 
							$('<a>Relist?</a>')
								.attr('href', '#relist:' + auctionData['AuctionID'])
								.click(LiveHaggleRelist) 
						);
				} else {
					$(stats)
						.append('This LiveHaggle has ended. There were no bids');
				}
			} else if (auctionData['bidder'] != LoginID) {
				$(stats)
					.append('This LiveHaggle has ended. You were not the winner.');
			} else  {
				$(stats)
					.append('You won the bidding! <a style="color:white;font-weight:bold;" href="/livehaggle.html?aid=' + auctionData['AuctionID'] + '">Arrange Payment and Shipping</a>');
			}
			
			$('.auction-bid', dom)
				.slideUp();
				
			$('.auction-time', dom)
				.fadeOut(function () { $(this).html('Auction has ended').fadeIn(); });
		}
		
		function humanTime (date) {
			var today = new Date();
			today.zeroTime();
			
			var yesterday = new Date(today - 1000 * 60 * 60 * 24);
			
			if (date >= today)
				return 'Today @ ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
			
			if (date >= yesterday)
				return 'Yesterday @ ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
				
			return date.toDateString();
		}
		
		$(dom).data('logic', { NewChat : NewChat, NewBid : NewBid, UpdateBidUI : UpdateHighBid, Dock : Dock, End : AuctionEnd, FadeBid : FadeBid });
		
		
		/* Flip Clock */
		$('.retroClock .sub', dom).data('value', 0);
		var flipClockObj = $('.retroClock', dom).flipClock();
		
		function SetupFlipClock (starts, ends) {
			var	starts = parseInt(starts, 10),
				ends = parseInt(ends, 10);
				
			var endTime = new Date();
			endTime.setSeconds(endTime.getSeconds() + ends);
			
			if (ends <= 0) {
				AuctionEnd();
			} else {
				if (starts <= 0) {
					flipClockObj.countDown(endTime);
				} else {
					var friendlyStart = auctionData['AuctionDateTimeStartFriendly'] ? auctionData['AuctionDateTimeStartFriendly'] : auctionData['ServerStartTime'];
					$('.retroClock', dom)
						.hide()
						.after('<div class="start-time">Auction starts: <br /><strong>' + friendlyStart + '</strong></div>');
					setTimeout(
						function () { 
							$('.start-time', dom).remove();
							$('.retroClock', dom).show(); 
							flipClockObj.countDown(endTime);
						}, starts * 1000);
				}
			}
		}
		
		if (typeof auctionData['secondsStart'] == 'undefined') {
			$.ajax({
				url		: '/ajax/chat.php',
				type	: 'POST',
				dataType: 'json',
				data	: { aid : auctionID, cmd : 'secondsLeft' },
				success	: function (j) {
					SetupFlipClock(j.secondsUntil, j.secondsLeft);
				}
			});
		} else {
			SetupFlipClock(auctionData['secondsStart'], auctionData['secondsEnd']);
		}
		
		fnCallback.apply(dom, arguments);
	}
	
	function FrontPageLH (auctionIDs, fnComplete) {
		for (var i=0; i<auctionIDs.length; i++) {
			auctionID = auctionIDs[i];
			
			var swf_url = 'http://files2.gigya.s3.amazonaws.com/stuffbuff/livehaggle_loader.swf';
			
			$('<li />')
				.flash({
						src:	swf_url + '?gid=0&auction_id=' + auctionID,
						width:	380,
						height:	400,
						wmode: 'transparent',
						flashvars: { 
							'gig_lt' : '1265826338296',
							'gig_pt' : '1265826348813',
							'gig_g'  : '2'
						}
					},
					{ version: 8 })
				.appendTo('#lhScrollArea');
		};
		
		fnComplete();
	}
	
	function newChatWidget (auctionID, title, item_id) {
		baseChatWidget(auctionID, function () {
		
			this
				.css({ position : 'absolute', top : '100px', left : '100px', width : '300px' })
				.attr('id', 'LH' + auctionID)
				.resizer()
				.appendTo('body');
			
			var	lhInput	= $('form', this),
				lhLogic = $(this).data('logic'),
				auctionData = FindAuction(auctionID);
			
			$('.seller-link', this)
				.attr({ href : '/browse.html?id=' + auctionData.dump.seller })
				.text(LoginID == auctionData.dump.seller ? "You" : auctionData.dump.sellerName);
			
			if (LoginID == auctionData.dump.seller) {
				// Can't bid on your own auction
				$('.auction-bid', this).remove();
			}
			
			$('.details-link', this)
				.attr({ href : '/item-detail.html?id=' + auctionData.dump.seller + '&item_id=' + auctionData.ItemID });
			
			var c = auctionData.dump.chat.length;
			for (var i=0; i<c; i++) {
				lhLogic.NewChat(auctionData.dump.chat[i]);
			}
			var c = auctionData.dump.bids.length;
			for (var i=0; i<c; i++) {
				lhLogic.NewBid(auctionData.dump.bids[i]);
			}
			lhLogic.UpdateBidUI();
			
			try {
				$('.LH-WRAPPER', this).draggable({handle : '.widget-title'});
				//dom.draggable({ handle : $('.widget-title', dom) });
			} catch (e) {
				//console.log('draggable failed: ', e);
			}
			
			$('.lh-close', this)
				.click(function () { lhLogic.Dock(); });
			
			$(lhInput)
				.submit(function () {
					try {
						// Data structure to send
						var data = { aid : auctionID };
						
						// Test for and append bid-value
						var bidInput = $(this).find('input[name="bid"]');
						if (bidInput.val() != '') {
							data['bid'] = parseFloat(bidInput.val());
							bidInput.val('');
						}
						
						// Same with chat
						var chatInput = $(this).find('input[name="text"]');
						if (chatInput.val() != '') {
							data['chat'] = chatInput.val();
							$(chatInput).val('');
						}
						
						if (auctionData['AuctionDateTimeStart'] > new Date()) {
							alert("Auction hasn't started yet!");
							return false;
						}
						
						console.log('Sending: ', data);
						
						$.ajax({
							url		: '/ajax/chat.php',
							type	: 'POST',
							dataType: 'json',
							data	: data,
							success	: 	function (j) { 
											if (j.status == "ok") {
												//DumperAlert(j);
												//setTimeout(refreshChat, interval);
											} else {
												if (j.message == 'BidException:1001(insufficient_bid)')
													return alert('The amount you attempted to bid is insufficient');
													
												if (j.message == "BidException:1002(auction_owner)")
													return alert("You can't bid on your own auctions");
												
												if (j.message == "BidException:1003(ridiclous_bid)")
													return alert('The maximum allowed bid currently is $50,000 for this auction');
												
												//DumperAlert(j);
											}
										},
							error	: function (r, m, e) { alert(m); }
						});
						
						if (data['bid']) {
							lhLogic.FadeBid();
						}
					} catch (e) {
						window.lastEx = e;
					}
					return false;
				})
				.keyup(function (event) {
				if (event.keyCode == 13) {
					$(this).submit();
				}
			});
			SwapChannel(auctionID);
		});
	}
	
	if (typeof(DemoLH) !== 'undefined') {
		FrontPageLH(DemoLH, function () { 
			$("div.scrollable")
				.scrollable({loop: true, clickable: false, hoverClass: 'hover'}); 
		});
	}
	
	function LiveHaggleRelist () {
		var aid = $(this).attr('href').match(/#relist:(\d+)/)[1];
		var data = FindAuction(aid);
		
		SellUI.load(data.dump['item_details']);
	}
	
	$('.lnkJoinAuctionNew')
		.click(function () {
			var auctionData = FindAuction( $(this).attr('href').match(/#auction:(\d+)/)[1] );
			if (auctionData != null) {
		
				profile.ensureLogin(function (uid) {
					var n = newChatWidget(auctionData.AuctionID, auctionData.title, auctionData.ItemID);
				});
			} else {
				alert("Unable to acquire LiveHaggle data from JSON");
			}
			
			return false;
		});
	
	$('.lnkJoinAuction')
		.click(function () {
			auctionData = $.evalJSON( $(this).attr('href').match(/#(.+)$/)[1] );
			
			if (auctionData.auctionType == "LiveHaggle") {
				profile.ensureLogin(function (uid) {
					n = newChatWidget(auctionData.auctionID, auctionData.itemTitle, auctionData.itemID);
				});
			}
			
			/*DumperAlert(auctionData);
			{
			 'auctionType' => 'LiveHaggle',
			 'auctionID' => '4',
			 'itemTitle' => 'Ghostbusters',
			 'from' => 'Jason',
			 'fromUID' => '3'
			}*/
			//href="#{&quot;auctionType&quot;:&quot;LiveHaggle&quot;,&quot;auctionID&quot;:&quot;4&quot;,&quot;itemTitle&quot;:&quot;Ghostbusters&quot;,&quot;from&quot;:&quot;Jason&quot;,&quot;fromUID&quot;:&quot;3&quot;}"
			
			return false;
		});
	
	$('.mnuAuction')
		.click(function () {
			auctionData = FindAuction( $(this).attr('href').match(/#auction:(\d+)/)[1] );
			if (true || auctionData.auctionType == "LiveHaggle") {
				try {
					profile.ensureLogin(function (uid) {
						n = newChatWidget(auctionData.AuctionID, auctionData.title, auctionData.ItemID);
					});
				} catch (e) {
					window.lastEx = e;
				}
			}
			return false;
		});
		/*
		{
		 'AuctionID' => '2',
		 'ItemID' => '231',
		 'StartBidPrice' => '45.00',
		 'AuctionDateTimeStart' => '2009-09-20 20:00:00',
		 'BidderCount' => '0',
		 'MaxBidPrice' => [null],
		 'title' => 'BeBox'
		}
		*/
	$('#lhMenu')
		.mouseover(function () { $('div.menu', this).show();	})
		.mouseout(function () { $('div.menu', this).hide(); });
			
});