$(document).ready(function(){
	
	//GLOBAL STOP VARS
	var clearQueue = true;
	var gotoEnd = true;
	
	//DATE
	function makeArray() {
		for (i = 0; i<makeArray.arguments.length; i++)
		this[i + 1] = makeArray.arguments[i];
	}
	
	var months = new makeArray('January','February','March','April','May',
	'June','July','August','September','October','November','December');
	var date = new Date();
	var day = date.getDate();
	var month = date.getMonth() + 1;
	var yy = date.getYear();
	var year = (yy < 1000) ? yy + 1900 : yy;
	$('#actualDate').text(months[month]+' '+day+' '+year);
	
	//FOOTER SITEMAP
	$('.sitemapLinks > li span').click(function(){
		if ( $(this).parent('li').children('ul').is(':visible') ) {
			$(this).parent('li').children('ul').stop(gotoEnd,clearQueue).slideUp();
		}
		else {
			$(this).parent('li').children('ul').stop(gotoEnd,clearQueue).slideDown();
		}
	});
	
	//CO2 SAVINGS LOADS
	if ( location.href.indexOf('co2saving.php') != -1 ) {
		$('#mainNavbar').hide();
		
		//Loading CO2 Savings Calculator Defaults
		$('.co2DL dt').animate({opacity:.7});
		$('.co2DL dd').animate({opacity:.7}).children('div').hide();
		
		//Display values and AddUp to the Total (onClick)
		$('.co2DL dt').click(function(){
			if ( $(this).hasClass('dtActive') ) {
				$(this).animate({opacity:.7},100).removeClass('dtActive');
				$(this).parent('dl').children('dd').animate({opacity:.7},100).children('div').hide();
				//SUBSTRACTS
				//getThisStringValues
				var co2IntA = $(this).parent('dl').children('dd.co2IntA').children('div').text();
				var co2IntB = $(this).parent('dl').children('dd.co2IntB').children('div').text();
				var co2IntC = $(this).parent('dl').children('dd.co2IntC').children('div').text();
				var parseCo2IntA = parseFloat(co2IntA);
				var parseCo2IntB = parseFloat(co2IntB);
				var parseCo2IntC = parseFloat(co2IntC);
				//getResultsStringValues
				var co2ResultA = $('#co2ResultA').text();
				var co2ResultB = $('#co2ResultB').text();
				var co2ResultC = $('#co2ResultC').text();
				var parseCo2ResultA = parseFloat(co2ResultA);
				var parseCo2ResultB = parseFloat(co2ResultB);
				var parseCo2ResultC = parseFloat(co2ResultC);
				//addIntegersToResults
				var co2SubsA = (parseCo2IntA-parseCo2ResultA)*-1;
				var co2SubsB = (parseCo2IntB-parseCo2ResultB)*-1;
				var co2SubsC = (parseCo2IntC-parseCo2ResultC)*-1;
				//printResults
				$('#co2ResultA').text(co2SubsA);
				$('#co2ResultB').text(co2SubsB);
				$('#co2ResultC').text(co2SubsC);
			}
			else {
				$(this).animate({opacity:1},100).addClass('dtActive');
				$(this).parent('dl').children('dd').animate({opacity:1},100).children('div').show();
				//ADDS UP
				//getThisStringValues
				var co2IntA = $(this).parent('dl').children('dd.co2IntA').children('div').text();
				var co2IntB = $(this).parent('dl').children('dd.co2IntB').children('div').text();
				var co2IntC = $(this).parent('dl').children('dd.co2IntC').children('div').text();
				var parseCo2IntA = parseFloat(co2IntA);
				var parseCo2IntB = parseFloat(co2IntB);
				var parseCo2IntC = parseFloat(co2IntC);
				//getResultsStringValues
				var co2ResultA = $('#co2ResultA').text();
				var co2ResultB = $('#co2ResultB').text();
				var co2ResultC = $('#co2ResultC').text();
				var parseCo2ResultA = parseFloat(co2ResultA);
				var parseCo2ResultB = parseFloat(co2ResultB);
				var parseCo2ResultC = parseFloat(co2ResultC);
				//addIntegersToResults
				var co2AddUpA = parseCo2IntA+parseCo2ResultA;
				var co2AddUpB = parseCo2IntB+parseCo2ResultB;
				var co2AddUpC = parseCo2IntC+parseCo2ResultC;
				//printResults
				$('#co2ResultA').text(co2AddUpA);
				$('#co2ResultB').text(co2AddUpB);
				$('#co2ResultC').text(co2AddUpC);
			}
		});
		
	}
	
	////
	$('#aboutUsWhoPlusBtn').click(function(){
		$('#aboutBottomInfo').fadeIn(350);
	});
	$('#ABwwdList li div').hover(
		function(){
			$(this).css({'background-position':'bottom left','color':'#F8981D'});
			$('#ABwwdList li ul').stop(gotoEnd,clearQueue).fadeOut(350);
			$(this).parent('li').children('ul').fadeIn(350);
		},
		function(){
			$(this).css({'background-position':'top left','color':'#565759'});
		}
	);
	$('#ABmapList li span').hover(
		function(){
			$(this).css({'background-position':'bottom left','color':'#F8981D'});
		},
		function(){
			$(this).css({'background-position':'top left','color':'#565759'});
		}
	);
	$('#ABmapList li span').click(function(){
		$('#ABmapList li div').stop(gotoEnd,clearQueue).fadeOut(350);
		$(this).parent('li').children('div').fadeIn(350);
	});
	$('#ABfiguresList li span').click(function(){
		$('#ABfiguresList li span').css({'color':'#565759'});
		$(this).css({'color':'#F8981D'});
		$('#ABfiguresList li div').stop(gotoEnd,clearQueue).fadeOut(350);
		$(this).parent('li').children('div').fadeIn(350);
	});
	
	$('#newsList li > span').click(function(){
		$('#newsList li > div').removeClass('selectedNews').fadeOut(350);
		$(this).parent('li').children('div').fadeIn(350);
	});
	
	/* $('#landownersList li span').hover(
		function(){
			$(this).css({'background-position':'bottom left','color':'#F8981D'});
		},
		function(){
			$(this).css({'background-position':'top left','color':'#565759'});
		}
	); */
	$('#landownersList li span').click(
		function(){
			$('#landownersList li > div').stop(gotoEnd,clearQueue).fadeOut(350);
			$(this).parent('li').children('div').fadeIn(350);
                        $('#landownersList li span').removeClass('selected');
                        $(this).addClass('selected');
		}
	);
	$('#landownersList li a').click(
                function(){
                        if ($(this).parent('li').children('ul').is(':visible')) {
                            $(this).parent('li').children('ul').slideUp(500,'swing');
                            $('#landownersList li a').removeClass('selected');
                        } else {
                            $('#landownersList li ul').slideUp(350);
                            $('#landownersList li a').removeClass('selected');
                            $(this).parent('li').children('ul').slideDown(500,'swing');
                            $(this).addClass('selected');
                            $(this).parent('li').children('ul').children('li:first-child').children('span').addClass('selected');
                        }
                }
        );
	/* $('#landownersList li a').hover(
		function(){
			$(this).css({'background-position':'bottom left','color':'#F8981D'});
		},
		function(){
			$(this).css({'background-position':'top left','color':'#565759'});
		}
	); */
	$('#cqI').click(
            function(){$('#formOverlay').fadeIn(350);} // css({'display':'block'})
        );
	$('#cqClose').click(
            function(){$('#formOverlay').fadeOut(350);}
        );
	$('#formOverlay').click(
            function(){$('#formOverlay').fadeOut(350);}
        );
	//Map Right Menu
	$('#mapPRsubmenu li').hover(
		function(){ $(this).children('*').css({'color':'#F8981D'}); },
		function(){ $(this).children('*').css({'color':'#565759'}); }
	);
	//Map List Highlight
	$('#cr2Li').hover(
		function(){ $('#googleCR2').addClass('mapMarkerActive'); },
		function(){ $('#googleCR2').removeClass('mapMarkerActive'); }
	);
	$('#cr3Li').hover(
		function(){ $('#googleCR3').addClass('mapMarkerActive'); },
		function(){ $('#googleCR3').removeClass('mapMarkerActive'); }
	);
	$('#pyLi').hover(
		function(){ $('#googlePY').addClass('mapMarkerActive'); },
		function(){ $('#googlePY').removeClass('mapMarkerActive'); }
	);
	/////////////////////////
	$('#hwLi').hover(
		function(){ $('#googleHW').addClass('mapMarkerActive'); },
		function(){ $('#googleHW').removeClass('mapMarkerActive'); }
	);
	$('#rcLi').hover(
		function(){ $('#googleRC').addClass('mapMarkerActive'); },
		function(){ $('#googleRC').removeClass('mapMarkerActive'); }
	);
	$('#bbLi').hover(
		function(){ $('#googleBB').addClass('mapMarkerActive'); },
		function(){ $('#googleBB').removeClass('mapMarkerActive'); }
	);
	$('#drLi').hover(
		function(){ $('#googleDR').addClass('mapMarkerActive'); },
		function(){ $('#googleDR').removeClass('mapMarkerActive'); }
	);
	$('#trLi').hover(
		function(){ $('#googleTR').addClass('mapMarkerActive'); },
		function(){ $('#googleTR').removeClass('mapMarkerActive'); }
	);
	
	//Map Zoom
	$('#nswOnly').click(function(){
		if ( $('#mapZoom').hasClass('nswSelected') ) {}
		else {
			//Markers+GoogleLink Reset
			$('#nswMapLinks li, #vicMapLinks li').removeClass('mapMarkerActive');
			$('#goToGoogleMaps').attr('href','#').animate({opacity:.5}).removeClass('mapMarkerActive');
			$('#staticMap, #vicMapLinks').hide();
			//Zoom Desired Map
			$('#mapZoom').removeClass('vicSelected').addClass('nswSelected');
			$('#mapZoom').stop(gotoEnd,clearQueue).fadeIn(350).animate({width:693,top:-310,left:-440},350);
			setTimeout("$('#nswMapLinks').fadeIn(350);$('#vicMapLinks').hide();",400);
			return false;
		}
	});
	$('#vicOnly').click(function(){
		if ( $('#mapZoom').hasClass('vicSelected') ) {}
		else {
			//Markers Reset
			$('#nswMapLinks li, #vicMapLinks li').removeClass('mapMarkerActive');
			$('#goToGoogleMaps').attr('href','#').animate({opacity:.5}).removeClass('mapMarkerActive');
			$('#staticMap, #nswMapLinks').hide();
			//Zoom Desired Map
			$('#mapZoom').removeClass('nswSelected').addClass('vicSelected');
			$('#mapZoom').stop(gotoEnd,clearQueue).fadeIn(350).animate({width:693,top:-382,left:-350},350);
			setTimeout("$('#vicMapLinks').fadeIn(350);$('#nswMapLinks').hide();",400);
			return false;
		}
	});
	$('#goToGoogleMaps').animate({opacity:.5});
	$('#goToGoogleMaps').click(function(){
		if ( $(this).attr('href') == '#' ) { return false; }
	});
	/**LOCATE ON GOOGLE MAPS**/
	$('#googleCR2').click(function(){
		$('#nswMapLinks li, #vicMapLinks li').removeClass('mapMarkerActive');
		$(this).addClass('mapMarkerActive');
		$('#goToGoogleMaps').attr('href','http://g.co/maps/z7zkd').animate({opacity:1}).addClass('mapMarkerActive');
	});
	$('#googleCR3').click(function(){
		$('#nswMapLinks li, #vicMapLinks li').removeClass('mapMarkerActive');
		$(this).addClass('mapMarkerActive');
		$('#goToGoogleMaps').attr('href','http://g.co/maps/z7zkd').animate({opacity:1}).addClass('mapMarkerActive');
	});
	$('#googlePY').click(function(){
		$('#nswMapLinks li, #vicMapLinks li').removeClass('mapMarkerActive');
		$(this).addClass('mapMarkerActive');
		$('#goToGoogleMaps').attr('href','http://g.co/maps/fbp2a').animate({opacity:1}).addClass('mapMarkerActive');
	});
	
	$('#googleHW').click(function(){
		$('#nswMapLinks li, #vicMapLinks li').removeClass('mapMarkerActive');
		$(this).addClass('mapMarkerActive');
		$('#goToGoogleMaps').attr('href','http://g.co/maps/9gj7r').animate({opacity:1}).addClass('mapMarkerActive');
	});
	$('#googleRC').click(function(){
		$('#nswMapLinks li, #vicMapLinks li').removeClass('mapMarkerActive');
		$(this).addClass('mapMarkerActive');
		$('#goToGoogleMaps').attr('href','http://g.co/maps/cwhup').animate({opacity:1}).addClass('mapMarkerActive');
	});
	$('#googleBB').click(function(){
		$('#nswMapLinks li, #vicMapLinks li').removeClass('mapMarkerActive');
		$(this).addClass('mapMarkerActive');
		$('#goToGoogleMaps').attr('href','http://g.co/maps/4xt3').animate({opacity:1}).addClass('mapMarkerActive');
	});
	$('#googleDR').click(function(){
		$('#nswMapLinks li, #vicMapLinks li').removeClass('mapMarkerActive');
		$(this).addClass('mapMarkerActive');
		$('#goToGoogleMaps').attr('href','http://g.co/maps/3a9n').animate({opacity:1}).addClass('mapMarkerActive');
	});
	$('#googleTR').click(function(){
		$('#nswMapLinks li, #vicMapLinks li').removeClass('mapMarkerActive');
		$(this).addClass('mapMarkerActive');
		$('#goToGoogleMaps').attr('href','http://g.co/maps/fzuqe').animate({opacity:1}).addClass('mapMarkerActive');
	});
	
});
