/**
* Index.js - all the js for the homepage and section homepages
**/ 

// this replaces the img src of the feature images with the real imag for pg speed. The src of the real img is set in the id
$(document).ready(function()
{
	$('.featureImg1').show();
	$('.featureImg').each(function(){
          $(this).attr('src', $(this).attr('title'));
          $(this).attr('title', "");
    });

    $('.grayHover').hover(function () {
   		$('.grayHover > img').css({'opacity' : '0.9'});
		$("img", this).css({'opacity' : '1'});
    });

    setInterval('rotate()',7000);
});

/**
* Rotate the main feature images
**/ 
function rotate() 
{	
	//Get the first image
	var current 		= $('.featureNavOn').attr('id');
	if(current == undefined){ return false; }
	var currentIdNumber = current.substr(10,1);
	var newIdNumber     = parseFloat(currentIdNumber);
	newIdNumber++;
	if(newIdNumber == 5){newIdNumber = 0};
	
	// hide all the images & remove on state from current item
	$('.featureImg').hide();
	$('.featureNavLink').removeClass('featureNavOn'); // removes the class which gives the 'on state
	//show the new img
	$('.featureImg').fadeOut('slow');
	$('.featureImg'+newIdNumber).fadeIn('slow');
	$('#featureNav'+newIdNumber).addClass('featureNavOn');
};


/** 
*	Swap out the images in the feature box on hover 
*	Make last as otherwise slows stuff down
**/
$(document).ready(function(){	
	// on hover change the main feature img
	$('.featureNavLink').hover(function () {
		$('.featureNavLink').removeClass('featureNavOn'); // removes the class which gives the 'on state to the first item
		// extract the identifier number from the link's id
		var linkId 			= $(this).attr('id');
		var linkIdNumber 	= linkId.substr(10,1);
		// hide all the images
		$('.featureImg').fadeOut('fast');
		//show the new img
		$('.featureImg'+linkIdNumber).fadeIn('fast');
      },
  	  function () {
      	$(this).addClass('featureNavOn'); // add the class to show the first item is selected again
  	  });
});
