/* 
	
	GSG scripts.
	
-------------------------------------------------------------------------------------------------- */

// Easings
$.easing.easeOutQuint = function(x,t,b,c,d){
	return c*((t=t/d-1)*t*t*t*t + 1) + b;
};

// Cufon calls
Cufon.replace('#homeContent h3, #impactListing h2, #content h1, #filterAccordion h3, .related .title, .testimonials h2, #sectionTitle, #summary, .diagram #main h2, #hoverBox .title');
Cufon.replace('#homeBanner h2, #diagramLanding .title');
//Cufon.replace('.moduleNewsList .title', { hover: true });

// jQuery functions
($(function(){
	
	// ---- Drop down nav ---- //
	$('#nav ul > li').hover(function(){
		$(this).addClass('over').children('ul').fadeIn(100);
	}, function(){
		$(this).removeClass('over').children('ul').fadeOut(100);
	});
	
	$('#nav ul ul > li').mouseenter(function(){
		$(this).children('ul').hide();
	});
	
	// ---- Home page banner ---- //
	$('#banners').before('<div id="bannersPager"></div>');
	$('#banners').cycle({
		fx: 'fade',
		speed: 1000,
		pause: 1,
		timeout: 7000,
		pager: '#bannersPager'
	});
	
	// ---- Home page news ticker ---- //
	$('#newsTicker ul').cycle({
		fx: 'fade',
		speed: 1000,
		pause: 1
	});
	
	// ---- Filter Accordion ---- //
	$('#filterAccordion .title').click(function(){
		if($(this).data('open')){
			$(this).data('open', false).removeClass('titleOpen').next('ul').slideUp({duration:400, easing: 'easeOutQuint'});
		}
		else{
			$(this).data('open', true).addClass('titleOpen').siblings('ul').slideDown({duration:400, easing: 'easeOutQuint'});
		}
	});
	
	// ---- Filter Accordion Detection ---- //
	$('#filterAccordion a').each(function(){
		if($(this).hasClass('on')){
			$(this).parents('ul').slideDown(100).prev('.title').addClass('titleOpen').data('open', true);
		}
	});
		
	// ---- Tabs on diagram ---- //
	if($('.diagram').length){
		if($('.diagram').attr('id') != 'diagramLanding'){
			$('#main').tabs({ fx : {opacity: 'toggle', duration: 'fast'} });
		}
	}
	
	// ---- Diagram landing ---- //
	if($('#diagramLanding').length){
		$('area').mouseenter(function(e){
			var id = $(e.target).attr('id');
			var pos;
			switch(id){
				case 'first':
					pos = 0;
					break;
				case 'second':
					pos = 352;
					break;
				case 'third':
					pos = 704;
					break;
				case 'forth':
					pos = 1056;
					break;
				case 'fifth':
					pos = 1408;
					break;
				case 'sixth':
					pos = 1760;
					break;
				default:
					break;
			}
			pos = pos * -1;
			$('#mapCont').css({'background-position': '0 ' + pos + 'px'});
		});

		$('area').mousemove(function(e){
			var id = $(e.target).attr('id');
			$('.'+id).show();
			$('.'+id).css({
				top: ((e.pageY - $('#solutionsLanding').offset().top) - 150) + 'px',
				left: ((e.pageX - $('#solutionsLanding').offset().left) ) + 'px'
			});	
		});
		$('area').mouseleave(function(e){
			var id = $(e.target).attr('id');
			$('.'+id).hide();
		});
	};
	$('#hoverBox li').hover(function(){
		$(this).show();
	}, function(){
		$(this).hide();
	});
	
	
	
	// ---- Diagram Detail ---- //
	if($('#edWheel').length){
		$('area').mouseenter(function(e){
			var id = $(e.target).attr('id');
			var pos;
			switch(id){
				case 'first':
					pos = 0;
					break;
				case 'second':
					pos = 260
					break;
				case 'third':
					pos = 520;
					break;
				case 'forth':
					pos = 780;
					break;
				case 'fifth':
					pos = 1040;
					break;
				case 'sixth':
					pos = 1300;
					break;
				default:
					break;
			}
			pos  = pos * -1;
			$('#edWheelCont').css({'background-position': '0 ' + pos + 'px'});
		});

		$('area').mousemove(function(e){
			var id = $(e.target).attr('id');
			$('.'+id).show();
			$('.'+id).css({
				top: ((e.pageY - $('#edWheel').offset().top) - 150) + 'px',
				left: ((e.pageX - $('#edWheel').offset().left) ) + 'px'
			});	
		});
		$('area').mouseleave(function(e){
			var id = $(e.target).attr('id');
			$('.'+id).hide();
			showSection();
		});
		
		$('#hoverBox li').click(function(){
			var className = $(this).attr('class');
			var href;
			switch(className){
				case 'first':
					href = $('#first').attr('href');
					break;
				case 'second':
					href = $('#second').attr('href');
					break;
				case 'third':
					href = $('#third').attr('href');
					break;
				case 'fourth':
					href = $('#fourth').attr('href');
					break;
				case 'fifth':
					href = $('#fifth').attr('href');
					break;
				case 'sixth':
					href = $('#sixth').attr('href');
					break;
				default :
					break;
			}
			window.location = href;
		});
		
		var showSection = function(){
			var url = window.location.href.split('/solutions/')[1];
			var pos;
			switch(url){
				case 'clarify-of-direction':
					pos = 0;
					break;
				case 'ability-to-sense-market-shifts':
					pos = 260;
					break;
				case 'continuous-improvement-innovation':
					pos = 520;
					break;
				case 'new-growth-initiatives':
					pos = 780;
					break;
				case 'agility-of-the-organisation':
					pos = 1040;
					break;
				case 'impact-of-execution':
					pos = 1300;
					break;
				default:
					break;
			}
			pos  = pos * -1;
			$('#edWheelCont').css({'background-position': '0 ' + pos + 'px'});
		};
		
		showSection();
		
	};
	
	
	$('.hentry:first').css('padding-top',0);
	
}));


