$(document).ready(
	function() {
	
	// Cycle Settings
		// Basic Slideshows
		if ($('.slideshow').length) {
			$('.slideshow').cycle({
				random: false
			});
		};
		// Homepage Photo Slideshow
		if ($('#featured-photos .slideshow').length) {
			$('#featured-photos .slideshow').cycle({
				random: false
			});
		};
	
	// Fancybox Settings
		// Lightbox
		if ($('.lightbox').length) {
			facebookURL = 'http://www.facebook.com/pages/Halfway-Cafe/196848572138?v=photos'
			function facebookTitle(title, currentArray, currentIndex, currentOpts) {
				return '<div id="fancybox-title-custom">' + (title && title.length ? title : '' ) + '<div id="fancybox-facebook-link"><a href="' + facebookURL + '" target="_blank">More Photos on Facebook &raquo;</a></div></div>';
			}
			$('.lightbox').fancybox({
				titlePosition: 'inside'
			});
			$('.lightbox-image').fancybox({
				titlePosition: 'inside',
				titleFormat: facebookTitle
			});
			$('.lightbox-iframe').fancybox({
				width: '90%',
				height: '90%',
				autoScale: false,
				type: 'iframe',
					titlePosition: 'inside',
					onClosed: function() { $("#fancybox-inner").empty(); }
			});
			$('.lightbox-pdf').click(function() {
				$.fancybox({
					width: '75%',
					height: '90%',
					autoDimensions: false,
					content: '<iframe src="'+this.href+'" width="100%" height="100%" frameborder="0"></iframe>',
					//content: '<object type="application/pdf" data="'+this.href+'" width="100%" height="100%"><param name="src" value="'+this.href+'" /></object>',
					titlePosition: 'inside',
					onClosed: function() { $("#fancybox-inner").empty(); }
				});
				return false;
			});
		};
	
	// Media Settings		
		// Default Players
		$.fn.media.defaults.flvPlayer = 'media/flvplayer.swf';
		$.fn.media.defaults.mp3Player = 'media/mediaplayer.swf';
		
		// Videos
		if ($('.video').length) {
			$('.phantom-video').media({
				width: '250',
				height: '215',
				bgColor: 'transparent',
				params: { wmode: 'transparent', menu: 'false', allowfullscreen: true },
				caption: false
			});
			$('.video').media({
				width: '250',
				height: '215',
				bgColor: 'transparent',
				params: { wmode: 'transparent', menu: 'false', allowfullscreen: true }
			});
		};
		// Jingle
		if ($('#jingle').length) {
			$('#jingle').media({
				src: 'media/halfwayjingle.mp3',
				width: '17',
				height: '19',
				bgColor: 'transparent',
				autoplay: true,
				params: { wmode: 'transparent', menu: 'false' },
				flashvars: { autostart: true, volume: 25 },
				caption: false
			});
		};
		// World Famous Banner
		if ($('#world-famous-banner').length) {
			$('#world-famous-banner').media({
				src: 'media/world-famous.swf',
				width: 575,
				height: 82,
				bgColor: 'transparent',
				params: { wmode: 'transparent', menu: 'false' },
				caption: false
			});
		};
		// Maynard Countdown Promo
		if ($('#promo-maynard-countdown').length) {
			$('#promo-maynard-countdown').media({
				src: 'media/countdown/promo-maynard-countdown.swf',
				width: 263,
				height: 215,
				bgColor: 'transparent',
				params: { wmode: 'transparent', menu: 'false', base: 'media/countdown/' },
				caption: false
			});
		};
		if ($('#maynard-countdown').length) {
			$('#maynard-countdown').media({
				src: 'media/countdown/maynard-countdown.swf',
				width: 360,
				height: 118,
				bgColor: 'transparent',
				params: { wmode: 'transparent', menu: 'false', base: 'media/countdown/' },
				caption: false
			});
		};
		// Text Replacement
		if ($('h2.page-title').length) {
			$('h2.page-title span').media(function(el, options) {
				options.caption = false;
				options.src = 'media/jfr_cooperblack.swf';
				options.height = $(el).height();
				options.width = $(el).width();
				options.bgColor = 'transparent';
				options.flashvars = {
					css: [ '* { color: #0e9344; text-align: center; }', 'a { color: #006633; }', 'a:hover { color: #003300; }' ].join(' ')
				};
				options.flashvars.txt = $(el).text();
			});
		};
	
		// Form Validation Settings
		if ($('form#form-holbrook-functions').length) {
			$.validator.addMethod("phoneUS", function(phone_number, element) {
				phone_number = phone_number.replace(/\s+/g, ""); 
				return this.optional(element) || phone_number.length > 9 &&
					phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
			}, "Please enter a valid phone number.");
			$('input.phone-us').mask('(999) 999-9999');
			$('input.date').mask('99/99/9999');
			$('form#form-holbrook-functions').validate({
				rules: {
					holbrook_functions_first_name: 'required',
					holbrook_functions_last_name: 'required',
					holbrook_functions_email: {
						required: true,
						email: true
					},
					holbrook_functions_phone: {
						required: true,
						phoneUS: true
					},
					holbrook_functions_guests: 'required',
					holbrook_functions_event_type: 'required',
					holbrook_functions_preferred_date: 'required',
					holbrook_functions_preferred_time: 'required'
				},
				messages: {
					holbrook_functions_first_name: 'Please enter your first name.',
					holbrook_functions_last_name: 'Please enter your last name.',
					holbrook_functions_event_type: 'Please select a type of event.'
				}
			});
		};
	
	});
