function jcarousel_initCallback(carousel) {
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

var katz = {
	init : function() {
		$('#mc_embed_signup').dialog({
			autoOpen: false,
			buttons: {
				'Sorry, I get enough email. Just close this window, will you?': function() {
					$(this).dialog('close');
				}
			},
			draggable: false,
			modal: true,
			resizable: false,
			width: 510
		});			
		$('.signup-form-popup-link').click(function(event){
			event.preventDefault();
			$('#mc_embed_signup').dialog('open');
			return false;
		});
	},
	contact: function() {

		var element = jQuery('.header-contact-content');		
		var duration = 400;
		var easing = 'bounceout';
		var opacity = 0.5;
		var closedheight = 6;
		var openheight = 139;
	
		jQuery('.header-contact-content-background').css({
			'opacity' : 0.5
		});
		
		jQuery('.header-contact-tab a').click(function(event){
			
			event.preventDefault();
	
			var height = closedheight;
			
			if(element.height() == closedheight) {
				height = openheight;
				jQuery('#fade').css('visibility','visible');
			}
			else {jQuery('#fade').css('visibility','hidden');}
			
			element.animate({
				'height' : height
			},{
				'queue' : false,
				'duration' : duration,
				'easing' : easing
			});
		
		});	
	},
	carousel: function() {
		var jcarousel_config = {
	    	'auto' : 5,
	        'easing' : 'easeInBack',
	        'scroll' : 1,
	        'wrap' : 'last',
	        initCallback: jcarousel_initCallback
	    };
	    
	    jQuery('.biography-splash ul, .homepage-splash ul, .projects-splash ul').jcarousel(jcarousel_config);
	},
	
	philosophy: function() {
		$('.philosophy-splash li').hover(
			function(event){
				$('.ps-content', this).animate({
					'backgroundColor' : '#ffffff',
					'color' : '#00aeef'
				},600);
				$('.ps-footer', this).animate({
					'height' : 60
				},{
					queue:false,
					duration:600,
					easing: 'easeOutBounce'
				});
			},
			function(event){
				$('.ps-content', this).animate({
					'backgroundColor' : '#00aeef',
					'color' : '#ffffff'
					
				},600);	
				$('.ps-footer', this).animate({
					'height' : 0
				},{
					queue:false,
					duration:600,
					easing: 'easeOutBounce'
				});
			}
		);
	},
	
	portfolio: function() {
		var opacity = 1;
		var bgcolor = '#b2e7fa';
		$('.project-row').css({
			'backgroundColor' : bgcolor
		});
		$('.project').css({
			'backgroundColor' : bgcolor
		}).hover(
			function(){
				$(this).stop().animate({
					'backgroundColor' : '#ffffff'
				},{'duration' : 500});
				$('.project-thumb-overlay',this).stop().animate({
					'opacity' : 0
				},{
					'duration' : 500
				});
			},
			function(){
				$(this).stop().animate({
					'backgroundColor' : bgcolor
				},{
					'duration' : 500
				});
				$('.project-thumb-overlay',this).stop().animate({
					'opacity' : opacity
				},{
					'duration' : 500
				});
			}
		);
	}
}

$(document).ready(function(){
	katz.init();
	katz.contact();
	katz.carousel();
	katz.philosophy();
	katz.portfolio();
});
