/* Fix image baseline
-------------------------------------------------------------- */

fixImageBaselines("img");


/* Cufon
-------------------------------------------------------------- */

Cufon.replace('div#navigation ul li a.header, h2, h3', { hover: true });


/* jQuery love
-------------------------------------------------------------- */

$(document).ready(function(){

	/* Initialize Googlemaps
	-------------------------------------------------------------- */

	if ($('#map').length>0)
	{
		var map = new GMap2(document.getElementById('map'));
		var geocoder = new GClientGeocoder();
		geocoder.getLatLng("62 Shoreditch High Street<br/>London E1 6JJ<br/>United Kingdom", function(point){
	        	
	        	var marker = new GMarker(point);
	        
	        	map.setCenter(point, 16);
	        	map.addOverlay(marker);
	        	map.setUIToDefault();
	        
		});
	}
	

	/* Hover effect for project thumbs
	-------------------------------------------------------------- */

	$('div#project-thumbs div.project-thumb').hover(
	
		function(){
		
			$('div.rollover', $(this)).show();
	
		},
		
		function(){
		
			$('div.rollover', $(this)).hide();
	
		}
		
	);

	
	/* Handle discipline expansion
	-------------------------------------------------------------- */
	
	var disciplineList = $('div#disciplines ul');
	
	var moreToggle = $('div#disciplines a#show-more');
	
	var maxCat = 20;
	
	var i = 1;
	
	function hideCats()
	{
	
		i = 1;
	
		$('li', disciplineList).each(function(){
	
			if (i>maxCat)
				$(this).hide();
			
			i++;
			
		});
	
	}
	
	hideCats();
	
	if (i>maxCat)
	{
		moreToggle.show();
		
		moreToggle.click(function(){
		
			if ($(this).hasClass('more'))
			{
			
				$('li', disciplineList).each(function(){
				        $(this).css('display','list-item');
					$(this).slideDown("normal");
				        
				});
				
				$(this).html('fewer &#8593;').addClass('fewer').removeClass('more');
			
			}
			else
			{
				hideCats();
				
				$(this).html('more &#8595;').removeClass('fewer').addClass('more');
				
			}
			
			return false;
		
		});
		
		
	}
	
	/* Handle expandable H4s
	-------------------------------------------------------------- */
	
	$('h4 a').click(function(){
	
		target = $(this).attr('href');
	
		if ($(this).hasClass('selected'))
		{
	
			$(target).slideUp();
			
			$(this).removeClass('selected');
		
		} else {
		
			$(target).slideDown();
		
			$(this).addClass('selected');
		
		}
	
		return false;
	
	});
	
	
	/* Tooltips for categories
	-------------------------------------------------------------- */
	
	$('ul#categories li a').tipsy();
	
	
	/* Slideshow
	-------------------------------------------------------------- */
	
	$('div#slideshow').cycle({ 
	    prev:   'a#prev', 
	    next:   'a#next', 
	    after:   onAfter, 
	    timeout: 0 
	});
	
	function onAfter(curr, next, opts) {
	
    	var index = opts.currSlide;
    	$('a#prev')[index == 0 ? 'hide' : 'show']();
    	$('a#next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
    	
		onBefore(curr, next, opts);
	}
	
	function onBefore(curr, next, opts) {
		$('span#curr').html(opts.currSlide+1);
    	$('span#count').html(opts.slideCount);
	}


});

