var TAB_SELECTOR = "#contentContainer div.tabContainer";
var TOOLTIP_SELECTOR = ".menuItem > a"
var TOOLTIP_ID = "divTT";
var TOOLTIP_CLASS = "tooltip";
var TOOLTIP_JID = "#" + TOOLTIP_ID;

var maxImageContainerWidthInPixels = 528;
var imageSlideshowTransitionPauseInMS = 6000;
var imageSlideshowTransitionDuractionInMS = 2000;
var isFirstSlide = true;

function SelectTab(tabText)
{
	// Attempt to locate the tab with inner text that matches the parameter.
	var tab = $(TAB_SELECTOR + " ul.ui-tabs-nav li:visible a:contains(" + tabText + ")");
	var customMessage = $('#customForSaleMessage');

	if(tab.length == 1)
	{
		tab.click();
	}
	else if(customMessage.length == 1)
	{
		alert(customMessage.text());
	}
	else
	{
		alert("The selected tab, '" + tabText + "', isn't available at this time for this community.\nPlease check back soon as our communities are constantly growing!");
	}
}

function OnCycleBefore()
{
	if (isFirstSlide == true)
	{
		isFirstSlide = false;
	}
	else
	{
		var _element = $(this);

		_element.css("left", (maxImageContainerWidthInPixels - _element.width()) / 2 + "px").css("top", "5px");
	}
}


$(document).ready(function()
{
	$('a.thickbox').colorbox({width:"50%", height:"50%"});
	
	// Set up the UI tabs.
	$(TAB_SELECTOR).tabs();

	$(TOOLTIP_SELECTOR).hover(function(e)
	{
		var target = $(e.target).is("a") ? $(e.target) : $(e.target).parents("a");
		var html = "<div id='" + TOOLTIP_ID + "' class='" + TOOLTIP_CLASS + "'>" + target.attr("rel") + "</div>";

		$(html).appendTo("body");
		
		$(TOOLTIP_JID).css(
		{
			left : (e.pageX + 10) + 'px',
			top : (e.pageY + 10) + 'px'
		});
		
		$(TOOLTIP_JID).show();
	}, function(e)
	{
		$(TOOLTIP_JID).remove();
	});
	
	// Find the current community page navigation tab, and alter the border.
	$("a[href$='/" + BASE_PAGE_NAME + "']").parent().css("border", "solid white 2px");

	$('.slideshowPhotoGallery').cycle(
	{
		timeout : imageSlideshowTransitionPauseInMS,
		speed : imageSlideshowTransitionDuractionInMS,
		before : OnCycleBefore
	});
});

