/**
 * @author bdgeorge
 * Whitepixels common Javascript routines for Xcart - requires jQuery and the color plugin
 */

$(document).ready(function(){	
	//Preload any hover images
	$('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
	$('img.wh-roll').hover(
		function(){
			//Over function
			this.src = addSuffix(this.src,'_on');
		},
		function(){
			//Out function
			this.src = remSuffix(this.src,'_on');
		});
	//If the user clicks in the subscribe input then clear out the default text
	//The funny ID is because this is a campaign monitor element
	$('#side_about input[type="text"]').one("click", function(){
		$(this).attr("value","");
	});
	$('img[longdesc]').thumbPopup();
	$("#accordion").accordion({ 
		header: "h3",			
		collapsible: true,
		active:false,
		autoHeight: false });		
});
$(window).load(function(){
	//repeat the body sizing in case we have any late loaders
	$('#page_body').height($('#page_body').height() - $('#page_body').height()%30 + 30);	
});
/**
* Helper functions
*/
function popupWindow(myurl, myheight, mywidth, mywindowID) {
 	if(window.open){
		window.open(myurl,mywindowID,'alwaysRaised=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=' + mywidth
		+ ',height=' + myheight
		+ ',screenX=150,screenY=150,top=150,left=150');
		return false;
 	}else{
 		return true;
 	}
}
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;
	}
	
}