$(document).ready(function(){


	// SUB-NAV BEHAVIOR 
	
	var subNavOn = function() {
		$(this).unbind('mouseenter',subNavOn) ;
		$(this).find('div.sub-nav').hide()
								   .stop(false,true)
								   .slideDown(200) ;
	} ;
	
	var subNavOff = function() {
		var $this = $(this) ;
		$this.find('div.sub-nav').stop(false,true)
								   .slideUp(200,function(){
									   $this.bind('mouseenter',subNavOn) ;
								   })  ;
	}
	
	$('div.nav-block').hover(subNavOn,subNavOff) ;


	// SLIDESHOW BEHAVIOR

	$('#slideshow div.slideshow-container:first').css('zIndex',100) ;
	var startPhoto = $('#slideshow div.slideshow-container').length - 1 ;
	rotatePics(startPhoto,4500,1000) ; // currentPhoto = 4 to start properly from the beginning
	
	function rotatePics(currentPhoto,stepTime,fadeTime) {
		var divSet = $('#slideshow div.slideshow-container')
		var numberOfPhotos = divSet.length ;
		currentPhoto = currentPhoto % numberOfPhotos ;
		
		divSet.eq(currentPhoto).fadeOut(fadeTime,function(){
			divSet.each(function(i) {
				var zDex = ((numberOfPhotos - i) + currentPhoto) % numberOfPhotos ;
				$(this).css('zIndex',zDex) ;
			}) ;
			$(this).show() ;
			
			setTimeout(function(){rotatePics(++currentPhoto,stepTime,fadeTime);},stepTime) ;
		}) ;
	}
	
	
	
	// CONSTANT CONTACT FORM BEHAVIOR
	$('#optIn input:text').each(function(){

		$(this).data('default',$(this).val())
			   .addClass('inactive') 
			   .focus(function(){
					$(this).removeClass('inactive') ;
					if ($(this).val() == $(this).data('default') || '' ) {
						$(this).val('') ;
					}
				})
			   
			   .blur(function(){
					var default_val = $(this).data('default') ;
					if ($(this).val() == '' ) {
						$(this).addClass('inactive') ;
						$(this).val($(this).data('default')) ;
					}
				})
	}) ;
	
	
	// contact button slider 
	$('a.contact-link').hover(function(){
		$(this).stop(true,true).animate({paddingLeft:'40px'},150) ;
	},function(){
		$(this).stop(true,true).animate({paddingLeft:'0'},150) ;
	}) ;
	
	
}) ;
