var ttImagesCache = new Array();
jQuery(function() {
	
	
	jQuery("div[class^=com-inventory-listing]").find("div.image > a > img").each(function() {
		el = jQuery(this);
		var id = el.attr('id').replace('vehicle-image-','');
		
		img = new Image();
		img.src = jQuery("#image-overlay-"+id).html().replace(/&amp;/g,'&');
		
		ttImagesCache[id] = img;
	});
	
	/*** Images Tooltip ***/
    jQuery("div.com-inventory-listing div.image > a").tooltip({
		tip: ".image-overlay",
		effect: 'slide',
        relative: true,
		position: 'center right',
		onBeforeShow: function(){
			var id = this.getTrigger().find("img").attr('id').replace('vehicle-image-','');
			this.getTip().text("");
			this.getTip().append(ttImagesCache[id]);
		},
		events: {
		  def:     "mouseenter,mouseleave",
		  tooltip: "mouseenter,mouseleave"
		}
	}).dynamic( { 
        bottom: { 
            direction: 'down', 
            bounce: true 
        },
        right: { 
            direction: 'left', 
            bounce: true 
        }
    });
    
    /*** Dealer Info Tooltip ***/
    jQuery("div.com-inventory-listing .dealer-info-box").tooltip({
		tip: ".dealer-info-box-popup",
		effect: 'slide',
        relative: true,
		position: 'bottom right',
		offset: [10, -20],
		events: {
		  def:     "mouseenter,mouseleave",
		  tooltip: "mouseenter,mouseleave"
		}
	}).dynamic( { 
        bottom: { 
            direction: 'down', 
            bounce: true 
        },
        right: { 
            direction: 'left', 
            bounce: true 
        }
    });
	
	/*** Incentives Tooltip ***/
    jQuery("div.com-inventory-listing .incentives-title").tooltip({
		tip: ".incentives-popup",
		effect: 'slide',
        relative: true,
		position: 'bottom right',
		onBeforeShow: function(){
			this.getTip().addClass("inventory-listing-incentives");
		},
		events: {
		  def:     "mouseenter,mouseleave",
		  tooltip: "mouseenter,mouseleave"
		}
	}).dynamic( { 
        bottom: { 
            direction: 'down', 
            bounce: true 
        },
        right: { 
            direction: 'left', 
            bounce: true 
        }
    });
    	
	$('.tools > .media > .video-count a').click(function() {
		jQuery.blockUIX(
			{
				message: jQuery(".mod-listing-video-overlay-template").val().replace(/{{framesrc}}/g,jQuery(this).attr('href')),
				css: {
					border: 'none',
					width: '830px',
					height: '640px'
				},
				autoCenter: true
			}
		)
		return false;d
	});
	$('.tools > .media > .photo-count a').click(function() {
		jQuery.blockUIX(
			{
				message: jQuery(".mod-listing-gallery-overlay-template").val().replace(/{{framesrc}}/g,jQuery(this).attr('href')),
				css: {
					border: 'none',
					width: '640px',
					height: '640px'
				},
				autoCenter: true
			}
		)
		return false;d
	});
	
	
	
	$('.price-block .recalc a').click(function() {
		jQuery.blockUIX(
			{
				message: jQuery(".mod-listing-calculation-overlay-template").val().replace(/{{framesrc}}/g,jQuery(this).attr('href')),
				css: {
					border: 'none',
					width: '640px',
					height: '640px'
				},
				autoCenter: true
			}
		)
		return false;d
	});
	
	$('.tools > .media > .sister-video-count a').click(function() {
		jQuery.blockUIX(
			{
				message: jQuery(".mod-listing-sister-video-overlay-template").val().replace(/{{framesrc}}/g,jQuery(this).attr('href')),
				css: {
					border: 'none',
					width: '520px',
					height: '360px'
				},
				autoCenter: true
			}
		)
		return false;d
	});	
	 
})
