/*
 * Sounder-JS 1.0 - The Sound Source & Lightrix.
 * By Gavin Coulson (http://www.gavincoulson.ca)
*/

var pathToTemp = '/wp/wp-content/themes/sounder/';	 //path to wordpress template



$(document).ready(function() {
						   
	// Header slide show settings

	$(function() {
		$('#crossslide').crossSlide({
			fade: 4
		}, [
		  {
			src:  pathToTemp + 'img/header/01_new.jpg',
			from: 'top left 1x',
			to:   'bottom right 1x',
			time: 12
		  },
		  
		  {
			src:  pathToTemp + 'img/header/02_new.jpg',
			from: 'bottom left 1x',
			to:   'top right 1x',
			time: 12
		  },
		  
		  {
			src:  pathToTemp + 'img/header/03_new.jpg',
			from: 'bottom left 1x',
			to:   'top right 1x',
			time: 12
		  }
		]);
	});
	
	
						   
	//Nav functionality
						   
	$("#page-nav li.current_page_item a").children("img.nav-buttonGreen").css({'opacity' : '1'});
	

	$("#page-nav li:not(.current_page_item) a").hover(
		function() {
			$(this).children("img.nav-buttonBlue").stop().animate({opacity: 1},200);
			meterAnimate();
		},
		function() {
			$(this).children("img.nav-buttonBlue").stop().animate({opacity: 0},700);
			$(".metre-active").stop().css("width","0px");
	});
	
	
	$("#page-nav li a").click(
		function() {
			$(this).children("img.nav-buttonGreen").stop().animate({opacity: 1},200);
			$("#page-nav li.current_page_item a").children("img.nav-buttonGreen").stop().animate({opacity: 0},200);
	});
	
	function meterAnimate() {
		var metreNo = 8;
		var incr = 16;
		var result = Math.round(Math.random()*8)*16;
		$(".metre-active").animate({width: result},150,meterAnimate);
	}
	
	
	
	//Residential page functions
	
	$("div#residential-posts div.post").hide();
	$("div#residential-posts div:first-child").show();

	
	$("ul#residential-nav li a").click(
		function() {
			var newsPostID = $(this).attr('id'); 
			$("div#residential-posts div.post:visible").hide();
			$("#residential-posts #post-"+newsPostID).fadeIn();
	});
	
	
	//Commercial page functions
	
	$("div#commercial-posts div.post").hide();
	$("div#commercial-posts div:first-child").show();

	
	$("ul#commercial-nav li a").click(
		function() {
			var newsPostID = $(this).attr('id'); 
			$("div#commercial-posts div.post:visible").hide();
			$("#commercial-posts #post-"+newsPostID).fadeIn();
	});
	
	//Projects page functions
	
	$("li#resNav-Header a").click(function() {
		$(this).toggleClass("down")	;		
		$("li#comNav-Header a").removeClass("down");
		
		$('ul#residential-nav').slideToggle();
		$('ul#commercial-nav').slideUp();

	});
	
	$("li#comNav-Header a").click(function() {
		$(this).toggleClass("down")	;	
		$("li#resNav-Header a").removeClass("down");
		
		$('ul#commercial-nav').slideToggle();
		$('ul#residential-nav').slideUp();
	});
	
	
	$("div#projects-posts div.post").hide();
	$("div#projects-posts div:first-child").show();
	
	$("ul#projects-nav ul.projectsSubNav li a").click(function() {
		var newsPostID = $(this).attr('id'); 
		$("div#projects-posts div.post:visible").hide();
		$("#projects-posts #post-"+newsPostID).fadeIn();
	});
	
	//Products page functions
	
	$("div#products-posts div.post").hide();
	$("div#products-posts div:first-child").show();

	
	$("ul#products-nav li a").click(
		function() {
			var newsPostID = $(this).attr('id'); 
			$("div#products-posts div.post:visible").hide();
			$("#products-posts #post-"+newsPostID).fadeIn();
	});
	
});