var rotating_path = '/images/rotating/index_'	
			
rotating_image = new Array()

rotating_image[0] = rotating_path + '2' + '.png'
rotating_image[1] = rotating_path + '3'	+ '.png'
rotating_image[2] = rotating_path + '4'	+ '.png'
rotating_image[3] = rotating_path + '5'	+ '.png'
rotating_image[4] = rotating_path + '6'	+ '.png'
rotating_image[5] = rotating_path + '7'	+ '.png'
rotating_image[6] = rotating_path + '1' + '.png'

function updateActiveMenu()
{
	var active = $jq( '#active_page' ).val()
	if( active != 'index' )
	{
		var img = $jq( '#' + active ).find( 'img' )
		var src = img.attr( 'src' )
		var new_src = src.replace( 'off', 'over' )

		$jq( img ).attr( 'src', new_src )
	} // if
} // updateActiveMenu
var element, timer

function showDropdown()
{
	if( $jq( this ).is( 'ul' ) )
		clearTimeout( timer )
		
	$jq( this ).find( '.dropdown' ).css( { 'display':'inline' } )
	
} // showDropDown

function actualHideDropdown()
{
	element.find( '.dropdown' ).hide()
} // actualShowDropdown

function hideDropdown()
{
	element = $jq( this )
	timer = setTimeout( "actualHideDropdown()" , 100 );
	
} // hideDropdown

function checkRotation()
{
	if( $jq( '#main_image' ).attr( 'src' ) == '/images/rotating/index_7.png' )
		setTimeout( "rotateImage()", 5000 )
		
} // checkRotation

function rotateImage()
{
	var rotating_path = '/images/rotating/index_'	
			
	rotating_image = new Array()
	
	rotating_image[0] = rotating_path + '2' + '.png'
	rotating_image[1] = rotating_path + '3'	+ '.png'
	rotating_image[2] = rotating_path + '4'	+ '.png'
	rotating_image[3] = rotating_path + '5'	+ '.png'
	rotating_image[4] = rotating_path + '6'	+ '.png'
	rotating_image[5] = rotating_path + '7'	+ '.png'
	rotating_image[6] = rotating_path + '1' + '.png'
	
	var i
	
	for( i=0; i<rotating_image.length; i++ )
	{
		setTimeout( "$jq( '#main_image' ).fadeOut( 'slow', function(){ $jq( '#main_image' ).attr( 'src', '" + rotating_image[i] + "').fadeIn( 'slow' ); checkRotation(); } )", 5000 * (i+1) ) 
	} // for
} // rotateImage

function click_thumbnail()
{
	//make sure we have something to click
	if( $jq( this ).attr( 'id' ) != '' )
	{
		// hide the grid
		$jq( '#meet_our_team img.thumbnail, #meet_our_team .caps' ).hide()
		
		// remove any previous content
		$jq( 'div.p_wrap.visible' ).remove()
		
		//show the active thumb
		$jq( this )
			.show()
			.parent()
				.css( { 'height':'600px' } )
		
		
		var active_thumb, active_thumb_object
		active_thumb_object = $jq( this )
		active_thumb = $jq( this ).attr( 'id' ).replace( 'thumb_', '' )
		
		
		// hide anything from previous clicks
		$jq( 'body' )
			.find( '.visible' )
				.removeClass( 'visible' )
				.hide()
		
		// grab the active profile
		var profile = $jq( 'div#' + $jq( this ).attr( 'alt' ).toLowerCase() )
		
		// different view for Torrey and Jamie
		if( profile.hasClass( 'owner' ) )
			profile.find ('p, div' ).addClass( 'owner' )
		
		// make the active profile visible
		/*
profile
			.find( 'p, div' )
				.addClass( 'visible' )
*/
				
		// grab the content
		var content = $jq( profile.html() )
		
		// grab the headline
		var headline = $jq( '<img class="clear visible" src="/images/our_team/headline/' + $jq( this ).attr( 'alt' ).toLowerCase() + '.png" alt="' + $jq( this ).attr( 'alt' ) + '" />' )
		
		// add the content to the page
		content.insertAfter( $jq( this ) )
		
		// add the headline to the page
		content
			/* .prepend( headline ) */
			.find( 'p, div' )
				.addClass( 'visible' )
		
		if( active_thumb != 1 && active_thumb != 2 )
			content.prepend( headline )
		
		$jq( '.active' ).show()
	
		
		// show and hide arrows based on profile
		$jq( 'div#arrows' ).show()
		
		
		
		// hide the next button if it's the last profile
		if( active_thumb == 17 )
			$jq( 'img#next_stylist' ).hide()
		
		else
			$jq( 'img#next_stylist' ).show()
		
		// hide the previous button if it's the first profile
		if( active_thumb == 1 )
			$jq( 'img#previous_stylist' ).hide()
			
		else
			$jq( 'img#previous_stylist' ).show()
		
		// remove the click on this img to cancel double clicking		
		//$jq( this ).unbind( 'click' )
		
		// change the address bar
		window.location.hash = $jq( this ).attr( 'alt' )
		
		//link the headline
		$jq( 'img#headline' )
			.wrap( '<a href="/our_team/meet_our_team/"></a>' )
			.css( { zIndex: 5432 } )
				
	} // if
} // click_thumbnail

function get_active_thumb()
{
	var hash = window.location.hash
	var thumb = $jq( 'img[alt=' + hash.replace( '#', '' ) + ']' )
	
	return thumb
} // get_active_thumb

function next_stylist()
{
	var next_thumb, next, active_thumb
	var active_thumb_object = get_active_thumb()
	
	//active_thumb_object.bind( "click", "click_thumbnail" )
	
	active_thumb = active_thumb_object.attr( 'id' ).replace( 'thumb_', '' )
	active_thumb *= 1
	
	if( active_thumb == 12 )
		window.location = '/our_team/meet_our_team2/#Vanessa'
								
	next_thumb = active_thumb + 1
	
	// Hack to get around loss of #9
	if( next_thumb == 9 )
		next_thumb = 10
	
	if( next_thumb < 10 )
		next_thumb = '0' + next_thumb
	
	next = 'thumb_' + next_thumb

	$jq( 'img#' + next ).show().click()
} // function


function previous_stylist()
{	
	
	var prev_thumb, prev, active_thumb
	var active_thumb_object = get_active_thumb()
	
	//active_thumb_object.bind( "click", "click_thumbnail" )
	
	active_thumb = active_thumb_object.attr( 'id' ).replace( 'thumb_', '' )
	active_thumb *= 1
	
	if( active_thumb == 13 )
		window.location = '/our_team/meet_our_team/#Maureen'
		
	prev_thumb = active_thumb - 1
	
	// Hack to get around loss of #9
	if( prev_thumb == 9 )
		prev_thumb = 8
		
	if( prev_thumb < 10 )
		prev_thumb = '0' + prev_thumb
		
	prev = 'thumb_' + prev_thumb
	
	$jq( 'img#' + prev ).show().click()

} // function

function get_i( i )
{
	if( i == 6 )
		return 0
	
	else
		return i
} // get_i

$jq( document ).ready(
	function()
	{

	
		$jq( '#navigation li' ).hover(
			function()
			{
				if( ! $jq( this ).hasClass( 'active' ) )
				{
	
					var src = $jq( this ).find( 'img' ).attr( 'src' )
					var new_src = src.replace( 'off', 'over' )
				
					$jq( this ).find( 'img' ).attr( 'src', new_src )
				} // if
				
				
			}, // function
			
			function()
			{	
				if( ! $jq( this ).hasClass( 'active' ) )
				{
					var src = $jq( this ).find( 'img' ).attr( 'src' )
					var new_src = src.replace( 'over', 'off' )
					$jq( this ).find( 'img' ).attr( 'src', new_src )
				} // if
				/* $jq( '#navigation_dropdown' ).hide() */
			} // function
		) // hover
		
		$jq( '#navigation li, ul.dropdown' ).hover( showDropdown, hideDropdown )
		
		$jq( '#navigation li' ).click( 
			function()
			{ 
				window.location = $jq( this ).find( 'a' ).attr( 'href' ) 
			} 
		)
		

		if( $jq( '#active_page' ).val() == 'index' )
		{
			var rotating_path = '/images/rotating/index_'	
			
			rotating_image = new Array()
			
			rotating_image[0] = rotating_path + '2' + '.png'
			rotating_image[1] = rotating_path + '3'	+ '.png'
			rotating_image[2] = rotating_path + '4'	+ '.png'
			rotating_image[3] = rotating_path + '5'	+ '.png'
			rotating_image[4] = rotating_path + '6'	+ '.png'
			rotating_image[5] = rotating_path + '7'	+ '.png'
			rotating_image[6] = rotating_path + '1' + '.png'
			
			var i
			
			//preload
			for( i=0; i<rotating_image.length; i++ )
			{
				var image = new Image()
				image.src = rotating_image[i]
			} // for
			
			//rotateImage()
			var c = 0
			for( i=0; i<rotating_image.length; i++ )
			{
				
				setTimeout( "$jq( '#main_image' ).fadeOut( 'slow', function(){ $jq( '#main_image' ).attr( 'src', '" + rotating_image[i] + "').fadeIn( 'slow' ); checkRotation(); } )", 5000 * (i+1) ) 
								
			} // for
			
			
		} // if
			
		updateActiveMenu()
		
		//! Preload Images
		var path = '/images/nav/over_'		

		var i = 0

		imageObj = new Image()

		images = new Array()
		images[0] = path + 'services.png'
		images[1] = path + 'our_team.png'
		images[2] = path + 'locations.png'
		images[3] = path + 'products.png'
		images[4] = path + 'gallery.png'
		images[5] = path + 'referrals.png'
		images[6] = path + 'sc_buzz.png'
		images[7] = path + 'policies.png'
		images[8] = path + 'cosabella_connection.png'

		for(i=0; i<=images.length; i++) 
			imageObj.src=images[i]
		
		
	
		$jq( '#meet_our_team img.thumbnail' ).click( click_thumbnail )
		
		if( window.location.hash != '' )
			$jq( 'img.thumbnail[alt=' + window.location.hash.replace( '#', '' ) + ']' ).click()
			
		$jq( 'img#next_stylist' ).click( next_stylist )
		$jq( 'img#previous_stylist' ).click( previous_stylist )
		
		// get rid of gmap stuff)
			
	} // function
) // ready
