/**
 * @author bdgeorge
 * Whitepixels common Javascript routines - requires jQuery
 */

jQuery(document).ready(
function(){
	//Preload any hover images
	jQuery('img.wh-roll').each(function(){
		this.ExtraImage= new Image();
		this.ExtraImage.src = addSuffix(this.src,'_on');
	});
	//Create roll over images on any image with wh-roll as its class
	jQuery('img.wh-roll').hover(
		function(){
			//Over function
			this.src = addSuffix(this.src,'_on');
		},
		function(){
			//Out function
			this.src = remSuffix(this.src,'_on');
		});	
		
	//Fix up height for IE6
	if(jQuery('#content').height() < 500){
		jQuery("#content").height('500px')	
	}
	
	//Feedburner subscribe form
	jQuery('form#feedburner input[type="text"]').one('click', function(){
		jQuery(this).attr('value','');
	})
		
	//General helpers		
	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;
		}
	}		
});


