/*
 * Global Vars
 */
 
	var menuSpeed = 400;
	var menuIsOpen = false;
	var mobileHasRun = false;
	var isScrolling;
	var searchToggled = false;

/*
 * End Global Vars
 */


function showMenu()
{
	menuIsOpen = true;
	
	$('#mainNav')
		.css({
			top: $(window).height() * 2,
			background:"#FFF"
		})
		.show()
		.animate({
			top:$('#mobile-menu-button').height()
		}, menuSpeed, function(){
			$('#content').hide();
		});
	//$('#mobile-menu-button span.menu').text('Hide');
}

function hideMenu()
{
	menuIsOpen = false;
	$('#mainNav')
		.animate({
			top: $(window).height() * 2
		}, menuSpeed, function(){
			$(this).hide();
		});
	$('#content').show();
	//$('#mobile-menu-button span.menu').text('Menu');
}

function locations()
{
		
		if( $('body#locations').length )
		{
			$('.officeItem').each(function(){
				var photo = $('.officePhoto', this);
				$('.officename', this).after( photo );
			});
			$('.officename').live('click', function(){
				if( $(this).attr('rel') == 'open' )
				{
					$(this).parent().parent().find('*').not('.officename, .officename a, .officeDetails').slideUp();
					$(this).attr('rel', 'closed');
				}
				else
				{
					$(this).parent().parent().find('*').slideDown();
					$(this).attr('rel', 'open');
				}
			});
		}
}

function locationsItem()
{
	if( $('body.locations-item').length )
	{
		$('#expandingSidebar').children().not('h3').hide();
		$('h1').after( "<div id='subLinks'><h3 id='Overview' class='active'>Overview</h3></div>" );
		$('#expandingSidebar h3').each(function(){
			$this = $(this);
			$this
				.attr('id', $this.text().replace(" ","") )
				.nextAll()
				.each(function(){ 
					if( $(this).is('h3') )
					{
						return false;
					}
					else
					{
						$(this).addClass($this.text().replace(" ","") + "-item reveal-item");
					}
				});
			$('#subLinks').append( $(this) );
		});
		
		if( $('.sp_map').length )
		{
			$('#subLinks').append( "<h3 id='map'>Map</h3>" );
			
			var mapURL = "";
			$('.mapPart').each(function(){
				mapURL += " " + $(this).text();
			});
			
			mapURL = "http://maps.google.com/maps?q=" + $.trim(mapURL).replace(/ /g, "%20");
			
			$('.directions').prepend("<a href='" + mapURL + "' class='mobileMapLink'>View Google Map</a>");
			
		}
		
		$('#subLinks h3').live('click', function(){
			$('.active').removeClass('active');
			$(this).addClass('active');
			
			if( $(this).attr('id') != 'Overview' && $(this).attr('id') != 'map' )
			{
				$('#subLinks').nextAll().hide();
				var items = "." + $(this).attr('id') + "-item";
				$('.reveal-item').hide();
				$(items).show();
			}
			else if( $(this).attr('id') == 'Overview' )
			{
				$('#subLinks').nextAll().each(function(){
					if( $(this).is('.mcontent, .mobileOffice') )
					{
						$(this).show();
					}
					else
					{
						$(this).hide();
					}
				});
				$('.reveal-item').hide();
			}
			else if( $(this).attr('id') == 'map' )
			{
				$('#subLinks').nextAll().hide();
				$('.reveal-item').hide();
				$('.directions').show();
			}
		});
	}
}

function peopleItem()
{
	
	if( $('body.people-item').length )
	{
		
		//$('.mobileOffice').after( $('#expandingSidebar') );
		$('#expandingSidebar').children().not('h3').hide();
		$('.mobileOffice').after( "<div id='subLinks'><h3 id='Overview' class='active'>Overview</h3></div>" );
		$('#expandingSidebar h3').each(function(){
			$this = $(this);
			$this
				.attr('id', $this.text().replace(" ","") )
				.nextAll()
				.each(function(){ 
					if( $(this).is('h3') )
					{
						return false;
					}
					else
					{
						$(this).addClass($this.text().replace(" ","") + "-item reveal-item");
					}
				});
			$('#subLinks').append( $(this) );
		});
		
		$('#subLinks h3').live('click', function(){
			$('.active').removeClass('active');
			$(this).addClass('active');
			
			if( $(this).attr('id') != 'Overview' )
			{
				$('#subLinks').nextAll().hide();
				var items = "." + $(this).attr('id') + "-item";
				$('.reveal-item').hide();
				$(items).show();
			}
			else
			{
				$('#subLinks').nextAll().show();
			}
		});
	}
}

function people()
{
	if( $('body#people').length )
	{
		$('body').prepend('<div id="debug"></div>');
		$('.attySearchButton').attr('value','Search');
		$('#attySearch p:last').after( $('.submitButton').show() );
		$('#bioLetters').append('<span></span><span></span>');
	}
}

function practicesItem()
{
	if( $('body.practices-item').length || $('body.industries-item').length )
	{
		$('h1:first').after( $('#sideNav') );
	}
		
}

function careers()
{
	if( $('body.careers').length )
	{
		if( $('#sectionTitle').length )
		{
			$('#sectionTitle').text('Careers');
		}
	}
}

function about()
{
	if( $('body.about').length )
	{
		$('.about .rankings-side, .about .straighttalk-side, .about .technology-side, .about .green-side').remove();
	}
}

function mobile( mobileParams )
{
	if( mobileParams )
	{
	
		$('#mobile-menu-button div.menu').click(function(){
			if( !menuIsOpen )
			{
				showMenu();
			}
			else
			{
				hideMenu();
			}
		});
		
		locations();
		locationsItem();
		peopleItem();
		people();
		practicesItem();
		careers();
		about();
		
		
	}
	
}

