

// ********************************************************************************************** //
// Determine Functions Relevant to Section to Initialise


// Boot up jQuery:
jQuery(document).ready(function($)
{
	//init_PageContent();
	$("[rel*=lightbox]").lightbox();
	
	$('#quotes').cycle({ 
		fx:     'fade', 
		speed:  'fast', 
		timeout: 10000, 
		next:   '#quote-next', 
		prev:   '#quote-prev',
		pause:	1
	});
	
});


// Determine functions to initialise at page load:
function init_PageContent()
{
	
	// Generic cross-site functions:
	$("a[href=#]").click(function() { return false; });
	init_MainNav_DropDowns();
	
	// Page specific functions:
	switch (curSection)
	{
		case("sect-home"):
			init_Slider();
			break;
		case("sect-retail"):
			$("[rel*=lightbox]").lightbox();
			break;
			
		case("sect-sponsorship"):
			console.log("Here");
			$("[rel*=lightbox]").lightbox();
			break;
			
		case("sect-lubricants"):
			initAccordion();
			break;
	}
	
}




// ********************************************************************************************** //
// Functions

function init_MainNav_DropDowns()
{
	$("ul#nav").superfish(
	{
		animation	: { height:"show" },
		speed		: "fast",
		delay		: 400
	});
}


function initTooltips() {
	
	//Select all anchor tag with rel set to tooltip
	
	$('.question-mark').mouseover(function(e) {  
		
		//Grab the title attribute's value and assign it to a variable  
		var tip = $(this).attr('title');      
		
		//Remove the title attribute's to avoid the native tooltip from the browser  
		$(this).attr('title','');  
		
		//Append the tooltip template and its value  
		$('body').append('<div id="tooltip"><p class="tipBody">' + tip + '</p></div>');       
		if ($.browser.msie && $.browser.version <= 6 ) $('#tooltip').bgIframe();
		
		var myWidth = $('#tooltip').width();
		var newY = e.pageY + 25;
		var newX = e.pageX + 15;
		var windowWidth = $(window).width();
		
		if ((newX + myWidth) > windowWidth) {
			newX = windowWidth - myWidth - 30;
		}
		
		//Set the X and Y axis of the tooltip  
		$('#tooltip').css('top', newY );
		$('#tooltip').css('left', newX );
		
		//Show the tooltip with faceIn effect  
		$('#tooltip').fadeIn('500');  
		//$('#tooltip').fadeTo('10',0.8);  
				
	}).mousemove(function(e) {
		
		var myWidth = $('#tooltip').width();
		var newY = e.pageY + 25;
		var newX = e.pageX + 15;
		var windowWidth = $(window).width();
		
		if ((newX + myWidth) > windowWidth) {
			newX = windowWidth - myWidth - 30;
		}
		
		//Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse  
		$('#tooltip').css('top', newY );  
		$('#tooltip').css('left', newX );  
			
	}).mouseout(function() {  
		
		//Put back the title attribute's value  
		$(this).attr('title',$('.tipBody').html());  
		
		//Remove the appended tooltip template  
		$('div#tooltip').remove();  
		
	});  
	
}


function init_Slider() {
	
	// -- slideAnything Plugin Functionality ---------------------------------------------------------------------------------------- //
	function formatText(index, panel) {
	  return index + "";
	}
	$(function () {
		$('.anythingSlider').anythingSlider({
			easing: "easeInOutExpo",				// Anything other than "linear" or "swing" requires the easing plugin
			autoPlay: true,					// This turns off the entire FUNCTIONALITY, not just if it starts running or not.
			delay: 5000,					// How long between slide transitions in AutoPlay mode
			startStopped: false,			// If autoPlay is on, this can force it to start stopped
			animationTime: 500,				// How long the slide transition takes
			hashTags: true,					// Should links change the hashtag in the URL?
			buildNavigation: true,			// If true, builds and list of anchor links to link to each slide
			pauseOnHover: true,				// If true, and autoPlay is enabled, the show will pause on hover
			startText: "Play",				// Start text
			stopText: "Pause",				// Stop text
			navigationFormatter: formatText	// Details at the top of the file on this use (advanced use)
		});
	});
	// ------------------------------------------------------------------------------------------------------------------------------ //

}


function initAccordion()
{
	$('.faq-accordion div.answer').hide();
	
	$('.faq-accordion>li>a').click(
		function() {
			
			var checkLink = $(this);
			var checkElement = $(this).next();
			
			$('.faq-accordion a').removeClass('selected');
			
			if((checkElement.is('div')) && (checkElement.is(':visible'))) {
				$('.faq-accordion div:visible').slideUp('normal');
				return false;
			}
			
			if((checkElement.is('div')) && (!checkElement.is(':visible'))) {
				$('.faq-accordion div:visible').slideUp('normal');
				checkElement.slideDown('normal');
				checkLink.addClass('selected');
				return false;
			}
			
			return false;
			
		}
		
	);
	
}


