$(document).ready(function() { 

	$(".white-border-shadow-image").addClass('apply-white-border-shadow-image');
	$(".popup").colorbox({width:"80%", height:"80%", iframe:true});
	$(".show-newsletter-form").colorbox({width:"350", inline:true, href:".newsletter-form"});
	$(".show-agent-contact-form").colorbox({width:"500", inline:true, href:".agent-contact-form"});
	Cufon.replace("#menu ul li",{
		fontWeight: 'bold',
		fontSize: '17px',
		textShadow: '1px 1px #fff',
		fontFamily: 'Gill Sans MT Condensed'
	});
	
	Cufon.replace("#menu ul li.selected",{
		fontWeight: 'bold',
		fontSize: '17px',
		textShadow: 'none',
		fontFamily: 'Gill Sans MT Condensed'
	});
	
	$("#menu ul li ul").hide();
	
	$('#menu ul li').hover(function() {
		  $(this).children("ul").show();
		  
		 
		  
		  
		 	Cufon.replace(this,{
				fontWeight: 'bold',
				fontSize: '17px',
				color: 'white',
				textShadow: 'none'
			});
			
			if($(this).children("ul").text().length>0)
			{
				$(this).css({"background-color":"#0975a9"});
				$(this).children("a").css({"height":"32px"});
				Cufon.replace($(this).children("ul").children("li"),{
					fontWeight: 'normal',
					fontSize: '15px',
					textShadow: 'none',
					fontFamily: 'Zurich Cn BT',
					color:"#96d7f4"
				});
				
			}
			
			 
			
		},function() {
		  $(this).children("ul").hide();
		  if(!$(this).hasClass("selected"))
		  {
		  Cufon.replace(this,{
				fontWeight: 'bold',
				fontSize: '17px',
				textShadow: '1px 1px #fff',
				color:"#5a5a5a"
			});
			if($(this).children("ul").text().length>0)
			{
				$(this).css({"background-color":"transparent"});
				$(this).children("a").css({"height":"31px"});
			}
		  }
	});
	
	
	 
	$('#menu li ul li').hover(function() {
	  	Cufon.replace(this,{
				fontWeight: 'normal',
				fontSize: '15px',
				textShadow: 'none',
				fontFamily: 'Zurich Cn BT',
				color:"white"
		});
	},function() {
	 	Cufon.replace(this,{
				fontWeight: 'normal',
				fontSize: '15px',
				textShadow: 'none',
				fontFamily: 'Zurich Cn BT',
				color:"#96d7f4"
		});
	});
	
	
	$('#menu li ul').hover(function() {
	  $(this).show();
	},function() {
	  $(this).hide();
	});
	if($("#h1replacement").text().length>0)
	{
		$("h1").text($("#h1replacement").text());
		$("#h1replacement").text("");
	}
	
	if($(".system-error-message h1").text().length>0)
	{
		$(".content h1").text($(".system-error-message h1").text());
		$(".system-error-message h1").text("");
	}
	
	
	if($(".content h1").text() == "biogill")
	$(".content h1").text("BIOGILL");
	
	$(".content h1").text($("h1").text().replace("&amp;","&"));

	$('a[rel=external]').attr('target','_blank');
	webappimagelinkreplace("homepage-item"); 	
	rotatelatestprojects(1);
}); 


 var clicked1=false;
 
 $('#CAT_Search').click(function() {
  
  if(clicked1 == false)
  {$('#CAT_Search').val(''); clicked1=true;}
});




function webappimagelinkreplace(input)
{
	$("."+input).each(function(i) {
		$(this).children('a').attr("href",$(this).children(".web-app-link").attr("href"));
	});

}

$('.faq-item .faq-question').click(function(event) {
event.preventDefault();
	
  $('.faq-answer').slideUp();
  $(this).next().slideDown();
});


var rotatelatestprojectstime=6000;
var rotatelatestprojectsnumber = 1;

function rotatelatestprojects(input)
{
	
	$('#latest-projects .latest-project-wrap').fadeOut();
	$('#latest-projects .latest-project-wrap:nth-child('+input+')').fadeIn();
	
	if(rotatelatestprojectsnumber>=2)
	rotatelatestprojectsnumber = 1;
	else
	rotatelatestprojectsnumber++; 
	
	
	setTimeout(
	  function() 
	  {
		rotatelatestprojects(rotatelatestprojectsnumber);
	  }, rotatelatestprojectstime);
}


function findagent()
{
	$("#catcustomcontentform66776").attr("action",$("#catcustomcontentform66776").attr("action")+"&country="+$("#CAT_Custom_209315").val());
	
	
	
	if($("#CAT_Custom_209315").val() == "All")
	document.location = ("/find-an-agent");
	else
	document.catcustomcontentform66776.submit();
}




