$(function(){

		// Service Icons - rollover
		$('.icons li a').bind('mouseenter mouseleave', function(){
			$(this).siblings('.rollover').stop(true,true).animate({opacity:'toggle'}, $.browser.msie ? 0 : 'fast');
		});


		$('ul.mainnav').children('li').hoverIntent(function(){
			var $this = $(this),
				dropdown = $('.dropdownblock', $this),
				anchor   = $this.children('a'),
				hasSublinks = !!$('ul', dropdown).length,
				overlay    = $('.overlay'),
				overlayVisible = overlay.is(':visible');
			// Show the blog below it
			dropdown.stop(true,true).fadeIn('fast');
			anchor.addClass('active');

			if (hasSublinks)
			{
				if ( ! overlayVisible)
				{
					overlay.stop(true,true).show().fadeTo('fast', .7);
				}
			}
			else
			{
				if (overlayVisible)
				{
					overlay.stop(true,true).fadeTo('fast', 0, function(){ $(this).hide(); });
				}
			}
		}, function(){
			var $this = $(this),
				dropdown = $('.dropdownblock', $this),
				anchor   = $this.children('a');

			// Show the blog below it
			dropdown.stop(true,true).fadeOut('fast');
			anchor.removeClass('active');
		});
		
		$('ul.mainnav').mouseleave(function(){
			var overlay    = $('.overlay'),
				overlayVisible = overlay.is(':visible');

			if (overlayVisible)
			{
				overlay.stop(true,true).fadeTo('fast', 0, function(){ $(this).hide(); });
			}
		});
		
		
		$('.servicesblock').mouseover(function() {
			$(this).find('.serviceinnerblock').stop().animate({top: "-70px"}, 200 );
			
		});
		$('.servicesblock').mouseout(function(){
			$(this).find('.serviceinnerblock').stop().animate({top: "0"}, 200 );
		});
		
		
		$('.servicesblock').bind('mouseenter mouseleave', function(){
			$(this).find('.titleblock').toggleClass('up');
			$('.servicestrapline', this).stop(true,true).animate({opacity:'toggle'}, $.browser.msie ? 0 : 'fast');
		});
		
		$('.servicesblock:has(a[href])').click(function()
		{
			var location = $('a[href]', this).eq(0).attr('href');
			
			if (location !== undefined)
			{
				window.location = location;
				window.status = location;
			}
			
		}).bind('mouseenter mouseleave', function()
		{	
			var title = $('a[href]', this).eq(0).attr('title');
			$(this).attr('title', title);
		});
		
		
		
		
		
		$('.workblock').mouseover(function() {
			$(this).find('.workinnerblock').stop().animate({top: "-62px"}, 200 );
			
		});
		$('.workblock').mouseout(function(){
			$(this).find('.workinnerblock').stop().animate({top: "0"}, 200 );
		});
		
		
		$('.workblock').bind('mouseenter mouseleave', function(){
			$(this).find('.titleblock').toggleClass('up');
			$('.workstrapline', this).stop(true,true).animate({opacity:'toggle'}, $.browser.msie ? 0 : 'slow');
		});
		
		$('.workblock:has(a[href])').click(function()
		{
			var location = $('a[href]', this).eq(0).attr('href');
			
			if (location !== undefined)
			{
				window.location = location;
				window.status = location;
			}
			
		}).bind('mouseenter mouseleave', function()
		{	
			var title = $('a[href]', this).eq(0).attr('title');
			$(this).attr('title', title);
		});
		

		
		
		// Page content - extra panel rollover
		$('.clickmore').click(function() {
			$('.extracontent').stop(true,true).animate({opacity:'toggle'}, $.browser.msie ? 0 : 'fast');
		});
		
		
		
		// Projectblock rollovers
		$('.projectblock:has(a[href])').click(function()
		{
			var location = $('a[href]', this).eq(0).attr('href');
			
			if (location !== undefined)
			{
				window.location = location;
				window.status = location;
			}
			
		}).bind('mouseenter mouseleave', function()
		{
			$(this).toggleClass('blockrollover');
			var title = $('a[href]', this).eq(0).attr('title');
			$(this).attr('title', title);
		});
		

		// Animate image within projectblocks
		$('.projectblock').mouseenter(function()
		{
			$('img', this).stop().fadeTo('fast', 0.4);
		}).mouseleave(function()
		{
			$('img', this).stop().fadeTo('fast', 1);
		});
		
		
		
		// Projectblock rollovers
		$('.largeprojectblock:has(a[href])').click(function()
		{
			var location = $('a[href]', this).eq(0).attr('href');
			
			if (location !== undefined)
			{
				window.location = location;
				window.status = location;
			}
			
		}).bind('mouseenter mouseleave', function()
		{
			$(this).toggleClass('blockrollover');
			var title = $('a[href]', this).eq(0).attr('title');
			$(this).attr('title', title);
		});
		

		// Animate image within projectblocks
		$('.largeprojectblock').mouseenter(function()
		{
			$('img', this).stop().fadeTo('fast', 0.4);
		}).mouseleave(function()
		{
			$('img', this).stop().fadeTo('fast', 1);
		});
		
		
		
		// Newsblock rollovers
		$('.newsblock:has(a[href])').click(function()
		{
			var location = $('a[href]', this).eq(0).attr('href');
			
			if (location !== undefined)
			{
				window.location = location;
				window.status = location;
			}
			
		}).bind('mouseenter mouseleave', function()
		{
			$(this).toggleClass('blockrollover');
			var title = $('a[href]', this).eq(0).attr('title');
			$(this).attr('title', title);
		});
		

		// Animate image within projectblocks
		$('.newsblock').mouseenter(function()
		{
			$('img', this).stop().fadeTo('fast', 0.4);
		}).mouseleave(function()
		{
			$('img', this).stop().fadeTo('fast', 1);
		});
		
		
		
		// Vacancyblock rollovers
		$('.vacancyblock:has(a[href])').click(function()
		{
			var location = $('a[href]', this).eq(0).attr('href');
			
			if (location !== undefined)
			{
				window.location = location;
				window.status = location;
			}
			
		}).bind('mouseenter mouseleave', function()
		{
			$(this).toggleClass('blockrollover');
			var title = $('a[href]', this).eq(0).attr('title');
			$(this).attr('title', title);
		});
		

		// Animate image within Vacancyblocks
		$('.vacancyblock').mouseenter(function()
		{
			$('img', this).stop().fadeTo('fast', 0.4);
		}).mouseleave(function()
		{
			$('img', this).stop().fadeTo('fast', 1);
		});


		function showPanelForMarker(panel){
			if (panel === '') return;
			var active = $('.mypanel.' + panel);
			var marker = $('#' + panel + '.mymarker');
			if (active.filter(':visible').length) return;
			$('.mymarker.active').removeClass('active');
			$('.mypanel:visible').hide();
			active.stop().fadeIn(200);
			marker.addClass('active');
		}

		// reworked javascript for contact us and company history
		$('.mymarker').mouseenter(function(){
			showPanelForMarker($(this).attr('id'));
		});

		$('.mymarker a').click(function(){ return false; });

		// preselect the location of the office from the hash if on the contacts page		
		if (document.location.hash === ''){
			showPanelForMarker('nottingham');
		}else{			
			showPanelForMarker(document.location.hash.replace('#', ''));
		}
});

	
		
$(function(){
	

	$('.basic-fader').scrolly({
		selectors: {
			container: '.items',
			controls: '.buttons'
		},
		minimumElements:2,
		before:function(){
			var self = this;
		
			var str = '';
			for (var i=0; i < this.total(); i++)			
			{
			  str += '<li>'+(i+1)+'</li>';
			}
			
			this.controls().html(str).find('li').click(function(){
				self.move($(this).prevAll().length + 1);
			});

		},
		autoscroll: 5000,
		moved: function(index){
			this.controls().find('li').removeClass('active').eq(index - 1).addClass('active');
			this.el.find('.controls .description').html(this.at(index).find('p').html());
			this.el.find('.controls .title').html(this.at(index).find('h3').html());
			
		},
		showControls:function(){
			return this.controls().parent().show();
		},
		show: function(item){
			$(item).stop(true,true).addClass(this.classes.active).fadeIn(500);
		}
	});
	
	var scroller;
	
	$('.cms-fader').scrolly({
		selectors: {
			container: '.cms-anchor',
			controls: '.buttons',
			items: '.cms-component'
		},
		before:function(){
			var self = this;

			var str = '';
			for (var i=0; i < this.total(); i++)
			{
			  str += '<li>'+(i+1)+'</li>';
			}

			this.controls().html(str).find('li').click(function(){
				self.move($(this).prevAll().length + 1);
			});

			scroller = this;
		},
		autoscroll: 3000,
		moved: function(index){
			this.controls().find('li').removeClass('active').eq(index - 1).addClass('active');
		},
		showControls:function(){
			return this.controls().parent().show();
		},		
		show: function(item){
			$(item).addClass(this.classes.active).stop(true,true).fadeIn(500);
		}		
	});

	var workspaceBind = function(scroller){
		if (typeof scroller === 'undefined') return;

		$('#cms-workspace').bind('editing-enabled', function(){
			scroller.el.parent().removeClass('afeature');
			scroller.disable();
		}).bind('editing-disabled', function(){
			scroller.el.parent().addClass('afeature');
			scroller.enable();
		});
	}

	//workspaceBind(scroller);

});
	
	

			
