
// jewishcafe - common javascript functions


// DEV function
// debug alert function, used to enable and disable "debug alerts" for checkpoint watching
// the alert aspect can be commented in or out to affect all alerts, or,
// the whatLevel arg (optional) can be used to choose which alerts to show)

function debugAlert (whatContent,whatLevel) {
	
	minLevel = 0;
	
	if (whatLevel == null) {whatLevel=-999;};
	
	if (whatLevel >= minLevel) {
		//alert (whatContent);
	}
}

// write inline content function
function  writeInlineContent(whatContent) {

	document.write(whatContent);
	//document.close();
}


// cron functions v1.1
// start cc custom generic rollover scripts, short html optimized, requires preload flag
// (short html optimized = efforts to shorten the html for bandwidth)
// * gif only
// * over images MUST have suffix -over
// * img parameter name must match SRC

function cron(whatName,srcPrefix) {
	if (document.images && (preloadFlag == true)) {
		if (!srcPrefix) { srcPrefix = "images/" }
		imgfileName = srcPrefix + whatName + "-over.gif";
		document[whatName].src = imgfileName;
	}
}

function croff(whatName,srcPrefix) {
	if (document.images && (preloadFlag == true)) {
		if (!srcPrefix) { srcPrefix = "images/" }
		imgfileName = srcPrefix + whatName + ".gif";
		document[whatName].src = imgfileName;
	}
}



// for newImage, create a global array for image variables, so each imgvar is unique
var newImageKount = 0;
var newImageArray = Array();

// start generic explicit rollover script (requires preload flag)
function newImage(arg) {
	if (document.images) {
		newImageArray[newImageKount] = new Image();
		newImageArray[newImageKount].src = arg;
		newImageKount++;
		return newImageArray[newImageKount];
	}
}

// long form HTML img swap, args are in pairs, (name,swap2src)
function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

// start generic img preload script
var preloadFlag = false;
function preloadImages() {
	
	if (document.images) {
		
		// explict preloads here
		
		// NOTE:  from james, Tuesday, June 11, 2002 
		//
		// these explict rollovers are my last copy of the explict JC rollovers
		// i'm sure they've been updated, but i've included them for reference.
		// the new "autopreload" handles most preloading quite well.  For most projects, I've
		// been able to ignore the need for explict rollovers, except for unusual circumstances
		// of unusual SRCs and path structure.
		//
		// (these explict rollovers are _NOT_ needed for the new front page as of today.  The
		// rollovers in the front page are currently handled by the autopreload)
		//
		// the autopreload automatically takes any image with a name attribute, and sucks off
		// the full SRC (absolute!), and preloads the same image with an -over, 
		// and the img suffix (.jpg or .gif)
		// it's really quite handy
		//
		// please experiment with the commented out development section in the autoPreload function
		// that pops a new window with
		// a list of all autoloaded images, to get a feel, to best meet your long term needs.
		//
		// in cases here with JC, the -over suffix got mangled because of the 32 char limit, being
		// mac friendly.  It's a balance between well named files and character limits to get
		// under 32 chars.
		
		// top right rollovers
/*		body_toprightnav_search_ove = newImage("images/body_toprightnav_search-ove.gif");
		body_toprightnav_helpfaq_ov = newImage("images/body_toprightnav_helpfaq-ov.gif");
		body_toprightnav_privacy_ov = newImage("images/body_toprightnav_privacy-ov.gif");
		
		// main nav rollovers preload
		body_mainnav_l_main_over 	= newImage("images/body_mainnav_l_main-over.gif");
		body_mainnav_l_memb_over 	= newImage("images/body_mainnav_l_memb-over.gif");
		body_mainnav_l_editpro_over = newImage("images/body_mainnav_l_editpro-over.gif");
		body_mainnav_l_pstjoke_over = newImage("images/body_mainnav_l_pstjoke-over.gif");
		body_mainnav_l_pstphto_over = newImage("images/body_mainnav_l_pstphto-over.gif");
		body_mainnav_l_qmatch_over 	= newImage("images/body_mainnav_l_qmatch-over.gif");
		body_mainnav_l_tests_over 	= newImage("images/body_mainnav_l_tests-over.gif");
		
		body_mainnav_r_srch_over 	= newImage("images/body_mainnav_r_srch-over.gif");
		body_mainnav_r_browse_over 	= newImage("images/body_mainnav_r_browse-over.gif");
		body_mainnav_r_chat_over 	= newImage("images/body_mainnav_r_chat-over.gif");
		body_mainnav_r_clinks_over 	= newImage("images/body_mainnav_r_clinks-over.gif");
		body_mainnav_r_friends_over = newImage("images/body_mainnav_r_friends-over.gif");
		body_mainnav_r_mailbox_over = newImage("images/body_mainnav_r_mailbox-over.gif");
		body_mainnav_r_sndmail_over = newImage("images/body_mainnav_r_sndmail-over.gif");
		body_mainnav_r_whoson_over 	= newImage("images/body_mainnav_r_whoson-over.gif");
		
		// arrow rollovers
		body_arrow_left_over 		= newImage("images/body_arrow_left-over.gif");
		body_arrow_right_over 		= newImage("images/body_arrow_right-over.gif");
		*/
		
		
		// start autoPreload
		autoPreloadImages();
		
		preloadFlag = true;
	}
}


// autoPreloadImages checks all local images and 'auto-assumes' a filename to preload for
// all images with a "name" attribute.  
//   - the rollover image is assumed to have suffix "-over"
//   - requires "newImage" function
//   - assumes 3 character extension (".gif", ".jpg")
// james maarhuis, v1.1, april 2002

function autoPreloadImages() {
	if (document.images) {
		
		var baseHREF = location.href.substring(0,location.href.lastIndexOf("/")+1);
		var autoLoaded = "autoLoaded: \n <br><br>" + location.href + "<BR><BR>";
		
	for (var i=0; i<document.images.length; i+=1) {
			if (document.images[i].name) { 
				imagesrc_full = document.images[i].src;

				imagesrc_prefix = imagesrc_full.substring(0,imagesrc_full.length-4);
				
				imagesrc_suffix = imagesrc_full.substring(imagesrc_full.length-4,imagesrc_full.length);
				preloadThis = newImage(imagesrc_prefix + "-over" + imagesrc_suffix);
		
				autoLoaded += imagesrc_prefix + "-over" + imagesrc_suffix + " \n <br>";
			}
		}
		
		// section below pops a new window with a SRC list of the autoPreloaded Images
		
		/*
		newWindow = window.open("","srclist","height=600,width=600,resizable=yes");
		newWindow.document.write(autoLoaded);
		newWindow.document.close();
		newWindow.focus();
		*/
		
	}
}


function popWindow(whatURL,whatName,whatWidth,whatHeight) {
	window.status=''
	newWindow = window.open(whatURL,whatName,"scrollbars=no,width=" + whatWidth + ",height=" + whatHeight + ",toolbar=no,titlebar=no");
	newWindow.focus();
	window.status=''
}	


