$(function() {
	
	
	
	
	//HOMEPAGE NAVIGATION/////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////
	
	function homepageNavInit(){
		
		//hide all li's and nav images but the first on page load
		$('#homeNav ul li').eq(0).nextAll('li').hide();
		$('.imap').eq(0).nextAll('img').hide();
		
		//onhover change images
		$('#homeNav_imageMap area').hover(function(e){
			
			
			//hide all images and text
			$('.imap').hide();
			$('#homeNav li').hide();
			
			//find which image based on href attr and change image displayed
			if($(this).attr('href') == '/'){
				$('#iMap_homeHover').show();
				$('#homeNav li').eq(0).show();
			}else if($(this).attr('href') == '/solutions_for_business_owners'){
				$('#iMap_sfbo').show();
				$('#homeNav li').eq(1).show();
			}else if($(this).attr('href') == '/about_us'){
				$('#iMap_about').show();
				$('#homeNav li').eq(7).show();
			}else if($(this).attr('href') == '/clients_partners'){
				$('#iMap_clients').show();
				$('#homeNav li').eq(8).show();
			}else if($(this).attr('href') == '/corporate_opportunities'){
				$('#iMap_corporate').show();
				$('#homeNav li').eq(2).show();
			}else if($(this).attr('href') == '/project_finance'){
				$('#iMap_finance').show();
				$('#homeNav li').eq(6).show();
			}else if($(this).attr('href') == '/public_sector_initiatives'){
				$('#iMap_public').show();
				$('#homeNav li').eq(4).show();
			}else if($(this).attr('href') == '/the_nonprofit_challenge'){
				$('#iMap_nonprof').show();
				$('#homeNav li').eq(3).show();
			}else if($(this).attr('href') == '/opportunities_for_investors'){
				$('#iMap_investors').show();
				$('#homeNav li').eq(5).show();
			}
			
			e.stopPropagation();
			e.preventDefault();
			
		}, function(e){
			//show original image & text
			$('.imap').hide();
			$('#iMap_home').show();
			$('#homeNav li').hide();
			$('#homeNav li').eq(0).show();
			
			e.stopPropagation();
			e.preventDefault();
			
		})
		
	}
	


	
	
	 //GLOBAL NAVIGATION//////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////
	
	function globalNavInit(){
		
		$('.navNormal').hover(function(){
			
			//hide pre rollover nav and show rolled over nav
			$('.navNormal').hide();
			$('#globalNavRolledOver').show();
			
			//keep display shown if rolled over
			$('#globalNavRolledOver').hover(function(){
				$(this).show();
			}, function(){
				$(this).hide();
				$('.navNormal').show();
			})
		
		})
	}
	
	
	
	
	
	 //TEAM///////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////
	
	function teamInit(){
		
		//initaite carousel
		$("#teamContainer").jSlide({             
			width: 882,
			height: 128,
			previous: "#teamPrev",
			next: "#teamNext",
			loop: false,
			speed: 800,
			amount: 9,
			direction: 'horizontal'
		});
		
		// look for hash and display correct team member onload
		// if there is an ID passed as a segment on load, that overrides the hash
		if(window.location.hash || theLoadID>0){

			var hash = window.location.hash;
			hash = hash.substr(4);
			
			if(theLoadID>0) hash = theLoadID;
			
			// hide and show bio in main content well
			// make sure new bio div exists first
			if($('.bio'+hash).hasClass('bioDesc')) {
				$('.bioMain, .bioDesc').hide();
				$('.bio'+hash).fadeIn(800);
			}
			
			//bold name on the left
			$('#bioindex tbody tr td a').each(function(){
				$(this).css({color: '#777'});
				if($(this).attr('bioid') == hash){
					$(this).css({color: '#000'})
				}
			})
			
		}
		
		
		
		//li hover animation and name display for standard bios
		$('#teamContainer #teamCarousel li').hover(function(){
			$(this).children('.blueBarTop, .blueBarBottom').fadeIn(400);
			$('#hoverNames').html('<h4>'+$(this).attr('names')+'</h4><h5>'+$(this).attr('jTitle')+'</h5>')
		},function(){
			$(this).children('.blueBarTop, .blueBarBottom').fadeOut(400);
			$('#hoverNames').html('');
		});
			
		
		//li click display correct bio
		$('#teamContainer #teamCarousel li').click(function(e){
			
			//vars
			var bioID = $(this).attr('bioid');
			
			//hide and show bio in main content well
			$('.bioMain, .bioDesc').hide();
			$('.bio'+ bioID).fadeIn(800);
			
			
			//bold name on the left
			$('#bioindex tbody tr td a').each(function(){
				$(this).css({color: '#777'});
				if($(this).attr('bioid') == bioID){
					$(this).css({color: '#000'})
				}
			})
			
			window.location.hash = "bio"+bioID;	
						
			e.preventDefault();
		})
		
		
		$('#bioindex tr td a').click(function(e){
			//vars
			$('#bioindex tr td a').css({color: '#777'});
			$(this).css({color: '#000'});
			
			var bioID = $(this).attr('bioid');
			$('.bioMain, .bioDesc').hide();
			$('.bio'+ bioID).fadeIn(800);
			
			window.location.hash = "bio"+bioID;			
			
			e.preventDefault();
		})
		
		
		
	}
	
	
	
	
	
	 //PORTFOLIO-CASE STUDIES/////////////////////////////////////////
	/////////////////////////////////////////////////////////////////
	
	function portfolioInit(){
		
		
		//initaite carousel
		$("#portfolioContainer").jSlide({             
			width: 920,
			height: 141,
			previous: "#portfolioPrev",
			next: "#portfolioNext",
			loop: false,
			speed: 800,
			amount: 2,
			direction: 'horizontal'
		});
		

		//portfolio modal panel show
		$('a.portfolioModal').click(function(e){
			$('#portfolioModal').fadeIn(700);
			$('#overlay').css({opacity: 0}).show().animate({opacity: .7}, 700);
			e.preventDefault();
		})
		
		//case studies modal panel show
		$('a.projectFinanceCaseStudies').click(function(e){
			$('#projectFinanceCaseStudies').fadeIn(700);
			$('#overlay').css({opacity: 0}).show().animate({opacity: .7}, 700);
			e.preventDefault();
		})
		
		//close overlay, portfoliomodal, projectfinancecasestudies
		$('#overlay, #xOut').click(function(e){
			$('#overlay, #portfolioModal, #projectFinanceCaseStudies').fadeOut(700,function(){
				$('#portfolioModal .pItems').children('li').hide();
				$('#portfolioModal #backToIndex, #portfolioModal #nextProject, #sliderNavigation').fadeOut(500);
				$('#portfolioModal .pItems').children('li').eq(0).fadeIn(500);
				portfolioItem = 0;
				$('.imageRotator').each(function(){
					$(this).cycle(0);
				});
			});
			e.preventDefault();
		})
		
		
		//li display info about portfolio piece on hover
		$('#portfolioContainer #portfolioCarousel li div.portfolioBanner ').hover(function(){
			$(this).children('.portfolioInfo').fadeTo(500, 0.9);
		},function(){
			$(this).children('.portfolioInfo').fadeTo(500, 0);
		})
		
		
		//portfolio interactivity / functionaility
		var portfolioItem = 0;
		var totalItems = ($('#portfolioModal .pItems').children('li').length)-1;
		
		
		$('#portfolioModal .pItems li').eq(0).nextAll('li').hide();
		
			
		$('#portfolioContainer #portfolioCarousel li .portfolioBanner').click(function(e){
			
			//vars
			portfolioItem = $(this).parents('li').attr('lang');
			
			$('#portfolioModal .pItems').children('li').hide();
			$('#portfolioModal #backToIndex, #portfolioModal #nextProject, #sliderNavigation').fadeIn(500);
			$('#portfolioModal .pItems').children('li').eq(portfolioItem).fadeIn(500);
			
			e.preventDefault();
			
		});
		
		//back to index
		$('#portfolioModal #backToIndex').click(function(e){
			$('#portfolioModal .pItems').children('li').hide();
			$('#portfolioModal #backToIndex, #portfolioModal #nextProject, #sliderNavigation').fadeOut(500);
			$('#portfolioModal .pItems').children('li').eq(0).fadeIn(500);
			portfolioItem = 0;
			e.preventDefault();
		})
		
		//next project
		$('#portfolioModal #nextProject').click(function(e){
			if(totalItems == parseInt(portfolioItem)){
				$('#portfolioModal .pItems').children('li').hide();
				$('#portfolioModal .pItems').children('li').eq(1).fadeIn(500);
				portfolioItem = 1;
			}else{
				portfolioItem = parseInt(portfolioItem)+1;
				$('#portfolioModal .pItems').children('li').hide();
				$('#portfolioModal .pItems').children('li').eq(portfolioItem).fadeIn(500);
			}
			e.preventDefault();
		})
		
	}
	
	
	
	
	
	
	//COMPONENTS//////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////
	
	//about quadrants
	function aboutQuadrants(){
		
		//onhover change images
		$('#quadrant_map area').hover(function(){
			//find which image based on href attr and change image displayed
			if($(this).attr('lang') == 'capital'){
				$('#aboutQuadrant img.main').hide();
				$('#aboutQuadrant img.capital').show();
			}else if($(this).attr('lang') == 'strategy'){
				$('#aboutQuadrant img.main').hide();
				$('#aboutQuadrant img.strategy').show();
			}else if($(this).attr('lang') == 'agency'){
				$('#aboutQuadrant img.main').hide();
				$('#aboutQuadrant img.agency').show();
			}else if($(this).attr('lang') == 'talent'){
				$('#aboutQuadrant img.main').hide();
				$('#aboutQuadrant img.talent').show();
			}
			
		})
		
		$('#quadrant_open_map area').hover(function(){
			//find which image based on href attr and change image displayed
			if($(this).attr('lang') == 'capital'){
				$('#aboutQuadrant img').hide();
				$('#aboutQuadrant img.capital').show();
			}else if($(this).attr('lang') == 'strategy'){
				$('#aboutQuadrant img').hide();
				$('#aboutQuadrant img.strategy').show();
			}else if($(this).attr('lang') == 'agency'){
				$('#aboutQuadrant img').hide();
				$('#aboutQuadrant img.agency').show();
			}else if($(this).attr('lang') == 'talent'){
				$('#aboutQuadrant img').hide();
				$('#aboutQuadrant img.talent').show();
			}
			
		}, function(){
			//alert('off');
			$('#aboutQuadrant img').hide();
			$('#aboutQuadrant #quadrant_map').show();
		})
			
	}
	
	//client panels
	function clientPanels(){
		
		//hide second panel
		$('#nextStreetIndustrySectTwo').hide();
		
		$('#nextStreetIndustrySectNav li a.one').click(function(e){
			$('#nextStreetIndustrySectNav li').eq(1).removeClass('here');
			$(this).parents('li').addClass('here');
			$('#nextStreetIndustrySectTwo').hide();
			$('#nextStreetIndustrySect').show();
			$('#nShow').hide();
			$('#bShow').fadeIn(500);
			e.preventDefault();
		})
		
		$('#nextStreetIndustrySectNav li a.two').click(function(e){
			$('#nextStreetIndustrySectNav li').eq(0).removeClass('here');
			$(this).parents('li').addClass('here');
			$('#nextStreetIndustrySect').hide();
			$('#nextStreetIndustrySectTwo').show();
			$('#bShow').hide();
			$('#nShow').fadeIn(500);
			e.preventDefault();
		})
		
	}
	
	//expandable 
	function expandable(){
		
		//check components and hide all text if hideAll is selected or hide everything after the first pargraph if not
		$('.expandable').each(function(){
			if($(this).attr('lang') == 'hideAll'){
				$(this).find('h4').nextAll('p').hide();
				$(this).find('a').live('click', function(e){
					if($(this).text() == 'SHOW MORE '){
						$(this).html('SHOW LESS <img src="/images/lessBtn.jpg" alt="" />');
					}else if($(this).text() == 'SHOW LESS '){
						$(this).html('SHOW MORE <img src="/images/moreBtn.jpg" alt="" />');
					};
					e.preventDefault();
					$(this).parents('.expandable').find('h4').nextAll('p').slideToggle();
				});
			}else if($(this).attr('lang') == 'showAll'){
				$(this).find('.expandableShow').hide();
			}else if($(this).attr('lang') != 'hideAll' || $(this).attr('lang') != 'showAll'){
				$(this).find('p').eq(0).nextAll('p').hide();
				$(this).find('a').live('click', function(e){
					if($(this).text() == 'SHOW MORE '){
						$(this).html('SHOW LESS <img src="/images/lessBtn.jpg" alt="" />');
					}else if($(this).text() == 'SHOW LESS '){
						$(this).html('SHOW MORE <img src="/images/moreBtn.jpg" alt="" />');
					};
					e.preventDefault();
					$(this).parents('.expandable').find('p').eq(0).nextAll('p').slideToggle();
				});
			}
		}) 
		
	}
	
	
	//expandable 
	function expandablePersp(){
		
	  $(".expandablePerspCont").each(function(){
		 
		  $(this).hide();
		  //toggle the componenet with class msg_body
		  $("a.expandableShow").click(function(e){
			$('.expandablePerspCont').slideToggle(600);
			
			if($(this).text() == 'SHOW COMPLETE TEXT '){
				$(this).html('SHOW LESS <img src="/images/lessBtn.jpg" alt="" />');
			}else if($(this).text() == 'SHOW LESS '){
				$(this).html('SHOW COMPLETE TEXT <img src="/images/moreBtn.jpg" alt="" />');
			};
			
			e.preventDefault();
		  });
	  
	  })
	
	}
	
	//chart slider
	function chartSlider(){
		
		$("#chartContainer").jSlide({             
			width: 609,
			height: 250,
			previous: "#chartPrev",
			next: "#chartNext",
			loop: false,
			speed: 800,
			direction: 'horizontal'
		});
		
		//set corret container width
		this.oldWidth = $('#chartCarousel').width();
		this.amount = parseInt($('#chartCarousel').children().length) * 150;
		$('#chartCarousel').width(this.oldWidth + this.amount);
	}
	
	//external link function 
	if (document.getElementsByTagName) {
		var anchors = document.getElementsByTagName("a");
		for (var i=0; i<anchors.length; i++) {
			var anchor = anchors[i];
			anchor.hideFocus = true;
			if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "external" || anchor.getAttribute("rel") == "alternate" || anchor.getAttribute("href").toLowerCase().indexOf(".pdf") > 4)){
				anchor.target = "_blank";
			}
		}
	}
	
	
	
	
	
	
	
	 //CONTACT////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////
	
	function contactInit(){
		
		
		//swap maps and sidebar content
		$('#contactNavBoston').click(function(e){
			$('#contactNavNY').removeClass('here');
			$('#contactNavBoston').addClass('here');
			if($.browser.msie){
				$('.ny').hide();
				$('.boston').show();
			}else{
				$('.ny').fadeOut(500, function(){$('.boston').fadeIn(500)})
			}
			e.preventDefault();
		})
		
		$('#contactNavNY').click(function(e){
			$('#contactNavBoston').removeClass('here');
			$('#contactNavNY').addClass('here');
			if($.browser.msie){
				$('.boston').hide();
				$('.ny').show();
			}else{
				$('.boston').fadeOut(500, function(){$('.ny').fadeIn(500)});
			}
			e.preventDefault();
		})
		
		//directions hover
		$('#drivingDirections a').hover(function(){
			$(this).find('.hiddenInstructions').fadeIn(200);
		},function(){
			$(this).find('.hiddenInstructions').fadeOut(200);
		})
		
		//contact modal panel
		$('a.contactModal').click(function(e){
			$('#contactModal').fadeIn(700);
			$('#overlay').css({opacity: 0}).show().animate({opacity: .7}, 700);
			e.preventDefault();
		})
		
		$('#overlay,  #xOut').click(function(e){
			$('#overlay, #contactModal').fadeOut(700);
			e.preventDefault();
		})
		
		
		//AJAX assistance form 
		$('#contact').ajaxForm({   
		  beforeSubmit:function() {
	  
			  //validation tests
			  if($('#fName').val() == "" || $('#fName').val() == "First Name*"){
				  $('#fNameError').fadeIn(300);
				  return false;
			  }
			  if($('#lName').val() == "" || $('#lName').val() == "Last Name*"){
				  $('#lNameError').fadeIn(300);
				  return false;
			  }
			  if($('#email').val() == "" || $('#email').val() == "Email*"){
				  $('#emailError').fadeIn(300);
				  return false;
			  }
			  if($('#message').val() == "" || $('#message').val() == "Message*"){
				  $('#messageError').fadeIn(300);
				  return false;
			  }
			  
		  },
		  success:function(response) {
			if (response=="success") {
			  $("#contact").resetForm();
			  $('#contactMSG').html('Your message has been successfully sent.');
			  
			}else{
			  $('#contactMSG').html('There was an error, please try again.');
			}
		  }
		});
		
	}
	
	//error check for mail directions
	$('#submitDirections, #submitDirectionsTwo').click(function(){
		
		if($(this).parents('dl').children('dd').children('#directionsEmailAddress').val() == "" || $(this).parents('dl').children('dd').children('#directionsEmailAddress').val() == "Email*"){
			$(this).parents('dl').children('dd').children('#emailDirectionsError').fadeIn(300);
			return false;
		}

	});
	
	
	
	
	
	
	
	//OPPORTUNITY FUND////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////
	
	function opportunityFund(){
		
		//navigtion roll overs
		$('#oppLocalNav li #glance, #oppLocalNav li #owners, #oppLocalNav li #sheet').hover(function(){
			$(this).nextAll('p').show();
		}, function(){
			$(this).nextAll('p').hide();
		})
		
		//text roll over
		$('#oppOpenTooltip').hover(function(){
			$('#oppTooltip').show();
		}, function(){
			$('#oppTooltip').hide();
		})
		
		//modal
		$('#oppStart').click(function(e){
			$('#oppModal').fadeIn(700);
			$('#overlay').css({opacity: 0}).show().animate({opacity: .7}, 700);
			e.preventDefault();
		})
		
		$('#overlay,  #xOut').click(function(e){
			$('#overlay, #oppModal').fadeOut(700);
			e.preventDefault();
		})
		
		//AJAX opportunityFundForm 
		$('#opportunityFundForm').ajaxForm({   
		  beforeSubmit:function() {
	  
			  //validation tests
			  if($('#name').val() == "" || $('#company').val() == "" || $('#email').val() == "" || $('#phone1').val() == "" || $('#street1').val() == "" || $('#city').val() == "" ||  $('#state').val() == "select a state" || $('#zipcode').val() == "" || $('#message').val() == "" || $('#needs').val() == ""){
				  $('#oppMSG').html('Please fill in all required fields denoted by *.');
				  return false;
			  }
			  
		  },
		  success:function(response) {
			if (response=="success") {
			  $("#opportunityFundForm").resetForm();
			  $('#oppMSG').html('Your message has been successfully sent.');
			}else{
			  $('#oppMSG').html('There was an error, please try again.');
			}
		  }
		});
		
		
	}
	
	
	
	
	
	
	
	//FIXES///////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////
	
	if ($.browser.mozilla) {
		//move twitter bird over
    	$('#secondFooter #secondFooterWrapper h4 > img').css({left: '170px'});
 	}
	
	// of pc and mozilla
	if (navigator.appVersion.indexOf("Win")!=-1){
		if ($.browser.mozilla || $.browser.msie) {
			$('h1').css({'font-family': 'arial', 'font-weight': 'bold'});
			$('#nav_sub li a').css({'font-family': 'arial'});
			$('#nav_sub li.here a').css({'font-weight': 'bold'});
 		}
	}
	
	if($.browser.msie && $.browser.version=="7.0"){
		$('#portfolioModal .sliderNavigation').css({'padding-top': '20px'});
		$('#oppSecondFooter #oppContainer #oppContainerLeft p').width('400px');
	}
	
    //Video Overlay
	$("a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'slow',theme:'light_square'});
	
	
	
	
	
	
	//EXECUTABLES
	homepageNavInit();
	globalNavInit();
	aboutQuadrants();
	clientPanels();
	expandable();
	expandablePersp();
	teamInit();
	portfolioInit();
	contactInit();
	var eachNav = 0;
	$('.imageRotator').each(function(){
		var $nav = $('<div class="sliderNavigation nav'+eachNav+'"></div>').insertAfter(this);
		$(this).cycle({ speed: 200, timeout: 0, pager: '.nav'+eachNav+''});
		eachNav++;    
	});
	$('.logoImages').cycle({ fx: 'fade', timeout: 6000});
	chartSlider();
	opportunityFund();
	
	
}); //END OF DOM READY
