/* define variables for "if n4 (Netscape 4), if IE (IE 4.x), 
and if n6 (if Netscape 6/W3C-DOM compliant)" */



/* detecting browser support for key objects/methods and 
assembling a custom document object */


/* document.layers detects Netscape 4.* */
/* document.all works for IE */
/* document. GetElementById() works for W3C DOM compliant browsers 
(Netscape 6 and 7 and future ones */

/* Probably "no sane person" uses Netscape 4.7 anymore, but we have it there so not to mess other sections of
the code. I plan to take it out */

var n4, ie, n6;

var doc,doc2,doc3,sty;

if (document.layers) {
  doc = "document.";
  doc2 = ".document.";
  doc3 = "";
  sty = "";
  n4 = true;
  }
else if (document.all) {
  doc = "document.all.";
  doc2 = "";
  doc3 = "";
  sty = ".style";
  ie = true;
}

else if (document.getElementById) {
  doc = "document.getElementById('";
  doc2 ="')";
  doc3 ="')";
  sty = "').style";
  n6 = "true";
 } 
 
 

// the variables for the window dimensions
// getting the width and the height; and then the center
// Netscape does it differently so... two arguments: innerWidth, etc / document.body.client.Width for IE.



var win_width,win_height;
var centerhor, centerver;


//Get dimensions of the window
function dimensions() {
if(n4 || n6){
 win_width=window.innerWidth;
 win_height=window.innerHeight;
}

else if(ie) {
  win_width=document.body.clientWidth;
  win_height=document.body.clientHeight;
     }

centerhor = win_width/2;
centerver = win_height/2;
}






// position the element on the page: three arguments: element (elem) which is the id of the element to be positioned,
// the LEFT and the TOP position of the element
// Again different for Netscape than for IE (Sometimes I hate both of them)


function placeIt(elem,leftPos,topPos) {
docObj = eval(doc + elem + sty);
if (n4 || n6) {
docObj.left = leftPos;
docObj.top= topPos;
 }
if (ie) {
docObj.pixelLeft = leftPos;
docObj.pixelTop = topPos;
 }
}



// preload navigation images

// This could be improved using and Array but it works fine this way also.
// Just uploaded the images with their names. The navdir variable save us some time.



var loaded = 0;
var navdir = "imgs/navigation/";

function preload() {
top_home_off = new Image;
top_home_off.src = navdir + "home-off.jpg";
top_home_on = new Image;
top_home_on.src = navdir + "home-on.jpg";


top_donate_off = new Image;
top_donate_off.src = navdir + "donate-off.jpg";

top_donate_on = new Image;
top_donate_on.src = navdir + "donate-on.jpg";





top_primera_off = new Image;
top_primera_off.src = navdir + "aboutUs-off.jpg";

top_primera_on = new Image;
top_primera_on.src = navdir + "aboutUs-on.jpg";




top_segunda_off = new Image;
top_segunda_off.src = navdir + "worship-off.jpg";

top_segunda_on = new Image;
top_segunda_on.src = navdir + "worship-on.jpg";



top_tercera_off = new Image;
top_tercera_off.src = navdir + "education-off.jpg";

top_tercera_on = new Image;
top_tercera_on.src = navdir + "education-on.jpg";



top_cuarta_off = new Image;
top_cuarta_off.src = navdir + "community-off.jpg";

top_cuarta_on = new Image;
top_cuarta_on.src = navdir + "community-on.jpg";


top_quinta_off = new Image;
top_quinta_off.src = navdir + "news-off.jpg";

top_quinta_on = new Image;
top_quinta_on.src = navdir + "news-on.jpg";



top_sexta_off = new Image;
top_sexta_off.src = navdir + "contactUs-off.jpg";

top_sexta_on = new Image;
top_sexta_on.src = navdir + "contactUs-on.jpg";






loaded = 1;
}






// img src swap function
function onoff (elemparent,elem,state) {
if (loaded) {
newstate = eval(elem+"_"+state);
if (n4) {
menuObj = eval (doc + elemparent + doc2 + elem);
 }
else if (ie || n6) {
menuObj = eval (doc + elem + doc2);
 }
menuObj.src = newstate.src;
 }
}


// mouse over (on) and mouseoff(off) color values

// D8BFE9  




var oncolor = "#7FC290";
var offcolor = "#FFB815";

function changecolor(divname,colorname) {
stopall();
if (!n4) {
menuObj = eval(doc + divname + sty);
menuObj.backgroundColor = colorname;
  }
}

// show or hide DIV element
function showhide(divname,state) {
if (n4) {
divObj = eval (doc + divname);
 }
else {
divObj = eval (doc + divname + sty);
}
divObj.visibility = state;
}








// variables that hold the value of the currently active (open) menu
var active_submenu1 = null;
var active_submenu2 = null;
var active_menuelem = null;
var active_topelem = null;

// function closes all active menus and turns back to 'off' state
function closeallmenus() {
if(active_submenu1 != null) {
  showhide(active_submenu1,'hidden');
  }
if(active_submenu2 != null) {
  showhide(active_submenu2,'hidden');
  }
if(active_menuelem != null) {
  changecolor(active_menuelem,offcolor);
  }
if(active_topelem != null) {
  onoff('mainmenu',active_topelem,'off');
  }
}

// the menu close timeout variable
var menu_close_timeout = 0;

// delay in miliseconds until the open menus are closed
var delay = 1500;

// function calls the closeallmenus() function after a delay
function closeall() {
menu_close_timeout = setTimeout('closeallmenus()',delay);
}

// stop all timeout functions (stops menus from closing)
function stopall() {
clearTimeout(menu_close_timeout);
}

// function controls submenus 
function controlsubmenu(submenu1,submenu2,menuelem,topelem) {
stopall();
closeallmenus();
if (submenu1 != null) {
  showhide(submenu1,'visible');
  active_submenu1 = submenu1;
  }
if (submenu2 != null) {
 showhide(submenu2,'visible');
 active_submenu2 = submenu2;
  }
if (menuelem != null) {
 changecolor(menuelem,oncolor);
 active_menuelem = menuelem;
 }
if (topelem != null) {
 onoff('mainmenu',topelem,'on');
 active_topelem = topelem;
 }
}


function initialize() {
preload();
closeallmenus();
stopall();
dimensions();
if (win_width < 800) {
mainmenuleft = centerhor  -400;        //-315
 }
else {
mainmenuleft = centerhor - 378;			// -285
     }
offset = 1     
offset1 = 105; 						// the width of the previous + a border
offset2 = 105; 
offset3 = 105;
offset4 = 105;
offset5 = 104;
offset6 = 104;

// the number is the top position which must be related  to the mainmenu position

placeIt('mainmenu',mainmenuleft,76);   // 120
placeIt('primera',mainmenuleft + offset,112);              // 126 number is the vertical distance
placeIt('segunda',mainmenuleft + + offset + offset1,112);
placeIt('tercera',mainmenuleft +offset +offset1+offset2,112);
placeIt('cuarta',mainmenuleft +offset +offset1+offset2+offset3,112);
placeIt('quinta',mainmenuleft + offset +offset1+offset2+offset3+offset4,112);


placeIt('sexta',mainmenuleft + offset +offset1+offset2+offset3+offset4+offset5,112);







// We have left the variables for a sub-sub menu even when we are not using one for SHIR TIKVAH (yet)


}
