$(document).ready(function() {
	try {
		$(".ProductList li").live('mouseover', function() {

			try {
				if (!$(this).data('init'))
				{
						$(this).data('init', true);
						$(this).hoverIntent({
								// There were some issues with instant hovers, so I added the hoverintent plugin
								sensitivity: 7,
								interval: 100,
								over: function(){
							
									// Hide alt attributes so their popups don't get in the way
									$(".ProductImage img").attr('alt', '');
							
									// Save this jquery object for future use
									var me = $(this);
		
									// Initialize BT, but don't activate
										$(this).bt({
											trigger: 'none',
											closeWhenOthersOpen: true,
											positions: ['right', 'left'], 
											padding: 0, 
											width: 380, 
											spikeGirth: 30, 
											spikeLength: 25, 
											cornerRadius: 10, 
											fill: '#FFF', 
											strokeStyle: '#FFF', 
											shadow: true, 
											shadowColor: 'rgba(0,0,0,.5)',
											shadowBlur: 10,
											shadowOffsetX: 0,
											shadowOffsetY: 0,
											cssStyles: { fontSize: '12px', fontFamily: 'arial,helvetica,sans-serif'},
											contentSelector: "$('#spice-tooltip').html()"
										});
							
									//Grab the product name, since we can't reliably access the ID or SKU
									var myProductName = $(this).find('.ProductDetails a').text();				
							
									 //Send the product name to our server...	
										$.getJSON("http://details.americanspice.com/product-info-by-name.php?productName="+myProductName+"&jsoncallback=?", function(data){
										 // ...which will return our product title and description
										 $('#spice-tooltip-title').html(data.title);
										 $('#spice-tooltip-description').html(data.desc);
										 me.btOn();
										});			
									},						
								out: function(){
										$(this).btOff();
									}
							});
							$(this).trigger('mouseover');
				}
			}
			catch (ex) {
				_ltk.Exception.Submit(ex, 'AmericanSpice.com --> detail_grabber.js');
			}
	
		});
	
		// Function to destroy the current tooltip on click, in case it gets stuck
		$('*').click(function(){
			try {
				if (typeof me != 'undefined') {
					me.btOff();
				}
			}
			catch (ex) {
    			_ltk.Exception.Submit(ex, 'AmericanSpice.com --> detail_grabber.js');
			}
		});
    }
    catch (ex) {
    	_ltk.Exception.Submit(ex, 'AmericanSpice.com --> detail_grabber.js');
    }
});
