$(document).ready(function(){

	/*
	----------------------------------------------------------
	GENERAL
	---------------------------------------------------------- */
	
	// HOVER FADE
	$('.fade').hover(function() {
		$(this).animate({opacity: 0.7}, "fast");
	}, function() {
		$(this).animate({opacity: 1}, "fast");
	});
	
	
	// MAKE ENTIRE AREA CLICKABLE
	$(".clickable").click(function(){
		if($(this).find("a").attr("rel") == "external") {
		    window.open($(this).find("a").attr("href"))
		} else{
		    window.location=$(this).find("a").attr("href"); return false;
		    return;
		}
	});


	// EXTERNAL WINDOWS
	$('a[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });


	// MONCUR LOGO ANIM
	$("#moncur a").hover(function() {
		$(this).next("span").animate({opacity: "show"}, "slow");
	}, function() {
		$(this).next("span").animate({opacity: "hide"}, "fast");
	});
	
	
	if($("body").attr("id") == "home") {
	$(function () {
		    $('#js-news').ticker({
				displayType: 'reveal',
		        fadeInSpeed: 600,
		        titleText: ''
		    });
		});
	}

	/*
	----------------------------------------------------------
	SET EQUAL HEIGHT COLUMNS: HOMEPAGE
	---------------------------------------------------------- */
	function setEqualHeight(columns) 
	{
		var tallestcolumn = 0;
		columns.each(
			function() 
			 {
				  currentHeight = $(this).height();
				  if(currentHeight > tallestcolumn) 
				  {
						tallestcolumn = currentHeight;
				  }
			}
		);
		columns.height(tallestcolumn);
	}

	// INITIALIZE EQUAL HEIGHT
	setEqualHeight($("#section-intros > div"));
	setEqualHeight($("#footer > div.inline"));
	
	
	/*
	----------------------------------------------------------
	SHOW / HIDE CONTENT TOGGLE
	---------------------------------------------------------- */
	$("#industry-services ul").hide();

	 $('#industry-services h3').click(function(){
		$(this).toggleClass("active");
		$(this).next("ul").slideToggle("normal");
		return false;
	});
	
	// CONTACTS
	// $('#contact-info h2:first').addClass("active");
	// $("#contact-info div:not(:first)").hide();
	
	$("#contact-info div").hide();
	 $('#contact-info h2').click(function(){
		$(this).toggleClass("active");
		$(this).next("div").slideToggle("normal");
		return false;
	});
	
	 $('#contact-info h3.parent').click(function(){
		$(this).toggleClass("active");
		$(this).next("div").slideToggle("normal");
		return false;
	});
	


		
	// Featured project filtering
	$("#project-list-industry-button").click(function() {
		var filterValue = $("#project-list-industry-select").val(); 
		var filterValueSelector = '';
		
		if (filterValue == "") { filterValue = "all"; }
		
		if (filterValue == "all") { 
			$(this).parent().parent().parent().find(".filter-section").show();
			$("#projects #project-listing h2").show();
		} else { 
			if (filterValue != "all") { filterValueSelector = '.filter-section-' + filterValue }		 
			$(this).parent().parent().parent().find(".filter-section").hide(); 
			$(this).parent().parent().parent().find(filterValueSelector).show();
			$("#projects #project-listing h2").hide();
			$("#projects #project-listing div h2").show();
		}
		
		if (filterValue == "all" ) {
			$("#h1-projects-browse").html("All Industries");
			window.location.hash = "";
		} else if (filterValue == "electric") {
			$("#h1-projects-browse").html("Electric Power");
			window.location.hash = "electric";
		} else if (filterValue == "gas") {
			$("#h1-projects-browse").html("Oil / Gas");
			window.location.hash = "gas";
		} else if (filterValue == "renewable") {
			$("#h1-projects-browse").html("Renewable Energy");
			window.location.hash = "renewable";
		} else if (filterValue == "water") {
			$("#h1-projects-browse").html("Water / Sewer / Civil");
			window.location.hash = "water";
		} else if (filterValue == "communications") {
			$("#h1-projects-browse").html("Communications");
			window.location.hash = "communications";
		// } else if (filterValue == "installation") {
		// 			$("#h1-projects-browse").html("Installation Fulfillment");
		} else if (filterValue == "government") {
			$("#h1-projects-browse").html("Government");
			window.location.hash = "government";
		}	
		
	});	
	
	if ( getParameterByName('industry') != '' ) {
		$("#project-list-industry-select").val(getParameterByName('industry'));
		$("#project-list-industry-button").click();		
	} 

	if ( window.location.hash != '' ) {
		$("#project-list-industry-select").val(window.location.hash.substring(1));
		$("#project-list-industry-button").click();		
	}
	
	// Featured Project Finder
	$("#project-finder-button-submit").click(function() {
		location.href = 'browse.aspx#' + $("#project-finder #industry").val();
	});

	
	
	$('.flexslider').flexslider();

	/*
	----------------------------------------------------------
	FORMS
	---------------------------------------------------------- */
	// CLEAR VALUE ON FOCUS
	$('.labelvalue').each(function() {
	    var default_value = this.value;
	    $(this).focus(function() {
	        if(this.value == default_value) {
	            this.value = '';
	        }
	    });
	    $(this).blur(function() {
	        if(this.value == '') {
	            this.value = default_value;
	        }
	    });
	});
	
	// VALIDATEOR
	$("#contact-form").validate();
	
	
});

// END ON READY


/*
----------------------------------------------------------
	UTILITY FUNCTIONS
---------------------------------------------------------- */

// Gets value of querystring item
function getParameterByName( name ) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null )
	return "";
	else
	return decodeURIComponent(results[1].replace(/\+/g, " "));
}	


function readCookie(name,delimit)
{


  if (document.cookie == '')
  {
    return false;
  }
  else
  {
    var fC,lC;
    var mcookie = unescape(document.cookie);
    fC = mcookie.indexOf(name);
    var ph = fC + name.length;
    if ((fC != -1) && (mcookie.charAt(ph) == '='))
    {
      fC += name.length + 1;
      lC = mcookie.indexOf(delimit,fC);
      if (lC == -1) lC = mcookie.length;
      return unescape(mcookie.substring(fC,lC));
    }
    else
    {
      return false;
    }
  }
}

		function validatorFormAssess(theform) {
		 
			var isError = false;
			var theCaptcha = readCookie('Captcha','; ');
	
			// Hide any errors previously shown
			$("#errors").hide();
			$("#errors li").hide();

			if (document.getElementById('contactform').fname.value.length == 0 || document.getElementById('contactform').fname.value=='First') {
				isError = true;
				$("#error-fname").animate({opacity: "show"}, "fast");
			}
   
          			
if (document.getElementById('contactform').lname.value.length == 0 || document.getElementById('contactform').lname.value=='Last') {
				isError = true;
				$("#error-lname").animate({opacity: "show"}, "fast");
			}

if (document.getElementById('contactform').email.value.length == 0 || document.getElementById('contactform').email.value=='Email') {
				isError = true;
				$("#error-email").animate({opacity: "show"}, "fast");
			}

if (document.getElementById('contactform').phone.value.length == 0 || document.getElementById('contactform').phone.value=='Phone') {
				isError = true;
				$("#error-phone").animate({opacity: "show"}, "fast");
			}
					

if (document.getElementById('contactform').department.value.length == 0 || document.getElementById('contactform').department.value=='Select a Department') {
				isError = true;
				$("#error-department").animate({opacity: "show"}, "fast");
			}



				
			if ( document.getElementById('contactform').captcha.value.length == 0 ) {
				isError = true;
				$("#error-captcha").animate({opacity: "show"}, "fast");
			}
		
			
			
			if ( document.getElementById('captcha').value != theCaptcha ) {
				isError = true;
				$("#error-captcha").animate({opacity: "show"}, "fast");
			}
		
			
			if (isError) {
				$("#errors").animate({opacity: "show"}, "fast");
				$("#errors").focus();
				return false;
		
			} else {
				return true;
			}
		
			return false;						
		}
		
		
		function setsubject(department)
		{
		  if (department.selectedIndex == 0 )
		  {
		    document.getElementById("sHR").style.display="none";
		    document.getElementById("sMarketing").style.display="none";		    
		    document.getElementById("sVendor").style.display="none";		    
		  }
		  
		  if (department.selectedIndex == 1 )
		  {
		    document.getElementById("sHR").style.display="block";
		    document.getElementById("sMarketing").style.display="none";		    
		    document.getElementById("sVendor").style.display="none";		    
		  }
		  
		  if (department.selectedIndex == 2 )
		  {
		    document.getElementById("sHR").style.display="none";
		    document.getElementById("sMarketing").style.display="block";		    
		    document.getElementById("sVendor").style.display="none";		    
		  }

		  if (department.selectedIndex == 3 )
		  {
		    document.getElementById("sHR").style.display="none";
		    document.getElementById("sMarketing").style.display="none";		    
		    document.getElementById("sVendor").style.display="block";		    
		  }

		  
		 }
		 
		
		

