//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Name: pspubnav.js
//Description: Creates navigation menus for public areas. 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Start Variables
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    var gtype = ".gif"                //Image Extention
    var ImagePath = "./images/nav/pspubnav/"  //Image Location
    var FooterImageName = "./images/nav/keyboard.jpg"          //Footer Image
    var FooterImageStyle= "width:118px;height:125px;background:gray;align:center" //Footer Image Styles
    var DisplayFooterImage = true     //Flag for hiding/showing footer image
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///End Variables
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///Location Settings
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (typeof (loc) == "undefined" || loc == "") {
    var loc = ""
    if (document.body && document.body.innerHTML) {
        var tt = document.body.innerHTML.toLowerCase();
        var last = tt.indexOf("pspubnav.js\"");
        if (last > 0) {
            var first = tt.lastIndexOf("\"", last);
            if (first > 0 && first < last) loc = document.body.innerHTML.substr(first + 1, last - first - 1);
        }
    }
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///End Location Settings
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Start Output of navigation table.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    document.write("<table border=\"0\" cellspacing=\"1\" cellpadding=\"1\"><tr>");     //Start Table & row
    tr(false);                                                                          //write </tr> End row
    //Start Button Creation
        writeButton(loc ,"default.asp","pspubnav_b1",120,22,"About","",0);                
        writeButton(loc ,"boards.asp","pspubnav_b2",120,22,"Association Sponsors","",0);
        writeButton(loc ,"districts.asp","pspubnav_b3",120,22,"School Districts","",0);
        writeButton(loc ,"parents.asp","pspubnav_b4",120,22,"Parents","",0);
        writeButton(loc ,"admin.asp","pspubnav_b5",120,22,"Admins Only","",0);
        writeButton(loc , "contact.asp", "pspubnav_b6", 120, 22, "Contact Information", "", 0);
        writeButton(loc , "learnmore.asp", "pspubnav_b7", 120, 22, "Learn More", "", 0);
    ///End Button Creation
    if (DisplayFooterImage) {                                                           //if DisplayFooterImage is true then:
        NavFooterImage(FooterImageName);                                                //Create Nav Footer Image
    }
    tr(true);                                                                           //write <tr> Start Row                    
    document.write("</tr></table>")                                                     ///End row and table
    loc="";                                                                        //reset loc variable
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///End Output of navigation table.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Start Function: NavFooterImage
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
///     Write <TR> or </TR>
/// </summary>
/// <param name="b"   type="boolean" > True start a row, False ends a row  </param>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    function NavFooterImage(imageName) {
        var _imgRow = "<tr><td>&nbsp</td></tr><tr><td><img style=\"" + FooterImageStyle + "\" src=\"" + imageName + "\" alt=\"Navigation Footer Image\"></td></tr>"
        document.write(_imgRow);        
    }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ///End Function: NavFooterImage
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Start Function: tr
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
///     Write <TR> or </TR>
/// </summary>
/// <param name="b"   type="boolean" > True start a row, False ends a row  </param>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    function tr(b){if (b) document.write("<tr>");else document.write("</tr>");}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///End Function: tr
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Start Function: turn_over 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
///     Replace img to create hover/click effects.
/// </summary>
/// <param name="name"   type="string" > Image Name  </param>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    function turn_over(name) {
	    if (document.images != null) {                          //If there are images on the page and clicked != name
		    document[name].src = document[name+"_over"].src;    //Replace with ImageName_over.src ( name_over.gif)
	    }
    }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///End Function: turn_over
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Start Function: reg 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
///     Replace img to create visual effect
/// </summary>
/// <param name="name"   type="string" > Image Name  </param>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    function turn_off(name) {
	    if (document.images != null) {                          //If there are images on the page and clicked != name
		    document[name].src = document[name+"_off"].src;     //Replace with ImageName_off.src ( name_off.gif)
	    }
    }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///End Function: reg
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Start Function: reg 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
///     Register 2 new images on document. ImageName_off & ImageName_over.
/// </summary>
/// <param name="gname"   type="string" > Image Name  </param>
/// <param name="name"    type="string" > Image Name  </param>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    function reg(gname,name)
    {
        if (document.images){                                            //If the document has images present.	    
	        document[name + "_off"] = new Image();                       //Register new image. name_off.gtype
	        document[name + "_off"].src = loc + ImagePath + gname + gtype;             //Set new image source = gname.gtype
	        document[name + "_over"] = new Image();                      //Register New image name_over
	        document[name + "_over"].src = loc + ImagePath + gname + "_over" + gtype; //Set new image source = name_over.gif
	    }
    	//Debug Helper:
    	//document.write("gname:" + gname + "<Br>name:" + name + "<br>gtype:" + gtype+"<Br>"+ "<br>loc:" + loc+"<Br>");
    }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///End Function: reg
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Start Function: evs 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
///     Register javascript events for onmouseover & onmouseout
/// </summary>
/// <param name="name"   type="string" > Element Name to add events too  </param>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    function evs(name){ return " onmouseover=\"turn_over('"+ name + "')\" onmouseout=\"turn_off('"+ name + "')\""}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///End Function: evs
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Start Function: writeButton 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
///     Writes formated Image Button.
/// </summary>
/// <param name="urld"   type="string" > Prefix for URL Target  </param>
/// <param name="url"    type="string" > URL target for button  </param>
/// <param name="name"   type="string" > Name of Button         </param>
/// <param name="w"      type="integer"> Width (optional)       </param>
/// <param name="h"      type="integer"> Height (optional       </param>
/// <param name="alt"    type="string" > Alt text (optional)    </param>
/// <param name="target" type="string" > Target (optional)      </param>
/// <param name="hsp"    type="integer"> Hspace (optional)      </param>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    function writeButton(urld, url, name, w, h, alt, target, hsp)
    {
	    gname = name;
	    while(typeof(document[name])!="undefined") name += "x";     //If object exists with same name add trailing spaces until unique
	    reg(gname, name);                                           //Register name_over.gif & name_off.gif images on document.
	    tr(true);                                                   //write <tr> for a new table row
	    document.write("<td>");                                     //write <td> for table collumn
	    if (alt != "") alt = " alt=\"" + alt + "\"";                //If alt is set then add that to the image button
	    if (target != "") target = " target=\"" + target + "\"";    //If target is set then add it to image button
	    if (w > 0) w = " width=\"" + w + "\""; else w = "";         //if width is set add it to the image button
	    if (h > 0) h = " height=\"" + h + "\""; else h = "";        //if height is set add it to the image button
	    if (url != "") url = " href=\"" + urld + url + "\"";        //if url is set add it to the image button with urld as prefix
	        	
	    document.write("<a " + url + evs(name) + target + ">");	    //Write a link with url, register onmouseover and onmouseout JS events, then add the target (if applicable)
    	
	    if (hsp == -1) hsp =" align=\"right\"";                     //if hsp is -1 then align the image to the right
	    else if (hsp > 0) hsp = " hspace=\""+hsp+"\"";              //If hsp > 0 set hspace = hsp
	    else hsp = "";                                              //else delete hsp
    	                                                    
    	                                                            //Write Image tag with afformentioned properties & end link and table collumn
	    document.write("<img src=\"" + loc + ImagePath + name + gtype + "\" name=\"" + name + "\"" + w + h + alt + hsp + " border=\"0\" /></a></td>"); 	   
	    tr(false);                                                  //Write </tr> to end table row
	    
	    //Debug Helper:
	    //document.write(    "<br>urld:  " + urld +"<br>url:   " + url  + "<br>name:  " + name + "<br>WxH    " + w + h  + "<br>alt:   " + alt  +"<br>target:" + target + "<br>hsp:   " + hsp );
    }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///End Function: writeButton 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
