var pembroke = {
// -------
	init: function() {
		this.prepareDocument();
		this.logoAnimation();
		this.clientsPagination();
		$('img[title], img[alt]').removeAttr('title').removeAttr('alt');		
	},
// -------
	enhanceFonts: function() {
		Cufon.set('fontFamily', 'DIN')
			.replace('aside h1, aside h2, aside h3, aside h4, .has-grid h2')
			.replace('#nav a', { 
					hover: true, 
					hoverables: { li:true } 
			});		
	},
// -------		
	logoAnimation: function() {	
		$('#banner > div').hover(function() {
			$('a', '#banner').stop(true, true).animate({ width: 'hide' }, 300, function() {
				$('.hidden', '#banner').animate({ width: 'show' }, 500)
			})
		}, function() {
			$('.hidden', '#banner').stop(true, true).animate({ width: 'hide' }, 300, function() {
				$('a', '#banner').animate({ width: 'show' }, 500)
			})
		});		
	},
// -------	
	prepareDocument: function() {	

		$('h3 a', 'aside').click(function(e) { 
			var _target = $(this).parent().next("article");
			if (_target.is(":visible") == false) {				
				$('article', 'aside').hide();
				_target.fadeIn(100);	
				$('img', '#content').hide();
				var _img = $('.'+ this.hash.slice(1));
				_img.length 
					? _img.fadeIn(200) 
					: $('img', '#content').eq(0).show();
			} 
			else {			    
				_target.slideUp(100);
			}
			e.preventDefault();		
		}).eq(0).trigger('click');

		$('figure', '.has-grid').hover(
			function() {
				$(this).find('figcaption').stop(true, true).animate({height:'show'}, 300);
			},
			function() {
				$(this).find('figcaption').stop(true, true).animate({height:'hide'}, 200);
			}			
		);
		
		$('a:has(img)', 'aside').click(function(e) { 
			$('aside a').removeClass('active').filter(this).addClass('active');
			$("#content").find('img').hide().end().append('<img src="'+ this.href +'" width="100%" />');	
			e.preventDefault();			
		}).eq(0).trigger('click');
		
		$('.onpage a').click(function(e) {		
			e.preventDefault();				
			var activeArticle = $('article:visible');
			if ($(this).hasClass('next')) {			
				activeArticle.parent().next().find('a').trigger('click');
			} else {
				activeArticle.parent().prev().find('a').trigger('click');
			}				
		});
		
		$('.controls a', '#content').click(function(e) {		
			e.preventDefault();				
			var activeImage = $('aside .active');
			if ($(this).hasClass('next')) {			
				activeImage.next('a').trigger('click');
			} else {
				activeImage.prev('a').trigger('click');
			}				
		});		
		
	},
// -------	
	clientsPagination: function() {
		$('#grid-pagination a').click(function(e) {
			e.preventDefault();			
			var pageNo = this.hash.slice(1);
			$('nav a').removeClass('active').filter(this).addClass('active');
			$('.page').hide().eq(pageNo).show();
		}).eq(0).trigger('click');
	}
// -------
};

$(function() {
	pembroke.init();
});
