if (document.images) {
	// Create image objects and preload images

	btn_tobaccomart_on = new Image();
	btn_tobaccomart_on.src = "images/btn_tobaccomart_on.gif";
	
	btn_tobaccomart_off = new Image();
	btn_tobaccomart_off.src = "images/btn_tobaccomart_off.gif";

	btn_chicksncigars_on = new Image();
	btn_chicksncigars_on.src = "images/btn_chicksncigars_on.gif";
	
	btn_chicksncigars_off = new Image();
	btn_chicksncigars_off.src = "images/btn_chicksncigars_off.gif";

	btn_winter_on = new Image();
	btn_winter_on.src = "images/btn_winter_on.gif";
	
	btn_winter_off = new Image();
	btn_winter_off.src = "images/btn_winter_off.gif";

	btn_cigarshops_on = new Image();
	btn_cigarshops_on.src = "images/btn_cigarshops_on.gif";
	
	btn_cigarshops_off = new Image();
	btn_cigarshops_off.src = "images/btn_cigarshops_off.gif";

	btn_humidor_on = new Image();
	btn_humidor_on.src = "images/btn_humidor_on.gif";
	
	btn_humidor_off = new Image();
	btn_humidor_off.src = "images/btn_humidor_off.gif";
	
	btn_depts_on = new Image();
	btn_depts_on.src = "images/btn_depts_on.gif";
	
	btn_depts_off = new Image();
	btn_depts_off.src = "images/btn_depts_off.gif";
	
	btn_advertisers_on = new Image();
	btn_advertisers_on.src = "images/btn_advertisers_on.gif";
	
	btn_advertisers_off = new Image();
	btn_advertisers_off.src = "images/btn_advertisers_off.gif";

//tonnav
	btn_login_on = new Image();
	btn_login_on.src = "images/btn_login_on.gif";
	
	btn_login_off = new Image();
	btn_login_off.src = "images/btn_login_off.gif";

	btn_viewcart_on = new Image();
	btn_viewcart_on.src = "images/btn_viewcart_on.gif";
	
	btn_viewcart_off = new Image();
	btn_viewcart_off.src = "images/btn_viewcart_off.gif";

	btn_checkout_on = new Image();
	btn_checkout_on.src = "images/btn_checkout_on.gif";
	
	btn_checkout_off = new Image();
	btn_checkout_off.src = "images/btn_checkout_off.gif";	

	btn_contact_on = new Image();
	btn_contact_on.src = "images/btn_contact_on.gif";
	
	btn_contact_off = new Image();
	btn_contact_off.src = "images/btn_contact_off.gif";
	

}

var button_hilighted  = false;
var default_hilighted = false;
var menu_visible      = false;
var menu_timer        = false;
var menu_delay        = 300;

var menu_offset_ie_x  = 143;
var menu_offset_wie_x = 153;
var menu_offset_ns_x  = 153;
var menu_offset_ie_y  = 20;
var menu_offset_wie_y = 0;
var menu_offset_ns_y  = 0;
var menu_offset_moz_x = 153;
var menu_offset_moz_y = 0;

var placeholder_x, placeholder_y = 0;


function button_over(b) {
  stop_everything();
  if(menu_visible) {
    hide_menu(menu_visible);
  }
  restore_default(false);
  hi_button(b);
  align_menu(b);
  show_menu(b);
}

function button_out(b) {
  lo_button(b);
  delay_hide_menu(b);
}

function menu_over(b) {
  stop_everything();
  hi_button(b);
}

function menu_out(b) {
  delay_hide_menu(b);
}

function icon_out(i) {
  lo_button(i);
  restore_default(true);
}

function hi_button(b) {
  hi_img("btn_"+b);
  button_hilighted = b;
}

function home_button(b) {
  home_img("btn_"+b);
}

function lo_button(b) {
  lo_img("btn_"+b);
  button_hilighted = false;
}

function delay_hide_menu(m) {
  stop_everything();
  menu_timer = setTimeout("hide_menu(\""+m+"\");", menu_delay);
}

function stop_everything() {
  if(menu_timer > 0) {
    clearTimeout(menu_timer);
    menu_timer = 0;
  }
}

function show_menu(m) {
  // hide any other menus that are visible
  if(menu_visible > 0) {
    hide_menu(menu_visible);
  }
  show_layer(m+"menu");
  menu_visible = m;
}

function hide_menu(m) {
  hide_layer(m+"menu");
  lo_button(m);
  menu_visible = false;
  restore_default(true);
}

function restore_default(d) {
  if(default_hilighted) {
    if(d) {
      home_button(default_hilighted);
    } else {
      lo_button(default_hilighted);
    }
  }
}

function align_menu(m) {
  if(document.getElementById) {
        var current = document.getElementById("btn_"+m);
    placeholder_x = 0;
    placeholder_y = 0;
    while(current.offsetParent != null) {
      placeholder_x += current.offsetLeft;
      placeholder_y += current.offsetTop;
      current = current.offsetParent;
    }
    if(navigator.userAgent.indexOf("Gecko") > 1) {
      placeholder_x += menu_offset_moz_x;
      placeholder_y += menu_offset_moz_y;
    } else if(navigator.appVersion.indexOf("Win") > 1) {
      placeholder_x += menu_offset_wie_x;
      placeholder_y += menu_offset_wie_y;
    } else {
      placeholder_x += menu_offset_ie_x;
      placeholder_y += menu_offset_ie_y;
    }
    var m = document.getElementById(m+"menu");
    m.style.left = placeholder_x;
    m.style.top = placeholder_y;
  } else if(document.all) {
    // need to get the location of the placeholder image
    var current = eval('document.images["btn_'+m+'"]');
    placeholder_x = 0;
    placeholder_y = 0;
    while(current.offsetParent != null) {
      placeholder_x += current.offsetLeft;
      placeholder_y += current.offsetTop;
      current = current.offsetParent;
    }
    // position the nav layer
    if(navigator.appVersion.indexOf("Win") > 1) {
      placeholder_x += menu_offset_wie_x;
      placeholder_y += menu_offset_wie_y;
    } else {
      placeholder_x += menu_offset_ie_x;
      placeholder_y += menu_offset_ie_y;
    }
    eval('document.all.'+m+'menu.style.left = '+placeholder_x);
    eval('document.all.'+m+'menu.style.top = '+placeholder_y);
  } else {
    placeholder_x = eval('document.layers["contentlayer"].document.images["btn_'+m+'"].x');
    placeholder_y = eval('document.layers["contentlayer"].document.images["btn_'+m+'"].y');
    placeholder_x += menu_offset_ns_x;
    placeholder_y += menu_offset_ns_y;
    eval('document.layers.'+m+'menu.moveTo(placeholder_x, placeholder_y)');
  }
}

function show_layer(l) {
  var tmp = '';
  if(document.getElementById) {
    document.getElementById(l).style.visibility = "visible";
  } else if(document.all) {
    tmp = 'all.'+l+'.style';
    eval('document.'+tmp+'.visibility="visible";');
  } else {
    tmp = l;
    eval('document.'+tmp+'.visibility="visible";');
  }
}

function hide_layer(l) {
  var tmp = '';
  if(document.getElementById) {
      document.getElementById(l).style.visibility = "hidden";
  } else if(document.all) {
    tmp = 'all.'+l+'.style';
    eval('document.'+tmp+'.visibility="hidden";');
  } else {
    tmp = l;
    eval('document.'+tmp+'.visibility="hidden";');
  }
}

function hi_img(i) {
  var newimg = eval(i+"_on.src");
  if(document.getElementById) {
    if(document.getElementById(i)) {
      document.getElementById(i).setAttribute("src",newimg);
    }
  } else if(document.all) {
    document.images[i].src = newimg;
  } else {
    document.layers["contentlayer"].document.images[i].src = newimg;
  }
}

function lo_img(i) {
  if(document.getElementById) {
    document.getElementById(i).setAttribute("src",eval(i+"_off.src"));
  } else if(document.all) {
    document[i].src = eval(i+"_off.src");
  } else {
    document.layers["contentlayer"].document.images[i].src = eval(i+"_off.src");
  }
}

function home_img(i) {
  if(document.getElementById) {
    document.getElementById(i).setAttribute("src",eval(i+"_home.src"));
  } else if(document.all) {
    document[i].src = eval(i+"_home.src");
  } else {
    document.layers["contentlayer"].document.images[i].src = eval(i+"_home.src");
  }
}
