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

var n4, ie, n6;

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


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
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.

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

var loaded = 0;
var navdir = "images/";

function preload() {
top_nah_off = new Image;
top_nah_off.src = navdir + "lsm_nah-off.gif";
top_nah_on = new Image;
top_nah_on.src = navdir + "lsm_nah-on.gif";

top_about_off = new Image;
top_about_off.src = navdir + "lsm_about_cspi-off.gif";
top_about_on = new Image;
top_about_on.src = navdir + "lsm_about_cspi-on.gif";

top_alcohol_off = new Image;
top_alcohol_off.src = navdir + "lsm_alcohol-off.gif";
top_alcohol_on = new Image;
top_alcohol_on.src = navdir + "lsm_alcohol-on.gif";

top_cspitv_off = new Image;
top_cspitv_off.src = navdir + "lsm_cspitv-off.gif";
top_cspitv_on = new Image;
top_cspitv_on.src = navdir + "lsm_cspitv-on.gif";

top_litigation_off = new Image;
top_litigation_off.src = navdir + "lsm_litigation-off.gif";
top_litigation_on = new Image;
top_litigation_on.src = navdir + "lsm_litigation-on.gif";

top_donate_off = new Image;
top_donate_off.src = navdir + "lsm_donate-off.gif";
top_donate_on = new Image;
top_donate_on.src = navdir + "lsm_donate-on.gif";

top_contact_off = new Image;
top_contact_off.src = navdir + "lsm_contact-off.gif";
top_contact_on = new Image;
top_contact_on.src = navdir + "lsm_contact-on.gif";

top_biotech_off = new Image;
top_biotech_off.src = navdir + "lsm_biotech-off.gif";
top_biotech_on = new Image;
top_biotech_on.src = navdir + "lsm_biotech-on.gif";

top_canada_off = new Image;
top_canada_off.src = navdir + "lsm_canada-off.gif";
top_canada_on = new Image;
top_canada_on.src = navdir + "lsm_canada-on.gif";

top_eating_off = new Image;
top_eating_off.src = navdir + "lsm_eating-off.gif";
top_eating_on = new Image;
top_eating_on.src = navdir + "lsm_eating-on.gif";

top_foodadd_off = new Image;
top_foodadd_off.src = navdir + "lsm_food_additives-off.gif";
top_foodadd_on = new Image;
top_foodadd_on.src = navdir + "lsm_food_additives-on.gif";

top_food_off = new Image;
top_food_off.src = navdir + "lsm_food_safety-off.gif";
top_food_on = new Image;
top_food_on.src = navdir + "lsm_food_safety-on.gif";

top_health_off = new Image;
top_health_off.src = navdir + "lsm_health_nut-off.gif";
top_health_on = new Image;
top_health_on.src = navdir + "lsm_health_nut-on.gif";

top_integrity_off = new Image;
top_integrity_off.src = navdir + "lsm_integrity-off.gif";
top_integrity_on = new Image;
top_integrity_on.src = navdir + "lsm_integrity-on.gif";

top_i12n_off = new Image;
top_i12n_off.src = navdir + "lsm_i12n-off.gif";
top_i12n_on = new Image;
top_i12n_on.src = navdir + "lsm_i12n-on.gif";

top_reports_off = new Image;
top_reports_off.src = navdir + "lsm_reports-off.gif";
top_reports_on = new Image;
top_reports_on.src = navdir + "lsm_reports-on.gif";

top_newsroom_off = new Image;
top_newsroom_off.src = navdir + "lsm_newsroom-off.gif";
top_newsroom_on = new Image;
top_newsroom_on.src = navdir + "lsm_newsroom-on.gif";

top_take_off = new Image;
top_take_off.src = navdir + "lsm_take_action-off.gif";
top_take_on = new Image;
top_take_on.src = navdir + "lsm_take_action-on.gif";

top_salt_off = new Image;
top_salt_off.src = navdir + "lsm_salt-off.gif";
top_salt_on = new Image;
top_salt_on.src = navdir + "lsm_salt-on.gif";

top_transfat_off = new Image;
top_transfat_off.src = navdir + "lsm_transfat-off.gif";
top_transfat_on = new Image;
top_transfat_on.src = navdir + "lsm_transfat-on.gif";

top_liquid_off = new Image;
top_liquid_off.src = navdir + "lsm_liquid-off.gif";
top_liquid_on = new Image;
top_liquid_on.src = navdir + "lsm_liquid-on.gif";

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
var oncolor = "#d4d5ea";
var offcolor = "#e1e2f1";

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 = 500;

// 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 < 770) {
// 80
// mainmenuleft = 165; // before 800x600 changes
mainmenuleft = 155;
 }
else {
// 50
mainmenuleft = centerhor - 218;
     }

var browser = new BrowserDetectLite();
var y_adjust=0;
var x_adjust=-11;
if ( browser.isGecko ) {
	y_adjust=-0;	// -7
	x_adjust=-20;	// was 12
}
if ( browser.isSafari ) {
	y_adjust=-0;	// -7
	x_adjust=-20;	// was 12
}
if ( browser.isOpera ) {
	y_adjust=+0;	// -7
	x_adjust=-12;
}

// adjusted -15 from earlier given topmargin=0

placeIt('nah',mainmenuleft + x_adjust, y_adjust + 110);			//125
// take action
placeIt('about',mainmenuleft + x_adjust, y_adjust + 160);		//229
// contact us
// cspi tv
placeIt('donate',mainmenuleft + x_adjust, y_adjust + 215);
placeIt('newsroom',mainmenuleft + x_adjust, y_adjust + 233); 	//175
placeIt('reports',mainmenuleft + x_adjust, y_adjust + 251);		//247
placeIt('alcohol',mainmenuleft + x_adjust, y_adjust + 269);		//157
placeIt('biotech',mainmenuleft + x_adjust, y_adjust + 288);	//301
// cspi in canada
placeIt('eating',mainmenuleft + x_adjust, y_adjust + 324);		//319
placeIt('food',mainmenuleft + x_adjust, y_adjust + 342);		
placeIt('integrity',mainmenuleft + x_adjust, y_adjust + 360);		//211
placeIt('i12n',mainmenuleft + x_adjust, y_adjust + 378);		//211
placeIt('litigation',mainmenuleft + x_adjust, y_adjust + 396);		//211
placeIt('health',mainmenuleft + x_adjust, y_adjust + 414);		//211
// placeIt('salt',mainmenuleft + x_adjust, y_adjust + 415);		//211
// placeIt('transfat',mainmenuleft + x_adjust, y_adjust + 425);		//211
// liquid candy
}
