// javascript/text

var interval = 6000;
var timer = Number;
var fadeSpeed = 1000;
var currentSlide = Number;
var currentPhoto = Number;
var numSlides = Number;
var numPhotos = Number;


function nextSlide() {
	//fade out elements
	$('#element_icons li').eq(currentSlide).animate({opacity:1}, fadeSpeed);
	$('#elements li').eq(currentSlide).fadeOut(fadeSpeed);
	
	// move to next slide or go back to beginning of cycle
	if(currentSlide < numSlides){
		currentSlide ++;
	}else{
		currentSlide = 0;
	}
	if(currentSlide%2===0){
		$('#slideshow img').eq(currentPhoto).fadeOut(fadeSpeed);
		// move to next photo or go back to beginning of cycle
		if(currentPhoto < numPhotos){
			currentPhoto ++;
		}else{
			currentPhoto = 0;
		}
		$('#slideshow img').eq(currentPhoto).fadeIn(fadeSpeed);
	}
	
	//fade in new elements
	$('#element_icons li').eq(currentSlide).animate({opacity:0.5}, fadeSpeed);
	$('#elements li').eq(currentSlide).fadeIn(fadeSpeed);
}

function setupSlideshow() {
	numSlides = $('#element_icons li').length; // get number of element icons
	numSlides = numSlides - 1; // make 1 -> 0 for js
	numPhotos = $('#slideshow img').length; // get number of slideshow imgs
	numPhotos = numPhotos - 1; // make 1 -> 0 for js
	// reset slideshow elements
	$('#element_icons li').css({'opacity':'1'});
	$('#elements li').hide();
	$('#slideshow img').hide();
	// set initial active elements
	currentSlide = 0;
	currentPhoto = 0;
	$('#element_icons li').eq(currentSlide).css({'opacity':'.5'});
	$('#elements li').eq(currentSlide).show();
	$('#slideshow img').eq(currentPhoto).show();
	timer = window.setInterval(nextSlide, interval);	
}

function setupNav(){
	$('#menu-navigation > li').hover(
		function(){
			if($(this).find('ul').stop(true, true).length){
				$(this).addClass('current-menu-item-hover').children('ul').slideDown();
				$('#menu-navigation .current-menu-item').addClass('not-current-menu-item').removeClass('current-menu-item');
				$('#menu-navigation .current_page_ancestor').addClass('not-current_page_ancestor').removeClass('current_page_ancestor');
			}
		},
		function(){
			if($(this).find('ul').length){
				$(this).removeClass('current-menu-item-hover').show().children('ul').slideUp();
				$('.not-current-menu-item').addClass('current-menu-item').removeClass('not-current-menu-item');
				$('.not-current_page_ancestor').addClass('current_page_ancestor').removeClass('not-current_page_ancestor');
			}
		}
	);	
}

function fixLastChild(){
	$('#menu-navigation > li:last-child').addClass('last');	
	$('ul.utility-menu li:last-child').addClass('last').css({'background':'none', 'border':'none'});
	$('.footer li:last-child').addClass('last-child');	
}

function removeSubmitValue(){
	$('.wpcf7-submit').attr('value', '');
}

$(document).ready(function(){
	setupSlideshow();
	setupNav();
	fixLastChild();
	removeSubmitValue();
});

//google analytics tracking code
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-25956698-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();




