jQuery.easing.easeOutExpo = function (x, t, b, c, d) {
	return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
}
jQuery.noConflict(); 
;(function($) {
$(document).ready(function() {
	$('#garden-expo-menu').lavaLamp({
		fx: 'easeOutExpo',
		speed: 1200 ,
		returnDelay: 1000,
		click: function() {

		}
	});
 
	$('#menu li:has(div.submenubox)').hoverIntent({
		over: function() {
			$(this).children('div.submenubox').stop().slideDown('normal');
		},
		out: function() {
			$(this).children('div.submenubox').stop().slideUp('fast', function() {
				$(this).hide();
			}); 
		},
		timeout: 300
	});
	
	
	$('#search label,.newsletter label').inFieldLabels({
		fadeOpacity: 0.2,
		fadeDuration: 500
	});
	Cufon.replace('#banner-text span', {textShadow:'1px 1px #a9b500'});
	
	$('#cmd-banner-dropdown').click(function(e) {
		e.preventDefault();
		$('#banner-dropdown').slideToggle(); 		
	});
	
	if($('#main.home').length) {
		$('#home-panels li').each(function() { $(this).children('span').html($('<a></a>').attr('href',$(this).children('a').attr('href')).text($(this).children('a').children('img').attr('alt'))); });
		Cufon.replace('#home-panels li span');
	}
	
	if($('table.photogalleryTable').length) {
		$('table.photogalleryTable').each(function(index) {
			var thumb = $(this).find('td.photogalleryItem a').random();
			thumb.children('img').attr('src',function(i,val) {
				return val.substring(0,val.length-48) + '&Width=335&Height=223&Algorithm=fill_proportional'; 
			});
			$(this).before(thumb); 
		});
	}
	
	if($('#viewport').length) {
		$('#viewport').mapbox({ 
			zoom: true, // does map zoom? 
			pan: true, // does map move side to side and up to down? 
			defaultLayer: 0, // starting at 0, which layer shows up first 
			layerSplit: 8, // how many times to split each layer as a zoom level 
			mapContent: '.mapcontent', // the name of the class on the content inner layer 
			defaultX: null, // default positioning on X-axis  
			defaultY: null, // default positioning on Y-axis 
			zoomToCursor: true, // if true, position on the map where the cursor is set will stay the same relative distance from the edge when zooming 
			doubleClickZoom: false, // if true, double clicking zooms to mouse position 
			clickZoom: false, // if true, clicking zooms to mouse position 
			doubleClickZoomOut: false, // if true, double clicking zooms out to mouse position 
			clickZoomOut: false, // if true, clicking zooms out to mouse position 
			doubleClickMove: false, // if true, double clicking moves the map to the cursor position 
			clickMove: false, // if true, clicking moves the map to the cursor position 
			doubleClickDistance: 1, // number of positions (determined by layerSplit) to move on a double-click zoom event 
			clickDistance: 1, // number of positions (determined by layerSplit) to move on a click zoom event 
			callBefore: function(layer, xcoord, ycoord, viewport) {}, // this callback happens before dragging of map starts 
			callAfter: function(layer, xcoord, ycoord, viewport) {}, // this callback happens at end of drag after map is released "mouseup" 
			beforeZoom: function(layer, xcoord, ycoord, viewport) {}, // callback before a zoom happens 
			afterZoom: function(layer, xcoord, ycoord, viewport) {}, // callback after zoom has completed 
			mousewheel: true /* requires mousewheel event plugin: http://plugins.jquery.com/project/mousewheel*/ 
		});
		$('#map-control a').click(function(e) {
            var viewport = $('#viewport'); 
            if(this.className == 'zoom' || this.className == 'back') { 
                viewport.mapbox(this.className, 2);
            } else { 
                viewport.mapbox(this.className); 
            } 
            e.preventDefault();
        }); 
	}
	if($('#exhibitors').length) {
		$('#exhibitors li.exhibitor0').each(function() {
			if($(this).children('img').attr('src').substring(0,1) != '?') $(this).children('img').show();
		});
	}
	if($('#sitemap').length) {
		var currentSquare = null;
		var activeTip;
				
		$('div.tooltip').each(function(index) {
			var tooltip = $(this);
			var dl = tooltip.children('dl');
			if(floatval(dl.children('dd.member.price').text().replace(/[^\d\.]/g, ''))==0) dl.children('dd.member.price').text('N/A');
			if(intval(tooltip.data('electricity'))==1) dl.children('dd.electricity').text('Yes');
			else dl.children('dd.electricity').text('No');
			if(intval(tooltip.data('undercover'))==1) dl.children('dd.undercover').text('Yes');
			else dl.children('dd.undercover').text('No');
			if(dl.children('dd.notes').text()=='') dl.children('.notes').remove();
			if(intval(tooltip.data('available'))==0) {
				//tooltip.children('h2').text(function(index,text) { return text + ' unavailable'; }); 
				tooltip.children('h2').text(function(index,text) { return text + ' - ' + tooltip.data('soldto'); }); 
				//dl.children('dt,dd').remove();
				dl.remove();
			}
			if(tooltip.children('img').attr('src').substring(0,1) != '?') tooltip.children('img').show();
		});
		
		$('area').hover(function () {
			currentSquare = $(this).prop('alt');
			activeTip = $('#tooltip-' + currentSquare);
			activeTip.fadeIn('fast');
		}, function () {
			activeTip.fadeOut('fast');
			currentSquare = null;
		});
		
		$(document).mousemove(function (e) {
			if (currentSquare === null) return;

			var left = e.pageX + 25;
			var top = e.pageY - 100;
			 
			activeTip.css({
				left: left,
				top: top
			});
		});
		
		var down = false,
			startx = 0,
			starty = 0;
			
		$('#hover-map').mousedown(function (e) {
			e.preventDefault();
			down = true;
			startx = e.pageX - intval($('#hover-window').css('left'));
			starty = e.pageY - intval($('#hover-window').css('top'));
		});
		
		$(document).mouseup(function (e) {
			down = false;	
		});
		$(document).mousemove(function (e) {
			if(down) $('#hover-window').css(align(e.pageX - startx, e.pageY - starty));
		});
		
		var img = $('#hover-window img'),
			size = 1,
			orig = {};
		
		$('map area').each(function (i, curr) {
			orig[i] = $.map(curr.coords.split(/\s*,\s*/), function (coord) {
				return intval(coord);
			});
		});
		
		$('#grow').click(function () {
			replaceMap(size += 1, false);
			$('#shrink').prop('disabled', false);
			if (size === 4) $(this).prop('disabled', true); 
		});
		
		$('#shrink').click(function () {
			replaceMap(size -= 1, false);
			$('#grow').prop('disabled', false);
			if (size === 1) $(this).prop('disabled', true);
		});
		
		replaceMap(1, true);
		
		$('#hover-map').bind('mousewheel',function(event,delta) {
			if(delta>0) {
				if(!$('#grow').prop('disabled')) $('#grow').trigger('click');
			} else {
				if(!$('#shrink').prop('disabled')) $('#shrink').trigger('click'); 
			}
			return false;
		});
	}
	function align(left, top, width, height) {
		var minL = 0;
		if(!width) minL = 690 - $('#hover-map img').width();
		else minL = 690 - width;
		if(left > 0 || minL > 0) left = 0;
		else if (left < minL) left = minL;
		
		var minT = 0;
		if(!height) minT = 496 - $('#hover-map img').height();
		else minT = 496 - height;
		if(top > 0 || minT > 0) top = 0;
		else if (top < minT) top = minT; 
		
		return {
			left: left,
			top: top
		};
	}
	function replaceMap(newSize, dontcl) {
		var ratio = (newSize * 1000 - 310) / 2690;
		
		var percentx = ((intval($('#hover-window').css('left')) * -1) + 345) / $('#hover-window > div').width();
		var percenty = ((intval($('#hover-window').css('top')) * -1) + 248) / $('#hover-window > div').height();
		
		if (dontcl !== true) img.parent().remove();
		else $('#hover-window img').remove();
		
		img = $('<img src="/images/sitemap/layer' + newSize + '.png" usemap="#mappy"/>');
		$('map').before(img);
		img.maphilight();
		
		// Align doesn't work here because maphilight hasn't finished putting the new image in
		// can't get the newwidth either
		var newwidth = newSize * 1000 - 310;
		var newheight = intval((1933/2690)*newwidth);
		
		var newleft = intval(percentx * newwidth - 345) * -1;
		var newtop = intval(percenty * newheight - 248) * -1;
	
		$('#hover-window').css(align(newleft,newtop,newwidth,newheight));

		$('map area').each(function (i, curr) {
			curr.coords = $.map(orig[i],function (coord) {
				return Math.round(coord * ratio);
			}).join(',');
		});
	}
	function intval(v) {
		v = parseInt(v);
		return isNaN(v) ? 0 : v;
	}
	function floatval(v) {
		v = parseFloat(v);
		return isNaN(v) ? 0 : v;
	}
})
})(jQuery);
jQuery.fn.random = function() {
    var randomIndex = Math.floor(Math.random() * this.length);  
    return jQuery(this[randomIndex]);
};
