$(function() {
  
  // search field opacity + focus and blur effects
  $('#search').css("opacity", "0.6");
  var labelTxt = $('#search label').text();
	$('#searchfield').attr('value',labelTxt);
	$('#searchfield').focus(function(){
		if ((this.value == '') || (this.value == labelTxt)) {
			$(this).val('');
		}
	});
	$('#searchfield').blur(function(){
		if (this.value == '') {
			$(this).val(labelTxt);
		}
	});
	
	// hover effect for icons in sidebar (bus, newsletter)
	$(".snippet a").hover(function() {
  		$(this).next("p").animate({opacity: "show", left: 100}, "slow");
  	}, function() {
  		$(this).next("p").animate({opacity: "hide", left: 120}, "fast");
  	});
  	
  // slideshow on homepage
  $('#slideshow .slide .description').css("opacity", "0.9");
  $('#slideshow .slide .link').css("opacity", "0.9");
  $('#slideshow').innerfade({
  				speed: 'slow',
  				timeout: 4000,
  				type: 'sequence',
  				containerheight: '385px'
  			});
  
  // facebox
  //$('a[rel*=facebox]').facebox();
  popup('a[rel]');
  
});

//Manages all of the popup windows using facebox
function popup(Elem) {
	$(Elem).click(function(){
			var theUrl = this.href.split("#")
			var addr = (theUrl[0] + " #" + theUrl[1] + " > *");
			
			if (this.rel == "equipe") {
				var c = $("<div class='equipe'><div style='text-align:center;'><img src='/facebox/loading.gif' /></div></div>");
			};
			
			$(c).load(addr, function(){
				jQuery.facebox(c);
			});
			return false;
	});
};