jQuery(function($) {
$(document).ready(function() {

                                // Preload all rollovers
                                $(".hoverlink img").each(function() {
                                                // Set the original src
                                                rollsrc = $(this).attr("src");
												if (rollsrc.match(/.gif$/ig)) {
												    rollON = rollsrc.replace(/.gif$/ig,"_over.gif");
												} else if (rollsrc.match(/.jpg$/ig)) {
                                                	rollON = rollsrc.replace(/.jpg$/ig,"_over.jpg");
												} else if (rollsrc.match(/.png$/ig)) {
													rollON = rollsrc.replace(/.png$/ig,"_over.png");
												} 
												

                                                $("<img>").attr("src", rollON);
                                });

                                // Navigation rollovers
                                $(".hoverlink a").mouseover(function(){
                                                imgsrc = $(this).children("img").attr("src");
												if (typeof imgsrc != 'undefined') {
                                                	matches = imgsrc.match(/_over/);

                                                	// don't do the rollover if state is already ON
                                                	if (!matches) {
														if (imgsrc.match(/.gif$/ig)) {
															imgsrcON = imgsrc.replace(/.gif$/ig,"_over.gif"); // strip off extension
														} else if (imgsrc.match(/.jpg$/ig)) {
                                                			imgsrcON = imgsrc.replace(/.jpg$/ig,"_over.jpg"); // strip off extension
														} else if (imgsrc.match(/.png$/ig)) {
															imgsrcON = imgsrc.replace(/.png$/ig,"_over.png"); // strip off extension
														}

	
											            if (testImage(imgsrcON)) {
															$(this).children("img").attr("src", imgsrcON);
														}
                                                	}
												}

                                });
								
								
                                $(".hoverlink a").mouseout(function(){
                                                $(this).children("img").attr("src", imgsrc);
                                });

                });
});

function testImage(URL) {
    var tester=new Image();
	var valid=new Boolean();
    tester.onLoad=isGood (valid);
    tester.onError=isBad (valid);
    tester.src=URL;
	if (typeof tester  != 'object') {
		valid = false;
	}
	if (tester.width < 1) {
		valid = false;
	}
	return valid;
	
}

function isGood(valid) {
    valid = true;
	return valid;
}

function isBad() {
    valid = false;
	return valid;
}


