$(document).ready(function() {
  // Wedding Calendar
  $('.calendar').each(function() {
    var defaultText = 'Select a Date';
    var display = $('<div/>', {'class': 'display'}).html(defaultText);

    $(this).find('table').each(function() {
      table = this;

      $(this).tableHover({
        colClass: 'hover'
      });

      $(this).find('tr').each(function() {
        for($i=5; $i<$(this).find('td').length; $i+=7) {
          $(this).find('td:eq('+$i+'), td:eq('+($i+1)+')').addClass('weekend');
        }
      });

      $(this).find('a').hover(function() {
        $(display).html($(this).attr('title')).removeClass('indulgence opulence sumptuous wedding booked provisional').addClass($(this).parent().attr('class'));
      }, function() {
        $(display).html(defaultText).removeClass('indulgence opulence sumptuous wedding booked provisional').addClass($(display).attr('rel'));
      }).click(function() {
        $(display).attr('rel', $(this).parent().attr('class'))
        defaultText = $(this).attr('title');
        $(table).find('.selected').removeClass('selected');
        $(this).parent().addClass('selected');
        $('#date').val($(this).attr('rel'));
        return false;
      });

      $(this).before($('<span/>', {'class': 'info'}).html('Please roll your mouse over dates to see prices.'));
    });

    $(this).append(display);
  });

  // Wedding Itinerary Tabs
  $(".itinerary").tabs({
    cookie: { expires: 30 }
  });

  $('a[rel="fancybox"]').fancybox({
		'zoomOpacity'         : true,
		'overlayShow'         : false,
		'zoomSpeedIn'       	: 500,
		'zoomSpeedOut'        : 500,
		'transitionIn'        : 'elastic',
		'transitionOut'       : 'elastic',
		'easingIn'          	: 'easeOutBack',
		'easingOut'       		: 'easeInBack',
		'hideOnContentClick'	: false,
    'centerOnScroll'  : true
	});

	$('.submit input').focus(function() {
		$(this).attr('src', '/media/images/buttons/submit-focus.gif');
	}).blur(function() {
		$(this).attr('src', '/media/images/buttons/submit.gif');
	});
	$('.login input').focus(function() {
		$(this).attr('src', '/media/images/buttons/login-focus.gif');
	}).blur(function() {
		$(this).attr('src', '/media/images/buttons/login.gif');
	});
  
	$(".date").datepicker({
		dateFormat: 'dd/mm/yy',
		onClose:
			function() {
				$(this).parents('form').submit();
			}
	});
	$(".save").hide();

  // Add close buttons to info flashes.
  $('.info').prepend($('<a/>', {'href': '#', 'css': {'float': 'right', 'padding': '0 2px'}}).html('X').click(function() {
    $(this).parent().fadeOut();
    return false;
  }));

  // Delay fade non-persist success flashes.
  $('.success:not(.persist)').delay(2000).fadeOut('slow').remove(1);
});

// Google Analytics
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-8205962-3']);
_gaq.push(['_trackPageview']);

(function() {
  var ga = document.createElement('script');
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' :
      'http://www') + '.google-analytics.com/ga.js';
  ga.setAttribute('async', 'true');
  document.documentElement.firstChild.appendChild(ga);
})();