/**
 * Adds rollover to an image.
 * This script assumes that there is a corresponding
 * image with _over appended to the filename (before the extension)
 * 
 * @param obj	A jquery object representing the image to add the rollover to
 */
function rollover(obj,selectedOverride) {
	if(obj.attr("src").indexOf("_over") > 0) return;
	if(obj.hasClass("selected") &! selectedOverride) return;
	var extension = obj.attr("src").substr((obj.attr("src").length-3),3);
	obj.attr("src",obj.attr("src").replace("."+extension,"_over."+extension));
}

/**
 * Adds rollout to an image.
 * This script assumes that there is a corresponding
 * image with _over appended to the filename (before the extension)
 * 
 * @param obj	A jquery object representing the image to add the rollout to
 */
function rollout(obj) {
	if(obj.attr("src").indexOf("_over") < 0) return;
	if(obj.hasClass("selected")) return;
	var extension = obj.attr("src").substr((obj.attr("src").length-3),3);
	obj.attr("src",obj.attr("src").replace("_over."+extension,"."+extension));
}

/**
 * Preloads a rollover image
 * This script assumes that there is a corresponding
 * image with _over appended to the filename (before the extension).
 * 
 *  @param obj	A jquery object representing the image to preload a rollover image for
 */
function preloadRollover(obj) {
	var extension = obj.attr("src").substr((obj.attr("src").length-3),3);
	var img = new Image();
	img.src = obj.attr("src").replace("."+extension,"_over."+extension);
}

function getPixelValue(css_pixel_string) {
	return parseFloat(css_pixel_string.replace("px",''));
}

/**
 * Adds rollover/rollout functionality to an image and
 * preloads the rollover image.
 * This script assumes that there is a corresponding
 * image with _over appended to the filename (before the extension)
 * 
 *  @param obj	A jquery object representing the image to add rollover functionality to
 */
function addRollover(obj) {
	obj.each(function() {
		preloadRollover($(this));
	});
	obj.mouseover(function() {
		rollover($(this));
	});
	obj.mouseout(function() {
		rollout($(this));
	});
}

function openWindow(pageUrl,width,height,winName,scrollbars) {
	if(scrollbars != 1) scrollbars = 0;
    var newWindow = window.open(pageUrl,winName,"toolbar=0,scrollbars="+scrollbars+",location=0,statusbar=0,menubar=0,resizable=0,width="+width+",height="+height);
    return newWindow;
}
	
/* function to fix the -10000 pixel limit of jquery.animate */
$.fx.prototype.cur = function(){
    if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
      return this.elem[ this.prop ];
    }
    var r = parseFloat( jQuery.css( this.elem, this.prop ) );
    return typeof r == 'undefined' ? 0 : r;
}
$(document).ready(function() {
	$(".rollover").each(function() {
		addRollover($(this));
	});
});
