if (typeof features === 'undefined') {
	features = {};
}

else {
	console.log('features is already defined');
}

features.slide = (function($) {
	function init() {
		$('.concertina-hide').hide(); 
		$('.activate-concertina').click(reveal);
	}
	
	function reveal() {
		var $this = $(this);
		$this.parent().find('dd').slideToggle(function() {
			if($(this).is(":visible")) {
 				$this.css('backgroundPosition', '460px -659px');
 			}
			
			else if($(this).is(":hidden")) {
 				$this.css('backgroundPosition', '460px -618px');
 			}
		});
	}
	
	$(document).ready(init);
})(jQuery);

features.timeline = (function($) {
	function init() {
		$('.body-text').hide();
		$('.show-timeline').click(reveal);
	}
	
	function reveal() {
		var parent = $(this).parent();
		parent.find('.body-text').slideToggle(function() {
			var text = parent.find('button');
			var test = text.text() === 'Show';
			test ? text.text('Hide') : text.text('Show');
		});
	}
	
	$(document).ready(init);
})(jQuery);

features.home_tabs = (function($) {
	function init() {
		$('.hide').hide().css('opacity' ,'0');
		$('.tab, .press-list li, .image-tabs').click(hide);
	}
	
	function hide() {
		var $this = $(this);
		$('.year-active').removeClass(function() {
			var active = 'year-active';
			if ($('html').hasClass('lt-ie7')) {
				if ($(this).parent().hasClass('press-table-years')) {
					return active;
				}
				
				else {
					$(this).css('background', '#ebebeb');
					return active;
				}
			}
			else {
				return active;
			}
		});
		$('.show').animate({
			opacity: '0'
		}, 200, function() {
			$(this).hide().removeClass('show').addClass('hide');
			var find_href = $this.find('a').attr('href');
			reveal(find_href);
		});
		$this.addClass('year-active');
		return false;
	}
	
	function reveal(selector) {
		$(selector).show().addClass('show').removeClass('hide').animate({
			opacity: '1'
		}, function() {
			var link = $('#more');
			var test = link.text() === 'More releases';
			test ? link.attr('href', '/laird/investor-relations/results-centre').text('More results') : link.attr('href', '/laird/media-centre/press-releases').text('More releases');
		});
	}
	
	$(document).ready(init);
})(jQuery);

features.cycle = (function($) {
	function init() {
		$('#cycle-items').cycle({
			fx:     'fade', 
			speed:  'slow',
			pager:  '.navigator',
			pagerAnchorBuilder: paginate
		});
	}
	
	function paginate(ind, el) {
		return '<li><a href="#'+ ind +'">&nbsp;</a></li>';
	}
	
	$(document).ready(init);
})(jQuery);

features.scroll = (function($) {
	function init() {
		$('#top').click(setUpScroll);
	}
	
	// Scroll for nav 
	
	function setUpScroll() {
		var $this = $(this);
		var getId = $this.attr('href');
		goToScroll(getId);
		return false;
	}
	
	function goToScroll(id) {
		$('html,body').animate({
    		scrollTop: $(id).offset().top
  		},'slow');
	}
	
	$(document).ready(init);
})(jQuery);

features.input_replace = (function($) {
	function init() {
		focus('#search');
	}
	
	function focus(selector) {
		var $this = $(selector);
			$this
				.data("originalText", $this.val())
				.focus(function() {
					if (this.value === $this.data("originalText")) {
						this.value = "";
					}
				})
				.blur(function() {
					if (this.value === "") {
						this.value = $this.data("originalText");
					}
				});
	}
	
	$(document).ready(init);
})(jQuery);

features.gen_content = (function($) {
	function init() {
		if ($('html').hasClass('lt-ie8')) {
			$('#history').append('<div class="timeline-root"></div>');
		}
	}
	
	$(document).ready(init);
})(jQuery);

features.ie6_hover = (function($) {
	function init() {
		if ($('html').hasClass('lt-ie7')) {
			var $this = $('.latest .tab');
			$this
				.hover(
					function() {
						$(this).css('background', '#25a7d1');
					},
					function() {
						if ($(this).hasClass('year-active')) {
							return;
						}
						
						else {
							$(this).css('background', '#ebebeb');
						}
					}
				);
			$('.sub-nav span').hover(
				function() {
					if ($(this).hasClass('active')) {
						return;
					}
					else {
						$(this).addClass('add-bg');
					}
				},
				function() {
					$(this).removeClass('add-bg');
				}
			);
		}
	}
	
	$(document).ready(init);
})(jQuery);

features.lightbox = (function($) {
	function init() {
		$('.images li .gallery, .lightbox a').lightBox();
	}
	
	$(document).ready(init);
})(jQuery);

features.add_lower_case_letter = (function($) {
	function init() {
		$('h1, h2').text(function() {
			var text = $(this).text();
			var regEXP = /KPIs/;
			var search = text.search(regEXP);
			if (search !== -1) {
				var test = text.charAt(text.length-1);
				var replace = text.replace(test, "<span class='lower-case'>s</span>");
				this.innerHTML = replace;
			}
		});
	}
	
	$(document).ready(init);
})(jQuery);



