function clearTextBox(inputBox, textString, cssClass) {
	if (inputBox) {
		if (!textString || inputBox.value == textString) {
			inputBox.value = '';
		}
		if (cssClass) {
			inputBox.className = cssClass;
		}
	}
	return true;
}

function setTextBox(inputBox, textString, cssClass) {
	if (inputBox) {
		if (inputBox.value == '') {
			inputBox.value = textString;
			if (cssClass) {
				inputBox.className = cssClass;
			}
		}
	}

	return true;
}

epcTabClicked = false;
function switchTab(name, noAnchorJump) {
	var selectedTab = document.getElementById('tabbutton-' + name);
	var selectedTabContent = document.getElementById('tab-' + name);
	var selectedTabAnchor = document.getElementById('anchor-' + name);

	if (selectedTab && selectedTabContent) {
		// get the parent DIV of the tabcontents and the tab uls
		var tabUL = selectedTab.parentNode.parentNode;
		var contentsContainer = selectedTabContent.parentNode;

		var tabs = tabUL.getElementsByTagName('a');
		var contents = contentsContainer.getElementsByTagName('div');

		for (var c = 0; c < tabs.length; c++) {
			var tab = tabs[c];
			if (tab.id == 'tabbutton-' + name) {
				tab.className = 'active';
			} else {
				tab.className = '';
			}
		}

		for (var c = 0; c < contents.length; c++) {
			var content = contents[c];
			if (content.id.substr(0, 4) == "tab-") {
				if (content.id == 'tab-' + name) {
					content.style.display = '';
				} else {
					content.style.display = 'none';
				}
			}
		}

		if (!noAnchorJump) {
			//location.href = '#anchor-' + name;
		}

		if (name == "location") {
			google.maps.event.trigger(map, 'resize');
			map.setCenter(mapCenter);
		}

		if (name == "epc" && !epcTabClicked) {
			epcTabClicked = true;
			$('.property-epcband').each(function(i) {
				if (!$(this).hasClass('printable')) {
					var item = $(this);
					var maxValue = item.html();
					if (maxValue > 0) {
						item.html(0);
						setTimeout(function() {
							item.animate({ zIndex: 100 + Number(maxValue), opacity: 1, bottom: item.attr('rel') + 'px' }, { step: function(now, fx) { if (fx.prop == 'zIndex') { item.html(Math.round(now - 100)); } }, duration: 1000 });
						}, 250 * i);
					}
				}
			});
		}
	}
}

$(document).ready(function() {
	$('#options-box ul a').click(function() {
		if (!($(this).hasClass('active'))) {
			var clicked = $(this);
			var id = clicked.attr('id').replace("options-", "");
			$('#options-display .option-box').fadeOut(500);
			$('#options-display #' + id).fadeIn(500);

			$('#options-box ul a').removeClass('active');
			$(this).addClass('active');
		}
		return false;
	});

	$('.gallery-thumb').click(function() {
		var id = $(this).attr('id').replace("main-thumbnail", "");
		$('#main-image').cycle(Number(id) - 1);
		$('.property-thumbnail img').removeClass('active');
		$(this).addClass('active');
	});

	$('#main-image').cycle({
		fx: 'fade',
		timeout: 5000,
		speed: 500,
		before: function() {
			var id = $(this).attr('id').replace("main-image", "");
			$('.property-thumbnail img').removeClass('active');
			$('#main-thumbnail' + id).addClass('active');
		}
	});
	$('#main-image').cycle('pause');

	$('#slideshow-link').click(function() {
		if ($(this).html() == "Play Slideshow") {
			$('#main-image').cycle('resume');
			$(this).html('Stop Slideshow');
		} else {
			$('#main-image').cycle('pause');
			$(this).html('Play Slideshow');
		}
	});
});
