$(document).ready(function() {
	
	if ( $("body.home").length > 0)
	{
		$('.promo-slider .inner-content').hide();
		$('.promo-slider .cycle').cycle({
			fx: 'scrollDown',
			timeout: 8000,
			slideResize:   0,
			containerResize: 0,
			pause : 1,
			before : function(currSlide,nextSlide) {
				if ($('.promo-slider .content .inner').text() == '')
					$('.promo-slider .content .inner').html( $('.promo-slider .inner-content:first-child').html() );
				else
					$('.promo-slider .content .inner p').fadeOut(500);
			},
			after : function(currSlide,nextSlide) {
				$('.promo-slider .content .inner').html( $('.inner-content',nextSlide).html() );
				$('.promo-slider .content .inner p').hide();
				$('.promo-slider .content .inner p').fadeIn(500);
			}
			
		});
		
		$('.gallery .cycle').cycle({
			fx: 'scrollHorz',
			timeout: 0, 
		    next:   '.gallery .next', 
		    prev:   '.gallery .prev' 
		});
	}
	
	$(".fancybox").fancybox({
		overlayColor: '#000',
		overlayOpacity: 0.8
	});
	
	
	$('.gallery .upload-picture form, #contact-form').validate();
	
	$('#signup-form').validate({
		rules : {
			'cm-name': {
				required: function(e) {
					if ($(e).hasClass('switch') && $(e).val() == $(e).attr('rel'))
						$(e).val('');
					return true;
				}
			},
			'cm-xiuhtj-xiuhtj': {
				required: function(e) {
					if ($(e).hasClass('switch') && $(e).val() == $(e).attr('rel'))
						$(e).val('');
					return true;
				},
				email: true
			}
		}
	});
	
	$(".switch").each( function() {
		if ( $(this).val() == '' )
			$(this).val( $(this).attr('rel') );
			
		$(this).focus( function() { 
			if ( $(this).val() == $(this).attr('rel') || $(this).val() == '' )
			{
				$(this).val('');
				$(this).addClass('normal');
			}	
		});
		$(this).blur( function() { 
			if ( $(this).val() == '' )
			{
				$(this).val( $(this).attr('rel') );
				$(this).removeClass('normal');
			}	
		});
	});
	
	if ( $('#contact-form').length > 0 )
	{
		var url = document.location.toString();
		if (url.match('#thanks'))
		{
			$('#success').html("<p>Thanks for sending us a message. We'll get back to you shortly!</p>")
			$('#success').show();
		}
	}
	
	if ( $(".sub-nav").length > 0)
	{
		$(".sub-nav li:last-child").removeClass('last').addClass('last');
	}
	
});
