// JavaScript Document

	// homepage slider vars and functions
	var gallery = false;
	var galleryIndex = 0;
	var galleryPaused = true;
	var galleryAction = false;
	var gallerySpeed = 1000;	// 1000
	var galleryTime = 4000;		// 5000
	function sliderForward() {
		galleryIndex++;
		if (galleryIndex >= gallery.length) {
			galleryIndex = 0;
		}
		sliderUpdate(galleryIndex);
	}
	function sliderPlay() {
		$('#slider_play').addClass('pause');
		galleryPaused = false;
		galleryAction = setInterval('sliderForward()', galleryTime);
	}
	function sliderUpdate(index) {
		if ($('#slider')) {
			$('#slider_caption').fadeOut(gallerySpeed);
			$('#slider_image').fadeOut(gallerySpeed, function() {
				$('#slider').css('background-image', 'none');			
				$('#slider_image').css('background-image', 'url(' + gallery[index].path + ')');
				$('#slider_image').css('background-position', 'top center');
				$('#slider_caption').html(gallery[index].caption);
				$('#slider').click(function() { 
					if (gallery[index].extlink)
					{
						window.location = gallery[index].extlink;
					}
					else
					{
						window.location = '/properties/office/' + gallery[index].id;
					}
				} );
				$('#slider_image').fadeIn(gallerySpeed);
				$('#slider_caption').fadeIn(gallerySpeed);
			} );
		}
	}

	// external launch
	function external_launch(href) {
//		newwin = window.open(href, 'newwin', 'height=' + $(window).height() + ',width=' + $(window).width());
		newwin = window.open(href, 'newwin', 'height=' + screen.height + ',width=' + screen.width + ',status=1,toolbar=1,location=1,menubar=1,resizable=1,scrollbars=1');
		newwin.focus();
		return false;
	}

	// space availabilities
	function select_all(){$('#fsLocation input[type=checkbox]').attr('checked', 'checked');}
	function select_some(id){$('#opts' + id + ' input[type=checkbox]').attr('checked', 'checked');}
	function deselect_all(){$('#fsLocation input[type=checkbox]').attr('checked', '');}

// document is ready
$( function() {

	// zebra-stripe tables
	$('.tableHoriz tr:odd').addClass('zebra');

	// sort tables
	$('.tableSort').tablesorter();

	// external links
	$('a[rel=external], a.pdf, a.pdfS').click(function() {
		return external_launch(this.href);
	} );

	// default values
	$('.inputDefault').focus(function() {
		this.value = '';
		$(this).removeClass('inputDefault');
	} );

	// homepage slider
	if (document.getElementById) {
		if (document.getElementById('slider')) {
			// ability to click on slider_info and slider independently
			$('#slider_info').click( function(e) {
				e.stopPropagation();
			} );
			if ($('#slider')) {
				// ajax info and update slider
				gallery = fast_gallery;
			}
			// auto-play
			sliderPlay();
		}
	}

	// nav rollover
	$('#nav li').hover(
		function ()
		{
			if (this.id)
			{
				var id = this.id;
				var height = $('#' + id).height();
				$('#' + id + ' ul').show().css('top', height);
			}
		},
		function ()
		{
			if (this.id)
			{
				var id = this.id;
				$('#' + id + ' ul').hide();
			}
		}
	);

	// property hovers
	$('.photo img').mouseleave(function() {
		$(this.parentNode.parentNode.firstChild).css('display', 'none');
	} ).mouseenter(function() {
		$(this.parentNode.parentNode.firstChild).css('display', 'block');
	} );

	// map
	if (document.getElementById('webMap')) {
		$(window).load(function () {
			map.init();
		} );
		$(window).unload(function () {
			GUnload();
		} );
	}

	// lightbox
	$('a[rel=lightbox]').lightBox();

} );