// javascript Document

//BEGIN window.addEvent('load', function()
window.addEvent('load', function() {
	/*MM_preloadImages('http://www.just4kidselc.com/new/resources/menu-indicator.gif','http://www.just4kidselc.com/new/resources/menu-indicator-actv.gif','http://www.just4kidselc.com/new/resources/menu-indicator-actvmov.gif','http://www.just4kidselc.com/new/resources/menu-indicator-mov.gif');*/
								 
	setPageDesignation(window.location);
	//setMainMenuDesignation(window.location);
});
//END window.addEvent('load', function()
	/*								   
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}					   
		*/							   
///////////////////////////////////////////////////////////////////////////////


/*------------------------------------------------------------------------------------
swap_image_based_on_url.js overview;  
.name == setPageDesignation(window.location);
.purpose == swaps any image (i.e., a menu button) associated with an <a> tag to its active page image counter part for the current page.
.call origin == <body onload="setAlternateImageSource(window.location);">
.notes == >>> be sure to include within the <head> of the html document: 
		      <script language="javascript" src="../DIRECTORY OF JS FILE/swapImgOrStyleByURL_v09-11301510.js" type="text/javascript"></script>
		  >>> IMPORTANT ID NAMING GUIDELINES:
		  >>> IMGs ONLY: The corresponding image's ID must incorporate the link's ID in order to pass the comparison. Ex: <a id="your-link"> <img id="your-link-img">
		  >>> ELEMENTs ONLY: The childNode <a> ID must incorporate the Element's ID in order to pass the comparison. Ex: <li id="this-info"> <a id="this-info-link">
		  >>> For validation purposes, ID comparisons *MUST* match begining from the the index position "0" (first character). Therefor ID's must not change the 
		  	   the start of the ID, For example, an ID "mycontent" and "link-mycontent" will fail whereas "mycontent" and "mycontent-link" will succeed.
------------------------------------------------------------------------------------*/

//NOTE THIS IS A SPECIAL VERSION THAT CHANGES THE PARENTS MENU INDICATOR IN ADDITION TO THE CURRENT PAGE'S MENU INDICATOR

function setPageDesignation(pageURL){
	//BEGIN adjust as required/desired
	
	// STYLE VARIABLES EXAMPLE
	var imageOrStyle="s"; //Determines if function will alter a image of a object's style. Acceptable values are i=image or s=style 
	var elementToChange="a"; //tag name. i.e., "img" OR "a" OR "p" OR "li" OR etc. If imageOrStyle="i" this must be "img";
	var activeImgSuffix="NA"; //Corresponding active image's suffix. ONLY REQUIRED IF imageOrStyle=="i"]. default value is "NA";
	var styleToChange="backgroundImage"; //The style's property to be changed. Be sure to use JS syntax. ONLY REQUIRED IF [imageOrStyle=="s"]. default value is "NA";
	var newStyleValue="url('http://www.hccmca.org/resources/tab-actv.jpg')"; //The style's new value. ONLY REQUIRED IF [imageOrStyle=="s"]. default value is "NA";
	
	/* IMAGE VARIABLES EXAMPLE
	var imageOrStyle="i"; //Determines if function will alter a image of a object's style. Acceptable values are i=image or s=style 
	var elementToChange="img"; //tag name. i.e., "img" OR "a" OR "p" OR "li" OR etc. If imageOrStyle="i" this must be "img";
	var activeImgSuffix="-actv"; //Corresponding active image's suffix. ONLY REQUIRED IF imageOrStyle=="i"]. default value is "NA";
	var styleToChange="NA"; //The style's property to be changed. Be sure to use JS syntax. ONLY REQUIRED IF [imageOrStyle=="s"]. default value is "NA";
	var newStyleValue="NA"; //The style's new value. ONLY REQUIRED IF [imageOrStyle=="s"]. default value is "NA";
	*/
	//END adjust as required/desired
	
	var docLinks=new Array();
	var itemForChange=new Array();
	var h,i,j;
	h='"'+pageURL+'"';
	docLinks=window.document.getElementsByTagName('a');
	itemForChange=window.document.getElementsByTagName(elementToChange);
	for(i=0;i<docLinks.length;i++){
		//URI Comparison checks to see if docLinks' array entry matches pageURL && then assures a match by confirming equal lengths
		//the second half of the comparison is in case documents with the same names appear in different sections;
		if((h.indexOf(docLinks[i].href)>-1)&&((h.length-2)==docLinks[i].href.length)){
			if(imageOrStyle=='i'){
				//implements if changing a image's src;
				for(j=0;j<=itemForChange.length;j++){
					//Checks to see that the Link's ID is within the itemForChange's ID* && then assures that the match was not in error due to a docLink not having an ID;
					//* ALSO > In order for this comparison to be successful it must validate to indexOf == 0. If we set the validation to >-1 it has the potential
					// to misinterpit <img id="your_link_img"> and <a id="our-link"> validating it as a match. We could simply change the order of links so 
					// our-link-img comes before your-link-img but that is unrealistic. Down side to validating to indexOf == 0 is the index position must be 0
					// which commands the match to be from the string's begining.
					if((itemForChange[j].id.indexOf(docLinks[i].id)==0)&&(docLinks[i].id!="")&&(docLinks[i].className.indexOf("mainmenu-elements")!=0)&&(itemForChange[j].id!="")){
						var imgURLString=String(itemForChange[j].src);
						newURLPart01=imgURLString.slice(0,imgURLString.lastIndexOf("."));
						newURLPart03=imgURLString.slice(imgURLString.lastIndexOf("."));
						itemForChange[j].src=(newURLPart01+activeImgSuffix+newURLPart03);
						//found a match and assigned the new value. Now set the parent links image if applicable
						
						//The following sets the active image for the ** parentNode ** of the current active page's link.
						//Initially developed for J4Ki so the link that matches the current page's URL ~AND~ the top level 
						//main menu link both have a active page indicator showing.
						
						//The number of parentNode entries required will vary based upon each site design.
						var parentObjForChange=itemForChange[j].parentNode.parentNode.parentNode.parentNode;
						//Checks to see if the parent object is a top level main menu entry by checking its id
						if(parentObjForChange.id.indexOf("mmenu")==0){
							movImg=document.getElementById(parentObjForChange.id).getElementsByTagName("img");
							//The index number will depend on how many images are within the movImg object. 
							//In this case there is only one image.
							movImgId=document.getElementById(movImg[0].id);
							var parentImgURLString=String(movImgId.src);
							parentImgURLPart01=parentImgURLString.slice(0,parentImgURLString.lastIndexOf("."));
							parentImgURLPart03=parentImgURLString.slice(parentImgURLString.lastIndexOf("."));
							movImgId.src=(parentImgURLPart01+activeImgSuffix+parentImgURLPart03);
						}
		
						break;
					}else{
						if((j+1)==itemForChange.length){
							//no corresponding id to link id found AND reached last array entry;
							break;
						}else{
							//no corresponding id to link id found, continue to next array entry;
							continue;
						}
					}
				}
			}else if(imageOrStyle=='s'){
				//implements if changing a element's style;
				for(j=0;j<=itemForChange.length;j++){
					//Checks to see that the Link's ID is within the itemForChange's ID && then assures that the match was not in error due to a docLink not having an ID; 
					if((docLinks[i].id.indexOf(itemForChange[j].id)==0)&&(docLinks[i].id!="")&&(itemForChange[j].id!="")){
						eval('document.getElementById(itemForChange[j].id).style.'+styleToChange+'="'+newStyleValue+'"');
						//found a match and assigned the new value. goodbye :-)
						break;
					}else{
						if((j+1)==itemForChange.length){
							//no corresponding id to link id found AND reached last array entry;
							break;
						}else{
							//no corresponding id to link id found, continue to next array entry;
							continue;
						}
					}
				}
			}
		}else{
			continue;
		}
	}
//END: ESTABLISHES CURRENT PAGE'S "ACTIVE" MENU IMAGE;
}

