// JavaScript Document
// jQ Lambda functions

// Check cookie for large text preference
$(function() {
	if ($.cookie('TAPtextsize') == 'large') {
		$('#sizer').addClass('decrease');
		$('body').addClass('biggerfont');
	};
});
 
// Change Font Size
$(function(){
  $("#sizer").click(function(){
	  if ($.cookie('TAPtextsize') == 'large') {
		  	$.cookie('TAPtextsize', null);
			$('#sizer').removeClass('decrease');
			$('body').removeClass('biggerfont');
	  } else {
			$.cookie('TAPtextsize', 'large', { expires: 365 });
			$('#sizer').addClass('decrease');
			$('body').addClass('biggerfont');
	  }
	});
});

// fix IE6 png 
$(function(){
	if ( $.browser.msie && ( $.browser.version.substring( 0, 1 ) == '5' || $.browser.version.substring( 0, 1 ) == '6' ) ) {
		$('.logo').addClass('logoIE');
		$('.increase').addClass('increaseIE');
		$('.decrease').addClass('decreaseIE');		
	}
});

// Handle login operation
$(function() {
	$('#login').click(function() {
		$('#loginForm').show('slow');
	});
});
	
$(function() {
	$('#loginSubmit').click(function() {
		$('#loginForm').hide('slow');
	});
});

// Create breadcrumb
$(function() {
       $("#breadCrumb").jBreadCrumb();
     });

// Newsletter animation
$(function() {
	$(".newsletter").animate({left:'350px'}, 3000, "easeOutBounce");
});

// play audio files
$(function() {
		$('#audio').toggle(function(){
		$('.controlspace').after('<div class="sound"><p src="' + voicefile + '" controls="volumelever" type="audio/basic" autostart="true" loop="false" width="0" height="0"></p><embed src="' + voicefile + '" controls="volumelever" type="audio/basic" autostart="true" loop="false" width="0" height="0"></embed></div>');
		$('#soundon').css('visibility', 'hidden');
		$('#soundoff').css('visibility', 'visible');
		}, function() {
		$('.sound').empty();
		$('#soundoff').css('visibility', 'hidden');
		$('#soundon').css('visibility', 'visible');
		});
});

// tempory format
$(function() {
		$('#newaudio').toggle(function(){
		$('.controlspace').after('<div class="sound"><p src="' + voicefile + '" controls="volumelever" type="audio/basic" autostart="true" loop="false" width="0" height="0"></p><embed src="' + voicefile + '" controls="volumelever" type="audio/basic" autostart="true" loop="false" width="0" height="0"></embed></div>');
		$('#newsoundon').css('visibility', 'hidden');
		$('#soundoff').css('visibility', 'visible');
		}, function() {
		$('.sound').empty();
		$('#soundoff').css('visibility', 'hidden');
		$('#newsoundon').css('visibility', 'visible');
		});
});

// Drive donate button animation
$(function(){
	$('#spin').hover(function() {$(this).animate({rotate: '+=720deg'});});
});

/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

// Drive link button animation
$(function(){
$(".websurvey").hoverIntent(function() {
			    $(this).stop().animate({ marginTop: "-10px" }, 150,  function() {
		    	$(this).animate({ marginTop: "-7px" }, 250);
		    });
		    	},function(){
				    $(this).stop().animate({ marginTop: "3px" }, 350, function() {
		    		$(this).animate({ marginTop: "0px" }, 350);
		    	});
		   });	
	});
	
$(function(){
$(".link1 img").hoverIntent(function() {
			    $(this).stop().animate({ marginTop: "-10px" }, 150, function() {
		    	$(this).animate({ marginTop: "-7px" }, 250);
		    });
		    	},function(){
				    $(this).stop().animate({ marginTop: "3px" }, 350, function() {
		    		$(this).animate({ marginTop: "0px" }, 350);
		    	});
		   });	
	});

$(function(){
$(".contactus img").hoverIntent(function() {
			    $(this).stop().animate({ marginTop: "-10px" }, 150, function() {
		    	$(this).animate({ marginTop: "-7px" }, 250);
		    });
		    	},function(){
				    $(this).stop().animate({ marginTop: "3px" }, 350, function() {
		    		$(this).animate({ marginTop: "0px" }, 350);
		    	});
		   });	
	});

// Show text for staff photos on Brent page
$(function() {
	$('#liz').click(function() {
		$('.julestext').fadeOut('slow');
		$('.debitext').fadeOut('slow');
		$('.liztext').show('slow');
	});
});

$(function () {
		$('.liztext').click(function() {
			$(this).hide("slow");
		});
});

$(function() {
	$('#jules').click(function() {
		$('.debitext').fadeOut('slow');
		$('.liztext').fadeOut('slow');
		$('.julestext').show('slow');
	});
});

$(function () {
		$('.julestext').click(function() {
			$(this).hide("slow");
		});
});

$(function() {
	$('#debi').click(function() {
		$('.liztext').fadeOut('slow');
		$('.julestext').fadeOut('slow');
		$('.debitext').show('slow');
	});
});

$(function () {
		$('.debitext').click(function() {
			$(this).hide("slow");
		});
});

// Drive spider animation
$(function(){
	$('.spiderbox.movespider').hover(function(){
		$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:900});
				}, function() {
					$(".cover", this).stop().animate({top:'-260px'},{queue:false,duration:900});
	});
});

// AJAX drivers
$(function() {
	$('#allaboutus').click(function() {
	$('#ajaxsection').load('allaboutus.html', function() {
		$(this).fadeIn('slow');
		});
	return false;
	});
});
$(function() {
	$('#speakingup').click(function() {
	$('#ajaxsection').load('bvspeakingup.html', function() {
		$(this).fadeIn('slow');
		});
	return false;
	});
});
$(function() {
	$('#itsmylife').click(function() {
	$('#ajaxsection').load('itsmylife.html', function() {
		$(this).fadeIn('slow');
		});
	return false;
	});
});
$(function() {
	$('#managementcommittee').click(function() {
	$('#ajaxsection').load('bvmancom.html', function() {
		$(this).fadeIn('slow');
		});
	return false;
	});
});
$(function() {
	$('#transition').click(function() {
	$('#ajaxsection').load('transition.html', function() {
		$(this).fadeIn('slow');
		});
	return false;
	});
});
