

// --------------------------------------------------------------------

function expandFlyout () {
	// console.log('over');
	
	if ( $flyout.hasClass( 'contracted' ) ) {
		$flyout.animate( {  
			width: "410px"
		}, 750 ).removeClass( 'contracted' ).addClass( 'expanded' );
		
		// Always the opposite of the current state
		jQuery( '#secondary-hide-one > a' ).text('Full Image');
		jQuery( '#secondary-hide-two' ).css('visibility', 'visible');			
	}
}

// ------------------------------------------------------------------

function contractFlyout () {
	// console.log('out');
	
	if ( $flyout.hasClass( 'expanded' ) || $flyout.hasClass( 'init' ) ) {
		$flyout.animate( {
			width: "145px"
		}, 750 ).removeClass( 'expanded' ).addClass( 'contracted' );
		
		// Always the opposite of the current state
		jQuery( '#secondary-hide-one > a' ).text('Show Text');
		jQuery( '#secondary-hide-two' ).css('visibility', 'hidden');		
	}
	
	if ( $flyout.hasClass( 'init' ) ) {
		$flyout.removeClass( 'init' );
	}
}

// ------------------------------------------------------------------

function mouseoutBackground () {
	return true;
} 

// ------------------------------------------------------------------

// add images to slideshow 
function onBefore(curr, next, opts) { 
	if (opts.addSlide) { // <-- important! 
		
		/*
		while(stack.length) {
			opts.addSlide(stack.pop());  
		}
    */
    
		/*  Alternatively, we can wait for all the other images to load and
			add them in one go.
		*/
		
		
		if ( stack.length == images.length ) {
			while(stack.length) {
				opts.addSlide(stack.pop());  
			}
		} 
		
		resizeWin(true); // Call to set image heights/widts for rest of images.
		

		jQuery('#background img').unbind("contextmenu");
		jQuery('#background img').bind("contextmenu", function(e) {
			  alert(copyrightMessage);
			  return false;
			}
		);

	}
}

// ------------------------------------------------------------------

jQuery( document ).ready( function () {
	window.$flyout = jQuery( '#flyout' );
	window.$background = jQuery( '#background' );
	window.copyrightMessage = "Copyright 2009 Archer's Hall Design Center";
  
	// Disable right clicking on images.
	jQuery('#background img').bind("contextmenu", function(e) {
		  alert(copyrightMessage);
		  return false;
		}
	);
	
     
	/* HOVER 
	 -------------------------------------------------------------- */
	var hoverIntentConfig = {    
		 sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 200, // number = milliseconds for onMouseOver polling interval    
		 over: expandFlyout, // function = onMouseOver callback (REQUIRED)    
		 timeout: 500, // number = milliseconds delay before onMouseOut    
		 out: contractFlyout // function = onMouseOut callback (REQUIRED)    
	};
	
	$flyout.hoverIntent( hoverIntentConfig );
	
	// Contract the flyout when the user hovers over the background images.
	$background.hoverIntent( contractFlyout, mouseoutBackground );

	// Add click handlers to hide the content/menu
	jQuery('#secondary-hide-one > a').click( function () {

		if ( $flyout.hasClass( 'expanded' ) ) {
			contractFlyout();
		} 
		else if ( $flyout.hasClass( 'contracted' ) ) {
			expandFlyout();
		}
	});

	jQuery('#secondary-hide-two').click( function () {
		if ( $flyout.hasClass( 'expanded' ) ) {
			contractFlyout();
		} 
		else if ( $flyout.hasClass( 'contracted' ) ) {
			expandFlyout();
		}
	});
	
	// Disable right clicks on images.
	jQuery(window).load( function () {
		jQuery('img').bind("contextmenu",function(e){
			return false;
		});
	});
	
	/* CYCLE - Preloads the image into the cycle. 
	 -------------------------------------------------------------- */		
	// preload the remaining images
	if ( window.images !== null ) {
		remainingImages = window.images.length;	// window.images is set by the PHP script when it loads the background images.
	
		for (var i = 0; i < remainingImages; i++) { 
			var img = new Image(); 
			img.src = 'SiteAssets/' + window.images[i]; 
	
			// When the image loads, put itself into the stack
			jQuery(img).bind('load', function() { 
				stack.push(this); 
			}); 
		}  
	}
	
	/* FORMS
	 -------------------------------------------------------------- */	
	jQuery("label").inFieldLabels();
	jQuery("input").attr("autocomplete","off");
	
	
	/* MUSIC
	 ------------------------------------------------------------- */

	// alert('Document Ready.');
	
	// jPlayer

	//console.log()

	
});



