// JavaScript Document

$(document).ready(function() {
	// SLIDE SHOW
	$("#slideshow").cycle({fx: "fade", timeout: 4000, speed: 1500});

	// SPECIALS BUTTON TO CHANGE LARGE SPECIALS IMAGE AREA 
	$(".specialBtn").mouseover(function(){
		$(".specialBtn").css({opacity:0.35});
		$(this).css({opacity:1});
	}).mouseout(function(){
		$(".specialBtn").css({opacity:1});
	});
	
	$(".specialBtn").click(function(){
		var thisImg = this;
		$("#specialsBigImage").animate({opacity:0}, function(){
			$("#specialsBigImage").attr("src", "/sitespecific/DimmitMotorCarCollection/medialibrary/" + thisImg.id + ".jpg");
			$("#specialsBigImage").load(function(){
				$("#specialsBigImage").animate({opacity:1});
			});
		});
	});
	
	// INVENTORY SUB MENU 
	$('.bubbleInfo').each(function () {
		var distance = 15;
		var time = 250;
		var hideDelay = 0;

		var hideDelayTimer = null;

		var beingShown = false;
		var shown = false;
		var trigger = $('.bubbleTrigger', this);
		var info = $('.popup', this).css('opacity', 0);


		$([trigger.get(0), info.get(0)]).mouseover(function () {
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			if (beingShown || shown) {
				// don't trigger the animation again
				return;
			} else {
				// reset position of info box
				beingShown = true;

				info.css({
					top: -5,
					left: -20,
					display: 'block'
				}).animate({
					top: '-=' + distance + 'px',
					opacity: 1
				}, time, 'swing', function() {
					beingShown = false;
					shown = true;
				});
			}

			return false;
		}).mouseout(function () {
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			hideDelayTimer = setTimeout(function () {
				hideDelayTimer = null;
				info.animate({
					top: '-=' + distance + 'px',
					opacity: 0
				}, time, 'swing', function () {
					shown = false;
					info.css('display', 'none');
				});

			}, hideDelay);

			return false;
		});
	});

});

function showSubs() {
	$("#inventorySubs").show("fast");
	$(this).unbind("mouseover");
}

function hideSubs() {
	$(this).hide("fast");
	 $("#inventoryLink").bind("mouseover",showSubs);
}

// INSERT FLASH HEADER //
	params_dimmitt = {menu:'false',allowscriptaccess:'always',wmode:'transparent'};
	flashvars_dimmitt = {siteID:"4867",servername:"http://www.dimmitt.com/",sephone:'727-797-7070',address:'25191 US Highway 19 N, Clearwater, FL 33763'};
	attributes_dimmitt = {};
	swfobject.embedSWF("/sitespecific/DimmitMotorCarCollection/Dimmitt_home_header.swf", "headerSWF", "975", "110", "9.0.0",false,flashvars_dimmitt,params_dimmitt,attributes_dimmitt);
