/*
 *	Simple Visual Swap of elements in a UL list when a second UL list is hovered.
 *	Also can automatically swap images based on delay time.
 */
 
var swapTarget;
var inIPhone = false;
var isMobile = false;
var curTarget = 1;
var fading = false;

function initHoverSwap ( s )
{	
/*
	hoverSelector:	'#homepageMenu',
	swapSelector:	'#homepageViews',
	transitionTime:	5
	*/
	swapTarget = s.swapSelector;
	
	// Init over actions
	$( s.hoverSelector+' li a' ).hover( hoverOn, hoverOff );
	
	//$( s.hoverSelector+' li' ).css('border', 'solid 1px #00F');
	
	var deviceAgent = navigator.userAgent.toLowerCase();
	isMobile = Boolean( deviceAgent.match(/(iphone|ipod|ipad)/) );
	
}

function hoverOn ()
{	
	var hoverTarget = $( this ).parent();
	if ( !isMobile ){
			
		/*
		var n = $( this ).index()+1;
		
				$( swapTarget+' li:visible' ).fadeOut('fast');
				$( swapTarget+' li:nth-of-type( 0n+'+n+' )' ).fadeIn('fast');
				
		if ( curTarget!=n ){
			curTarget = n;
			if ( !fading ){
				// Hide current item
				fading = true;
				$( swapTarget+' li:visible' ).fadeOut('slow', function(){
					// Show current item
					fading = false;
					$( swapTarget+' li:nth-of-type( 0n+'+curTarget+' )' ).fadeIn('slow');
				} );
			}
		}
		// */
		
		//*
		// Hide all items
		$( swapTarget+' li' ).css('display', 'none');
		
		// Show current item
		n = hoverTarget.index()+1;
		$( swapTarget+' li:nth-of-type( 0n+'+n+' )' ).css('display', 'block');
		// */
	}
	
	// Remove selected highlight from previous, then add it to the current
	hoverTarget.parent().children( 'li' ).removeClass( 'selected' );
	hoverTarget.addClass( 'selected' );
	
	//hoverTarget.css('border', 'solid 1px #0F0');
	
	/*
	// Hide all items
	$( swapTarget+' li' ).css('display', 'none');
	
	// Show current item
	n = hoverTarget.index()+1;
	$( swapTarget+' li:nth-of-type( 0n+'+n+' )' ).css('display', 'block');
	
	// Remove selected highlight from previous, then add it to the current
	hoverTarget.parent().children( 'li' ).removeClass( 'selected' );
	hoverTarget.addClass( 'selected' );
	
	//hoverTarget.css('border', 'solid 1px #0F0');
	*/
}
function hoverOff ()
{	
	//$( this ).css('border', 'solid 1px #FF0');
}

