/**** Control drop shadow header ****/

function MakeDropShadow() {
  
    var node = document;
    var tag = '*';
    var wantedClass = 'dropshadow';

    // Build a regular expression that will search specically for 'wantedClass'
    var pattern = new RegExp("(^|\\s)"+wantedClass+"(\\s|$)");

    // Scan through all tag elements in the document
    var scan_elem = node.getElementsByTagName(tag);
    for (i = 0; i < scan_elem.length; i++) {

      // If element has a class of 'wantedClass'
      if (pattern.test(scan_elem[i].className) ) {

        // Get the value from the element
        var text_value = scan_elem[i].innerHTML; 

        // Create Shadow Children for this element
        CreateShadowChildren(scan_elem[i],text_value);
     }
   } // End for loop
}
  
function CreateShadowChildren(shadow_element,shadow_value) {   
  
   var left_pos = 1; // Initial shadow position X
   var top_pos = 1;  // Initial shadow position Y
   var left_inc = 1;
   var top_inc = 1;
   var starting_color = '00'; // Assign starting color (in Hex notation) for the Red, Green, and Blue
//   var starting_color = '44';
   var max_shadows = 2; // Max number of shadow elements to create. Should never be larger than the Z-Index value of dropshadow class.
  
  
   // Components (except for 00, when they all have the same value you will alwys get a gray color).
   // For lighter shadows start with a "lighter" color of 66, 77, 88 99, aa, bb, etc.
   var cRed = parseInt(starting_color,'16');
   var cGreen = parseInt(starting_color,'16');
   var cBlue = parseInt(starting_color,'16');

   // Calculate color increament based on range of gray colors (from starting_color to
   // the lighest gray color of #fefefe) and max number of shadows you want
   var color_inc =  parseInt(( parseInt('fe','16') - parseInt(starting_color,'16') ) / max_shadows,'10');

   for (j = 1; j <= max_shadows; j++) {

   // Build full color Hex string from it's individual RGB values
   var full_color_value = cRed.toString(16) + cGreen.toString(16) + cBlue.toString(16);

   // Create a Shadow DIV
   var shadow_div = document.createElement('div');

   //  Add the shadow_value to Shadow DIV
   shadow_div.innerHTML = shadow_value;

   // Style Shadow DIV
   shadow_div.style.width=shadow_element.offsetWidth + "px";
   shadow_div.style.color = '#' + full_color_value;
   shadow_div.style.borderColor = '#' + full_color_value;
   shadow_div.style.display = "block";
   shadow_div.style.position = "absolute";
   shadow_div.style.top = top_pos + "px";
   shadow_div.style.left = left_pos + "px";
   shadow_div.style.zIndex = (-1) * j;

   // Apppend Shadow DIV to shadow element   
   shadow_element.appendChild(shadow_div);   

   // Increment positons and shadows individual RGB color values   
   left_pos += left_inc;
   top_pos += top_inc;
   cRed += color_inc;
   cGreen += color_inc;
   cBlue += color_inc;
   }
}

/* Nav control */

var activeSub=0;
var SubNum=0;

/* Main nav rollover color */
//var sColorBkgndRollover = "#000000";
var sColorTextRollover = "#FFFFFF";
var sColorTextOrig = "#000000";

function reDo(){ window.location.reload() }
window.onresize = reDo;

    //Define global variables

	    var timerID = null;
		var timerOn = false;
		var timecount = 1000;
		var what = null;
		var newbrowser = true;
		var check = false;

    	function initnav(){
    	//  alert ("Running Init");
          if (document.layers) {
                      //  alert ("Running Netscape 4");
                        layerRef="document.layers";
                        styleSwitch="";
                        visibleVar="show";
			screenSize = window.innerWidth;
			what ="ns4";


          }else if(document.all){
                      //  alert ("Running IE");
                        layerRef="document.all";
                        styleSwitch=".style";
                        visibleVar="visible";
			screenSize = document.body.clientWidth + 18;
			what ="ie";

		  }else if(document.getElementById){
                      //  alert ("Running Netscape 6");
                        layerRef="document.getElementByID";
                        styleSwitch=".style";
                        visibleVar="visible";
			what="moz";

		  }else{
		  	//alert("Older than 4.0 browser.");
			what="none";
			newbrowser = false;
		  }


		window.status='status bar text to go here';
		check = true;
  	 	}

	// Turns the layers on and off
        function showLayer(layerName){
        	if(check){
        		if (what =="none"){
        			return;
        			}
	        	else if (what == "moz"){
        			document.getElementById(layerName).style.visibility="visible";
                        var oElem = document.getElementById(layerName + "A");
                        if(oElem){
                           //oElem.style.backgroundColor = sColorBkgndRollover;
                           oElem.style.color = sColorTextRollover;
                           }
        			}
        		else{
                  eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"');
                  var sElemA = layerRef+'["'+layerName+'A"]';
                  var sElemAFS = sElemA + styleSwitch;
                  if(eval(sElemA)){
                     //eval(sElemAFS+'.backgroundColor="'+sColorBkgndRollover+'"');
                     eval(sElemAFS+'.color="'+sColorTextRollover+'"');
                     }
                  }
		 }
        	else {// alert ("Please wait for the page to finish loading.");
        		return;}
		}

        function hideLayer(layerName){
        	if(check){
        		if (what =="none"){
        			return;
        			}
        		else if (what == "moz"){
        			document.getElementById(layerName).style.visibility="hidden";
                        var oElem = document.getElementById(layerName + "A");
                        if(oElem){
                           //oElem.style.backgroundColor = "";
                           oElem.style.color = sColorTextOrig;
                           }
        			}
        		else{
                  eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"');
                  var sElemA = layerRef+'["'+layerName+'A"]';
                  var sElemAFS = sElemA + styleSwitch;
                  if(eval(sElemA)){
                     //eval(sElemAFS+'.backgroundColor=""');
                     eval(sElemAFS+'.color="'+sColorTextOrig+'"');
                     }
				}
        	}
        	else {// alert ("Please wait for the page to finish loading.");
        		return;}
        }

		function hideAll(){
				hideLayer('OC');
				hideLayer('OS');
				hideLayer('SC');
				hideLayer('US');
				hideLayer('CD');
				}

		function startTime() {
	        if (timerOn == false) {
                timerID=setTimeout( "hideAll()" , timecount);
                timerOn = true;

	        }
		}

		function stopTime() {
	        if (timerOn) {
    	        clearTimeout(timerID);
                timerID = null;
                timerOn = false;
	        }
		}

		function onLoad(){
			initnav();
			}

/* Load functions */

addDOMLoadEvent = (function() {

   // create event function stack
   var load_events = [],
      load_timer,
      script,
      done,
      exec,
      old_onload,
      init = function () {
         done = true;

         // kill the timer
         clearInterval(load_timer);

         // execute each function in the stack in the order they were added
         while (exec = load_events.shift()) exec();
         if (script) script.onreadystatechange = '';
      };

   return function (func) {
      // if the init function was already ran, just run this function now and stop
      if (done) return func();

      if (!load_events[0]) {
         // for Mozilla/Opera9
         if (document.addEventListener) document.addEventListener("DOMContentLoaded", init, false);

         // for Internet Explorer
         /*@cc_on @*/
         /*@if (@_win32)
            document.write("<script id=__ie_onload defer src=unsaved://0><\/scr"+"ipt>");
            script = document.getElementById("__ie_onload");
            script.onreadystatechange = function() {
               if (this.readyState == "complete") init(); // call the onload handler
            };
            /*@end @*/

            // for Safari
            if (/WebKit/i.test(navigator.userAgent)) { // sniff
               load_timer = setInterval(function() {
                  if (/loaded|complete/.test(document.readyState)) init(); // call the onload handler
               }, 10);
            }

            // for other browsers set the window.onload, but also execute the old window.onload
            old_onload = window.onload;
            window.onload = function() {
               init();
               if (old_onload) old_onload();
            };
      }

      load_events.push(func);
   }
})();

function fnCountPageClicks(nIndCat) {
    var pauseMS = 500; // Looks like we need to take a breath before navigating to selected link
    var scriptsURL = "http://www.meridiansite.com/Scripts/DoPageAccessCount.asp?id=" + nIndCat;
    var xmlHTTP;

    if (window.XMLHttpRequest) xmlHTTP = new XMLHttpRequest(); // IE7+, Firefox, Chrome, Opera, Safari
    else if (window.ActiveXObject) xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP"); // IE6, IE5
    else return;

    // Communication with the server is unilateral. The response is superfluous and discarded.
    with(xmlHTTP) {
        open("GET", scriptsURL, true);
        send(null);
    }

    // Impart delay before navigating away from this page.
    var now = new Date();
    var stopTime = now.getTime() + pauseMS;
    while(now.getTime() < stopTime) now = new Date();
}

addDOMLoadEvent(MakeDropShadow);
addDOMLoadEvent(initnav);
