
/*-------------------------------------------------------
---- BEHAVIOUR (Primary Javascript file) ----------------
--------------------------------------------------------*/


$(document).ready( function() { 																	//When the document is ready
	
	
//Open external links in new windows
		
		var external = $('a[rel="external"]');														//Get all links with rel="external" and place them into the 'external'
	
		external.attr("title", external.attr("title") + " - Link opens in a new window..");			//Take the links current title and append it with the external link message
			
		external.click( function() {																//When an external link is clicked
			
		window.open( $(this).attr('href') );														//Open its href in a new window
        
		return false;																				//Cancel the links default behaviour
		
		});																							//End function
		
		
//Colour form fields on form submission, visual aid when submitting forms via AJAX

//165,202,240
	
		/*$('form.frmGeneric').submit( function() {													//When a form is submitted
			
		var formFields = $(this).find(':input[class!="submit-button"]');									//Put the forms input and textarea elements into 'formFields' with the exception of submit button (has id="submit-button")
		
		var increment = 155;																		//The amount of blue to be used initially
		
		function fadeIt(){																			//Declare a function called fadeIt
		
		formFields.css({backgroundColor: "rgb(255,255,"+ (increment+=4) +")"});						//Take the selected inputs and increase the blue by four degrees 
		
		if(increment < 255){																		//If the increment is less than white	
			
			setTimeout(fadeIt, 40);																	//repeat after 40 milliseconds
			
			}
		
		}
		
		fadeIt();																					//Call the initial function
		
		return false;																				//Cancel the forms default behaviour (replace with AJAX)
		
		});		*/																					//End function


			
//Customisable Accordion function ----------------------------------

//CONFIG --
var independant = false;                                                                    //Change to true if you want accordion items to open and close independently                      
  
//---------

  $('.accordion li div').hide();
  
  $('.accordion .accordionHeading').click( function(){
  

      if($(this).parent().find('.accordionContent').is(":hidden")){     
        
        if (independant === false) {
          
          $(this).parent().parent().find('.accordionContent').slideUp('fast');
          $(this).parent().parent().find('.accordionHeading').removeClass('active');

         
          //$('.accordion li div').slideUp('fast')
         // $('.accordionHeading').removeClass('active');
        
        };
        
        $(this).parent().find('.accordionContent').slideDown('fast');
        $(this).addClass('active'); 
        
      } else {    
        
        $(this).parent().find('.accordionContent').slideUp('fast');
        $(this).parent().parent().find('.accordionHeading').removeClass('active');
              
      }

  });
				


//Tabbed Panes function ------------------------------------------

	if('.tabbedContent'){
		
		$('.tabbedContent').addClass('panes');
		
		var height = 0;
		
		$('.panes').before("<ul class='tabs'></ul>");
	
		$('.panes div').each( function(i){
			
			$(this).addClass('pane' + i);
			
			$('ul.tabs').append("<li id='" + i + "'><a href='#'>" + $(this).find('.panelHeading').text() + "</a></li>");
			
			if($(this).height() > height){
				
				height = $(this).height();
				
			}
			
		});
	
		$('ul.tabs li#0').addClass('active');	
	
		$('.panes').css({'height': height + 40});

		$('.panes div').hide();
		$('.panes div:first').show();	

		$('ul.tabs a').click( function(){
		
			$('ul.tabs li').removeClass('active');
			$(this).parent('li').addClass('active');
		
			var pane = $(this).parent('li').attr('id');
			
			$('.panes div').hide();
			$('.panes div.pane' + pane).show();
			
			return false;
			
		});

	}
	
	
//Focus form function ------------------------------------------

	$('.tip').hide();
	
	$(".focus").prepend("<div id='focusPane'><p></p></div>");

	$(".focus .frmRow").click( function(){
		
		$('input,select,textarea').css({'border-color': '#cccccc','border-style':'solid','border-width':'1px'});
		
		$(this).children('input,select,textarea').css('border-color','#51A0F0');
		
		$("#focusPane").fadeIn('fast');
		$("#focusPane p").text($(this).children('.tip').text());

		var position = $(this).position();			  							
		$("#focusPane").animate({"top":position.top - 6});

    });
	
	$(".focus .frmRow input, .focus .frmRow select, .focus .frmRow textarea").focus( function(){
		
		$('input,select,textarea').css({'border-color': '#cccccc','border-style':'solid','border-width':'1px'});
		
		$(this).css('border-color','#51A0F0');
		
		$("#focusPane").fadeIn('fast');
		$("#focusPane p").text($(this).siblings('.tip').text());

		var position = $(this).parent('.frmRow').position();			  							
		$("#focusPane").animate({"top":position.top - 6});

    });
	
// Fading blockquote mechanism -------------------------------------

	var quoteArray = new Array("We can't solve problems by using the same kind of thinking we used when we created them.<em>~ Albert Einstein</em>","Every act of creation is first an act of destruction.<em>~ Pablo Picasso</em>","Don't find a fault. Find a remedy.<em>~ Henry Ford</em>","It's kind of<br />fun to do the impossible.<em>~ Walt Disney</em>");
	var count = 0;
	
	function changeQuote(newQuote){
		
		$('.fadeQuote p').remove();
		$('.fadeQuote').append("<p style='display:none;'>" + newQuote + "</p>");
		$('.fadeQuote p').fadeIn(3000);
		$('.fadeQuote p').fadeOut(3000);
		
		if(count == quoteArray.length - 1){
		
			count = 0;
		
		} else {

			count++;

		}
		
	}
	
	setInterval(function(){changeQuote(quoteArray[count])},6000);

	

	
}); 																								//End document.ready













