$(document).ready(function() {

  // floor plan - entire space active / rollover others
  $('#floorplan').each(function() {
    var $floorplan = $(this),
        floorRight = $floorplan.offset().left + 136,
        $entireSpace = $floorplan.find('li.entire-space a');

    $floorplan.bind('mouseover', function(event) {
      var $tgt = $(event.target);
      floorRight = $floorplan.offset().left + 136;

      if ( $entireSpace.is('.active') && event.pageX < floorRight) {
        $entireSpace.addClass('hidden');
        return;
      }

      if ( $tgt.parent().is('.entire-space') ||
        ( $entireSpace.is('.active') && !$tgt.closest('a').length )
      ) {

        $entireSpace.removeClass('hidden');
      } else {
        $entireSpace.addClass('hidden');
      }

    }).bind('mouseleave', function() {
      $entireSpace.removeClass('hidden');
    })
    .bind('mousemove', function(event) {
      if ( event.pageX < floorRight) {
        $entireSpace.addClass('hidden');
      }
    });

  });

	//intro paragraphs
  // $('#content-main p:first').addClass('p-first');

	//append bullets to list nav for properly sized bullet with hover states
	$('#nav-quick li:not(.nav-phone) a').prepend('&bull;&nbsp;');

	//zoom in map
	$('#map-zoom .images')
	.after('<div class="nav"></div>')
	.cycle({
	    fx:     'fadeZoom',
	    speed:  300,
			pager: '#map-zoom .nav',
			next: '#map-zoom .images',
	    timeout: 0,
			pagerAnchorBuilder: function(idx){
				return '<a href="#"><span class="nav-' + (idx+1) + '">Zoom Out/In</span></a>';
			}
	});

	//slideshow cycle for homepage
	var $slideshowImages = $('div.slideshow div.images'),
	    numImages = $slideshowImages.children().length;
	if (numImages > 1) {
  	$slideshowImages
  	.before('<div class="nav"></div>')
  	.cycle({
  	    fx: 'scrollHorz',
  	    autostop: true,
  	    autostopCount: numImages+1,
  	    speed:  300,
  	    timeout: 6000,
        next: '.slideshow .images',
  	    pager:  'div.slideshow div.nav:first',
  			pagerAnchorBuilder: function(){
  				return '<a href="#">&bull;</a>';
  			}
  	});
  	if ($('body').is('.events')) {
  	  $('#content-feature .content-one').css({marginTop: $slideshowImages.prev('.nav').height() || 0});
  	}
  }
	// events calendar - weekend class
	$('table.mini-cal').find('td:nth-child(6), td:last-child').addClass('weekend');
});

/** =Reservations form validation
************************************** */

$(document).ready(function() {
  if (typeof $.fn.tinyvalidate != 'undefined') {
    $('#reservations-form').tinyvalidate({
      positionElement: ['inline', '#submitrequest'],
      positionType: 'after',
      submitDetails: false,
      wrapper: '<span></span>',
      preNotice: 'some information that we need is missing',
      primaryEvent: 'submit',
      secondaryEvent: null
    });
  }
});
