
var nous = {

	currSil: 0,
	
    init:function() { 
	
		// Misc ----------------------------- 
        
        $('.categories .category:nth-child(2n+2)').css({'margin-right': '0'}).after('<div class="clearfix"></div>');
        $('.news-events-list .news-event:nth-child(2n+2)').css({'margin-right': '0'}).after('<div class="clearfix"></div>');
        $('.publications-list .publication:nth-child(2n+2)').css({'margin-right': '0'}).after('<div class="clearfix"></div>');
    
        $('#codeigniter_profiler').hide();
        $('#codeigniter_profiler').next('div').hide();
		
		// Add odd class to odd list
		$('#sector-list li:nth-child(2n), #news-events ul li:nth-child(2n), #service-lines-list li:nth-child(2n), #work-list li:nth-child(2n), #news-list li:nth-child(2n), #news .content-list>li:nth-child(2n)').addClass('odd');
                        
        // Match the heights of the footer nav column	
		if(document.documentElement.clientWidth > 320) {
			$('footer nav').matchHeights();
		}
		
		// Change the arrows on read more links that should expand/contract
		$('.sector-summary-more .read-more, .profile-more, .work-more a, .read-more-careers a, . recent-people .read-more').addClass('expand');
		
		// Change the properties of .hide so the matching heights plugin can get the heights of hidden elements
		$('.experience .hide').css({'position':'static'});
		
		// Match work heights on people profile page
		$('.experience div.work').matchHeights();
		
		
		
        // Header nav dropdowns
        
		var navHover = {
			over: navOver,
			timeout: 0, 
			out: navOut
		};		
		function navOver() {
			var $this = $(this),              
            navoffset = $('header nav').offset();
            
            $this.next('li').addClass('next');
            $this.prev('li').addClass('prev');
            $this.children('a').append('<span class="shadow-l"></span><span class="shadow-r"></span><span class="dropdown-overlay"></span>');
            $('.dropdown-overlay').width($this.outerWidth());                         
           $(this).addClass('hover').children('.content-dropdown').stop(true, true).show();
		}
		function navOut() {
			var $this = $(this);            
            $this.next('li').removeClass('next');
            $this.prev('li').removeClass('prev');
            $this.children('a').children('span').remove();
            $('.shadow-top').remove();       
            $this.children('.content-dropdown').stop(true, true).hide(); 
			$('header nav *').removeClass('hover');
		}
        $('header>nav>ul>li').hoverIntent(navHover);
        
        // Left column expand/close menus
        $('#left-col h3 a.right').click(function() {
            $this = $(this);
            if($this.parents('h3').next('.top-level').is(':hidden')) {
                $this.parents('h3').next('.top-level').slideDown();
                $this.addClass('close').text('Close').attr('title', 'Close');
                $this.attr('title', 'Close');
            } else {
                $this.parents('h3').next('.top-level').slideUp();
                $this.removeClass('close').text('Expand').attr('title', 'Expand');
                $this.attr('title', 'Expand');
            }
            return false;
        });                
        $('#sectors #industries-left-menu h3 .right').addClass('close').attr('title', 'Close');
        $('#service-lines #service-lines-left-menu h3 .right').addClass('close').attr('title', 'Close');
        $('#people #people-left-menu h3 .right').addClass('close').attr('title', 'Close');
        
		
		// People -----------------------------    

		// --- Person view --- 
		
		$('.profile-more').click(function() {
			$(this).parent('p').next('.hide').slideDown();
			if($(this).text() == "Read more") {
				$(this).parent('p').next('.hide').slideDown(function() {
					$('.profile-more').removeClass('expand').addClass('contract').text('Hide');
				});
			} else {
				$(this).parent('p').next('.hide').slideUp('medium', function() {
					$('.profile-more').removeClass('contract').addClass('expand').text('Read more');
				});
			}			
		});
		
		// Recent project members
		$('.recent-people .more-people').click(function() {								
			$('.recent-people .people-list .hide').slideDown();			
			if($(this).text() == "View more team members") {
				$('.recent-people .people-list .hide').slideDown(function() {
					$('.recent-people .more-people').text('View less team members');
				});
			} else {
				$('.recent-people .people-list .hide').slideUp('medium', function() {
					$('.recent-people .more-people').text('View more team members');
				});
			}
		});
		
		
		$('.person-details .work-more a').click(function() {
			if($(this).text() == "View more") {
				$('.experience .hide').slideDown('medium', function() {
					$('.work-more a').removeClass('expand').addClass('contract').text('Hide');
				});
			} else {
				$('.experience .hide').slideUp('medium', function() {
					$('.work-more a').removeClass('contract').addClass('expand').text('View more');
				});
			}								
		});
		
		// --- People search and list --- 
		
		// Make the people list be equal heights
        $('.person').matchHeights({minHeight:200});    
        
        // Stop the search form from submitting
        $('#search-person').bind('submit', function() {
            return false;
        });
        
        // People thumb image positioning
       $('.person-tooltip').live('mouseenter', function() {			
            $(this).children('.tooltip').stop(true, true).fadeIn(700);
       });
	   $('.person-tooltip').live('mouseleave', function() {
			$(this).children('.tooltip').stop(true, true).fadeOut(600);
	   });   

        
        // Home ----------------------------- 
		
        // Home rotator 
        
        var silOps = {
			home: {
				'top':-0,
				'left':-1355
			},
            businessStrategy: {
                'top':-812,
                'left':-1236
            },
            imt: {
                'top':-433,
                'left':-131
            },
            leadership: {
                'top':0,
                'left':0
            },
            organisationalCapabilty: {
                'top':-403,
                'left':-1629
            },
            publicPolicy: {
                'top':-497,
                'left':-804
            },
            award: {
            	'top':-250,
            	'left':-205
            }
        }   	
		$('.silhouette .map').css({ 'top':silOps.home.top, 'left':silOps.home.left });
		
        
        if($('.rotator').length) {
            $('.rotator').after('<div class="nav">').cycle({ fx:'scrollHorz', timeout:0, pager:'.nav', easeIn:'jswing', easeOut:'jswing', prev:'.prev', next:'.next', before:function(currSlideElement, nextSlideElement) {
					mask();
                }, onPagerEvent:function(zeroBasedSlideIndex) {
					nous.currSil = zeroBasedSlideIndex;	
				}, onPrevNextEvent:function(isNext, zeroBasedSlideIndex, slideElement) {
					nous.currSil = zeroBasedSlideIndex;	
				}
            });
        }
		
		function mask() {
			 // Move the silhouette image
			switch (nous.currSil) {
				case 0:
					$('.silhouette .map').animate({ 'top':silOps.home.top, 'left':silOps.home.left }, 1000, 'easeOutSine');                            
					break;
				case 1:
					$('.silhouette .map').animate({ 'top':silOps.award.top, 'left':silOps.award.left }, 1000, 'easeOutSine');
					break;       				
				case 2:
					 $('.silhouette .map').animate({ 'top':silOps.leadership.top, 'left':silOps.leadership.left }, 1000, 'easeOutSine');                            
					break;
				case 3:
					$('.silhouette .map').animate({ 'top':silOps.organisationalCapabilty.top, 'left':silOps.organisationalCapabilty.left }, 1000, 'easeOutSine');
					break;                            
				case 4:
					$('.silhouette .map').animate({ 'top':silOps.businessStrategy.top, 'left':silOps.businessStrategy.left }, 1000, 'easeOutSine');
					break;
				case 5:
					$('.silhouette .map').animate({ 'top':silOps.imt.top, 'left':silOps.imt.left }, 1000, 'easeOutSine');                            
					break;
				case 6:
					$('.silhouette .map').animate({ 'top':silOps.publicPolicy.top, 'left':silOps.publicPolicy.left }, 1000, 'easeOutSine');
					break;  
				                     
			}   
			// Increase the current slide count
			if (nous.currSil === ($('.rotator>div').length - 1)) {
				nous.currSil = 0;
			} else {
				nous.currSil++;
			}
		}
        
		
       
       // Careers ----------------------------- 
       
       $('.show-current-opportunities a').addClass('expand').click(function() {
			var $this = $(this);
			if($this.hasClass('expand')) {
				$this.parent('p').next('.hide').slideDown();
				$this.removeClass('expand').addClass('contract').text('Hide current opportunities');
			} else {
				$this.parent('p').next('.hide').slideUp();
				$this.removeClass('contract').addClass('expand').text('Show current opportunities');
			}
		});
	   
	   // Show careers more details	   
	   $('.read-more-careers .read-more').click(function() {
			$(this).parent('p').next('.hide').slideDown();
			if($(this).text() == "Read more") {
				$(this).parent('p').next('.hide').slideDown(function() {
					$('.read-more-careers .read-more').removeClass('expand').addClass('contract').text('Hide');
				});
			} else {
				$(this).parent('p').next('.hide').slideUp('medium', function() {
					$('.read-more-careers .read-more').removeClass('contract').addClass('expand').text('Read more');
				});
			}			
		});		
	   
	   
	   // Sectors ----------------------------- 
	   
	   // Show/hide the extra work items on sectors
	   $('.case-studies-list .work:odd').addClass('odd');
	   $('.case-studies-list .read-more').click(function() {
			if($(this).text() == "View more work") {
				$('.case-studies-list .hide').slideDown('medium', function() {
					$('.work-more a').removeClass('expand').addClass('contract').text('View less work');
				});
			} else {
				$('.case-studies-list .hide').slideUp('medium', function() {
					$('.work-more a').removeClass('contract').addClass('expand').text('View more work');
				});
			}								
		});
		
	   
	   // Expand/contract the key people if more than 4
	   if($('.sectors-key-people .more-people').length) {
		   var origPepHeight = $('.people-list').outerHeight();
		   $('.more-people').click(function() {
				if($(this).hasClass('expanded')) {
					$('.people-list').animate({'height':$('.key-people .person').outerHeight()}, 1000);
					$(this).removeClass('expanded').text('View more key people');
				} else {
					$('.people-list').animate({'height':origPepHeight}, 1000);
					$(this).addClass('expanded').text('View less key people');
				}
				return false;			
		   });
		   keyPeopleHeight();	 
		}		   
		function keyPeopleHeight () {
			$('.people-list').height($('.key-people .person').outerHeight());
		}

		// News/events to be equal height
		$('.news-event-list .news-event').matchHeights();		
		
		// Sector content more info
		$('.sector-summary-more .read-more').click(function() {
			if($(this).text() == "Read more") {
				$('.sector-more').slideDown();
				$('.sector-summary-more .read-more').removeClass('expand').addClass('contract').text('Hide');
			} else {
				$('.sector-more').slideUp();
				$('.sector-summary-more .read-more').removeClass('contract').addClass('expand').text('Read more');
			}
		});
	   

	   
       // Sitemap ----------------------------- 

       // Make the people list be equal heights
       $('.sitemap-people ul').matchHeights();
	   
	   
	   
		 // Service lines ----------------------------- 
		$('#service-lines-list>li').matchHeights();      
		
		// Change the properties of .hide so the matching heights plugin can get the heights of hidden elements
		$('.experience .hide').hide();
		
    }    
 }
 $(function() {
	nous.init();
});
