// JavaScript Document
var browser
function getbrowser(){
	if (document.layers) {
		browser = 'ns4';
	}else if (document.getElementById && !document.all) {
		browser = 'moz';
	}else if(document.all){
		browser = 'ie';
	}
}
function img_over(img_name){
	document.images[img_name].src = images + "button_" + img_name + "_.gif";
	if (browser == 'ns4') return
	if (browser == 'moz'){
		buttons2 = document.getElementById("buttons2");
	}	
	if (buttons2.innerHTML != orig_buttons2_content){
		buttons2.innerHTML = orig_buttons2_content;
	}
}

function img_out(img_name){
	document.images[img_name].src = images + "button_" + img_name + ".gif";
}
var orig_buttons2_content
var timeon
var products = new Array();
var but = new Array();

but['products'] = new Array();
but['products'][0] = "<a class='buttons2' onMouseOver=\"DMmouseon('','cocopeat')\" onMouseOut=\"DMmouseout('','cocopeat')\" href='"+http_path+"level2_gro_pacific/coco_peat.php'>coir</a>";
but['products'][1] = "<a class='buttons2' href='"+http_path+"level2_gro_pacific/sphagnum_moss.php'>sphagnum moss</a>";
but['products'][2] = "<a class='buttons2' href='"+http_path+"level2_gro_pacific/aged_orchid_bark.php'>orchid bark</a>";
but['products'][3] = "<a class='buttons2' href='"+http_path+"level2_gro_pacific/hawaian_floral_mist.php'>floral mist</a>";
but['products'][4] = "<a class='buttons2' href='"+http_path+"level2_gro_pacific/specialised_mixes.php'>specialised mixes</a>";
but['products'][5] = "<a class='buttons2' href='"+http_path+"level2_gro_pacific/horticultural.php'>horticultural</a>";

orig_buttons2_content = "SUPPLYING ORGANIC HORTICULTURAL GROWING MEDIA&nbsp;";

if (but[page]){
	orig_buttons2_content = setup_menu_table(page);
}

function setup_menu_table(button_set){
	inner = "<table cellpadding=0 cellspacing=0 border=0><tr><td bgcolor='#CCCCCC'><img src='"+http_path+"images/spacer.gif' width=1></td>";
	for (button in but[button_set]) {
		inner += "<td onmouseover=\"cell_highlight(this)\" onmouseout=\"cell_unhighlight(this)\">&nbsp;";
		inner += but[button_set][button]
		inner += "&nbsp;</td>";
		inner += "<td bgcolor='#CCCCCC'><img src='"+http_path+"images/spacer.gif' width=1></td>"
	}
	inner += "</tr></table>";
	return inner;
}

function over(button_set){
	if (browser == 'ns4') return;
	clear_timer();	
	inner = setup_menu_table(button_set)
		
	if (browser == 'moz'){
		buttons2 = document.getElementById("buttons2");
	}
	buttons2.innerHTML = inner;
}

function reset_timer(){
	clear_timer()
	timeon = window.setTimeout("reset_content()",2000);
}
function clear_timer(){
	if (timeon){
		window.clearTimeout(timeon);
	}
}
function reset_content(){
	
	if (browser == 'moz'){
		buttons2 = document.getElementById("buttons2");
	}
	if (browser != 'ns4'){
		buttons2.innerHTML = orig_buttons2_content;
	}
	
}

function cell_highlight(cell){
	if (browser != 'ns4'){
		cell.style.backgroundColor = highlight
	}
}
function cell_unhighlight(cell){
	if (browser != 'ns4'){
		cell.style.backgroundColor = ''
	}
}

function init(){
	getbrowser();
	preload();
}

function preload(){
	img1 = new Image; img1.src = images + 'button_welcome_.gif'
	img2 = new Image; img2.src = images + 'button_products_.gif'
	img3 = new Image; img3.src = images + 'button_order_.gif'
	img4 = new Image; img4.src = images + 'button_about_us_.gif'
	img5 = new Image; img5.src = images + 'button_contact_us_.gif'
}


function getRealLeft(el) { 
	xPos = el.offsetLeft; tempEl = el.offsetParent; 
	while (tempEl != null) { xPos += tempEl.offsetLeft; 
		tempEl = tempEl.offsetParent; 
	} 
	return xPos; 
} 

function getRealTop(el) { 
	yPos = el.offsetTop; tempEl = el.offsetParent; 
	while (tempEl != null) { yPos += tempEl.offsetTop; 
		tempEl = tempEl.offsetParent; 
	} 
	return yPos; 
} 

//Assign the returned values to variables in this way: 

function return_positions(img) {
	if (browser == 'ie' || browser == 'moz') {
		trueX = getRealLeft(document.images[img]); 
		trueY = getRealTop(document.images[img]); 
	} else if (browser == 'ns4') {
		trueY = document.images[img].y;
		trueX = document.images[img].x;
	} else if (document.getElementById) {
		trueX =	document.images[img].offsetLeft;
		trueY = (document.images[img].offsetTop)+8;
	}
	pos = new Array();
	pos['x'] = trueX;
	pos['y'] = trueY;
	return pos;
}

// -- functions for drop menu

var menu_timer = new Array();
var menu_cell = "";
var highlight = '#EBEBEB';
var menu_status = new Array();
var browser;

function DMbrowser(){
	if (document.all){
		browser = 'ie'
	}else if (document.getElementById){
		browser = 'moz'
	}else if (document.layers){
		browser = 'ns4'
	}
	return browser
}
browser = DMbrowser()

function DMpersistent_highlight(cell){
	DMclose_all_subs()
	if (cell) {
		menu_cell = cell
	}
}
function DMmouseon(cell,submenu){
	
	clear_timer()
	if (browser != 'ns4' && cell){
		cell.style.backgroundColor = highlight;
	}
	if (submenu){
		DMsubmenu_on(submenu)
	} else {
		DMclose_all_subs()
	}
}
function DMmouseout(cell,submenu){
	reset_timer()
	if (browser != 'ns4' && menu_cell != cell && cell){
		cell.style.backgroundColor = ""
	}
	if (submenu){
		DMsubmenu_off(submenu)
	}
}

function DMmenu_div(div_name){
	if (browser == 'ie'){
		construct = document.all[div_name].style;
	}else if (browser == 'moz'){
		construct = document.getElementById(div_name).style
	}else if (browser == 'ns4'){
		construct = document.layers[div_name]
	}
	return construct
}
function DMsubClick(href){
	document.location.href = href
}
function DMsubmenu_on(menu){
	menu_status[menu] = 0;
	DMclose_all_subs();
	DMclear_timer(menu);
	menu_status[menu] = 1;
	pos = return_positions('welcome');
	DMmenu_div(menu).top = pos['y'] + 35
	DMmenu_div(menu).left = pos['x'] - 149
	DMmenu_div(menu).visibility = 'visible';
}
function DMsubmenu_off(menu){
	DMset_timer(menu)
}
function DMclose_menu(menu){
	DMmenu_div(menu).visibility = 'hidden';
	menu_status[menu] = 0;
	if (!document.layers && menu_cell) menu_cell.style.backgroundColor = "";
}
function DMset_timer(menu){
	menu_timer[menu] = setTimeout("DMclose_menu('"+menu+"')",1000)
}
function DMclear_timer(menu){
	if (menu_timer[menu]){
		clearTimeout(menu_timer[menu]);
	}
}
function DMclose_all_subs(){
	for (i in menu_status){
		if (menu_status[i] == 1) {
			DMclose_menu(i);
			DMclear_timer(i);
		}
	}
}
