/***********************************************************************************************************************
DOCUMENT: acc.js
BASE CODE: Ryan Stemkoski
ENHANCED BY: Sons of Ipanema GmbH
DESCRIPTION: This is the JavaScript required to create the accordion style menu.  Requires jQuery library
NOTE: Because of a bug in jQuery with IE8 we had to add an IE stylesheet hack to get the system to work in all browsers. I hate hacks but had no choice :(.
************************************************************************************************************************/

jQuery(document).ready(function() {
	 
	//ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
	jQuery('.accordionButton').click(function() {
	
		if(jQuery(this).hasClass('on') == true) {
	 		jQuery('.accordionContent').slideUp('normal');
	 		jQuery.scrollTo(0,300);
	 	} else {
	 		jQuery('.accordionContent').slideUp('normal',scrollToSlide(this));
	 	}

		//REMOVE THE ON CLASS FROM ALL BUTTONS
		jQuery('.accordionButton').removeClass('on');
   
		//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
		if(jQuery(this).next().is(':hidden') == true) {
			
			//ADD THE ON CLASS TO THE BUTTON
			jQuery(this).addClass('on');
			  
			//OPEN THE SLIDE
			var ani = jQuery(this).next().slideDown('normal');
	
		 } 
		 
	 });
	  
	
	/*** REMOVE IF MOUSEOVER IS NOT REQUIRED ***/
	
	//ADDS THE .OVER CLASS FROM THE STYLESHEET ON MOUSEOVER 
	jQuery('.accordionButton').mouseover(function() {
		jQuery(this).addClass('over');
		
	//ON MOUSEOUT REMOVE THE OVER CLASS
	}).mouseout(function() {
		jQuery(this).removeClass('over');										
	});
	
	/*** END REMOVE IF MOUSEOVER IS NOT REQUIRED ***/
	

	
	/********************************************************************************************************************
	ALTERNATIVE ACCORDION
	********************************************************************************************************************/
	jQuery('.accordionButton2').click(function() {
  	
	 	if(jQuery(this).hasClass('on2') == true) {
	 		jQuery('.accordionContent2').slideUp('normal');
	 		jQuery.scrollTo(0,300);
	 	} else {
	 		jQuery('.accordionContent2').slideUp('normal',scrollToSlideAlt(this));
	 	}
   
		jQuery('.accordionButton2').removeClass('on2');
		
		if(jQuery(this).next().is(':hidden') == true) {
			
			jQuery(this).addClass('on2');
			  
			jQuery(this).next().slideDown('normal');
		 } 
		  
	 });
	  
	
	/*** REMOVE IF MOUSEOVER IS NOT REQUIRED ***/
	
	jQuery('.accordionButton2').mouseover(function() {
		jQuery(this).addClass('over2');
		
	}).mouseout(function() {
		jQuery(this).removeClass('over2');										
	});
	
	/*** END REMOVE IF MOUSEOVER IS NOT REQUIRED ***/	
	
	
	
	/********************************************************************************************************************
	CLOSES ALL S ON PAGE LOAD
	********************************************************************************************************************/	
	jQuery('.accordionContent').hide();
	jQuery('.accordionContent2').hide();



	/********************************************************************************************************************
	SCROLL TO TOP EXPANSION
	********************************************************************************************************************/	
	
	//set the link
  	jQuery('#top-link').topLink({
   		min: 200,
    	fadeSpeed: 500
  	});
  	
  	//smoothscroll
  	jQuery('#top-link').click(function(e) {
    	e.preventDefault();
    	jQuery.scrollTo(0,300);
  	});


});


// SCROLL TO SLIDE
function scrollToSlide(caller) {
	var elementClick = jQuery(caller).attr("id");
	var tempo = (elementClick-1)*31 + 220;
	var destination = jQuery(tempo).offset();
	jQuery.scrollTo(tempo,500);
}


// SCROLL TO SLIDE -> ALTERNATIVE ACCORDEON
function scrollToSlideAlt(caller) {
	var elementClick = jQuery(caller).attr("id");
	var tempo = (elementClick-1)*73 + 220;
	var destination = jQuery(tempo).offset();
	jQuery.scrollTo(tempo,500);
	// console.log(elementClick,tempo)
}


/********************************************************************************************************************
SCROLL TO TOP EXPANSION
********************************************************************************************************************/	

jQuery.fn.topLink = function(settings) {
  	
  	settings = jQuery.extend({
    	min: 1,
    	fadeSpeed: 200
  	}, settings);
  	
  	return this.each(function() {
    	//listen for scroll
    	var el = jQuery(this);
    	el.hide(); //in case the user forgot
    
    	jQuery(window).scroll(function() {
      		if(jQuery(window).scrollTop() >= settings.min)
      		{
        		el.fadeIn(settings.fadeSpeed);
      		}
      		else
      		{
        		el.fadeOut(settings.fadeSpeed);
      		}
    	});
  	});
};

