/**
 * @author bdgeorge
 * @version 1.0 23/02/2009 Replaced .html() with .text() to work around bug with Safari 2.0.4
 */
$(document).ready(function(){
wh.init();
	$('.rotator ul')
		.cycle({ 
	    fx:     'fade', 
	    speed:  'slow', 
	    timeout: 5000, 
	});
});
//Helper functions
function remSuffix(a,b){
	//removes suffix b from filename a without removing the file extension
	var lastdot = a.lastIndexOf(b + '.');
	if (lastdot==-1){
		return a;
	} else {
		var ext = a.slice(lastdot+b.length,a.length);
		return a.slice(0,lastdot) + ext;
	}		
}
function addSuffix(a,b){
	//adds suffix b to filename a without removing the file extension
	var lastdot = a.lastIndexOf(".");
	if (lastdot==-1){
		return a;
	} else {
		var ext = a.slice(lastdot,a.length);
		return a.slice(0,lastdot) + b + ext;
	}
	
}
//White Pixels object
var wh = {	
		/***********************************************************/
		/*********** No need to change below here ******************/
		init: function(){
			//Remove roll over class for any png's in Internet Explorer 6
			$("img[src$='.png']").each(
				function(i){
					if($.browser.msie){
						if(parseInt(jQuery.browser.version)<=6){
							$(this).removeClass('wh-roll');
						}				
					}
				});
			//preload the images for rollovers
			$('img.wh-roll').each(function(){
				this.ExtraImage= new Image();
				this.ExtraImage.src = addSuffix(this.src,'_on');
			});			
			//Add roll over images to them
			$('img.wh-roll').hover(
				function(){
					//Over function
					this.src = addSuffix(this.src,'_on');
				},
				function(){
					//Out function
					this.src = remSuffix(this.src,'_on');
				});	
			//Add default text styling to form fields
			$(".defaultText").focus(function(){
				if ($(this).val() == $(this).attr('title')){
					$(this).removeClass("defaultTextActive");
					$(this).val('');
				}
			});	
			$(".defaultText").blur(function(){
				if ($(this).val()==""){
					$(this).addClass("defaultTextActive");
					$(this).val($(this).attr('title'));
				}
			});
			$(".defaultText").blur();
			//Flush out any default text before submitting a form
			$("form").submit(function(){
				//Look for anything with the defaultTextActive class
				//and reset it to empty
				$(".defaultTextActive").each(function(){
					//This if clause is just belts and braces
					if ($(this).val() == $(this).attr('title')){
						$(this).removeClass("defaultTextActive");
						$(this).val('');
				}					
				});
			});
		}
	}