jaxscript.run(function() {
	var Dt = dom.dimensions('topmenu');
	
	style.move('sub_aboutus',0, Dt.h+3);
	style.move('sub_product',dom.dimensions('product').x - Dt.x - 3, Dt.h+3);
	style.move('sub_gallery',dom.dimensions('gallery').x - Dt.x - 3, Dt.h+3);
	style.opacity('sub_aboutus',0);
	style.opacity('sub_product',0);
	style.opacity('sub_gallery',0);
	style.visible('sub_aboutus',true);
	style.visible('sub_product',true);
	style.visible('sub_gallery',true);
	
	selectDefaultMenu();
	
	var w = dom.id('topmenuwrap');
	dom.addEvent(w,'mouseout',function(e) {
		var s = dom.eventTarget(e);
		var t = dom.relatedTarget(e);
		if (s!=w) return;
		if (dom.isChild(t,s)) return;
		selectDefaultMenu();
	});
});

function selectDefaultMenu() {
	echo('selectDefaultMenu');
	if (hmenuDefaults.menu) {
		selectMenu(hmenuDefaults.menu);
		
		//alert(dom.id(hmenuDefaults.menu));
		
		dom.id(hmenuDefaults.menu).className = 'hselected';
		//echo(dom.id(hmenuDefaults.menu).id+' '+dom.id(hmenuDefaults.menu).className);
		
		var h = dom.id('hsubmenus');
		if (h.getElementsByTagName) {
			var a = h.getElementsByTagName('a');
			for (var i=0;i<a.length;i++) {
				var href = a[i].href;
				href = href.replace('http://'+location.host,'');
				if (href == hmenuDefaults.subMenu) {
					a[i].className = 'hsubselected';
					return;
				}
			}
		}
	}
}

function getHmenuDefaults() {
	var hmenus = {
		aboutus : ['/about.html','/inthenews.html','/product_literature.html','/warranty_info.html', '/warranty_info_cont.html','/contact.html'],
		product : ['/features.html','/yardistry_components.html','/clicknlock.html','/design_files.html'],
		gallery : ['/gallery.php','/gallery.php?section=screen','/gallery.php?section=structures','/gallery.php?section=fences','/gallery.php?section=sample'],
		customer : ['/customer_support.html']
	};
	var h,m,i;
	for (h in hmenus) {
		for (i=0;i<hmenus[h].length;i++) {
			var index = document.location.href.indexOf(hmenus[h][i]);
			if (index + hmenus[h][i].length == document.location.href.length) {
				return {
					menu : h,
					subMenu : hmenus[h][i]
				}
			}
		}
	}
	return {};
}
var hmenuDefaults = getHmenuDefaults();
echo('defaults are '+hmenuDefaults.menu+' '+hmenuDefaults.subMenu);

var selectedMenu = null;
var hmenus = ['aboutus','product','gallery','customer'];

function selectMenu(m) {
	
	for (var i=0;i<hmenus.length;i++) {
		//echo('menus = '+hmenus[i]+' '+m);
		if (m==hmenus[i]) {
			//echo('continue');
			continue;
		}
		
		var d = dom.id('sub_'+hmenus[i]);
		//echo('check '+hmenus[i]+' fadingIn='+d.fadingIn+' o='+style.getOpacity(d));
		
		if (style.getOpacity(d)!=0) {
			if (dom.id(hmenus[i]).className == 'hselected') dom.id(hmenus[i]).className = '';
			//echo('fading out '+d.id);
			fx.fadeOut(d,function() {
				d.fadingIn = false;
				//echo('DONE fading out '+d);
			});
		}
	}
	
	if (m!=null && selectedMenu != m) {
		var d = dom.id('sub_'+m);
		//echo('fading in '+m);
		selectedMenu = m;
		
		d.fadingIn = true;
		dom.id(m).className = 'hselected';
		style.maxZ(d);
		fx.fadeIn(d,function() {			
			d.fadingIn = false;
			//echo('DONE fading In '+m);
		});
	}
/*	if (selectedMenu == m) {
		var d = dom.id('sub_'+m);
		if (!d.fadingIn && 
	}*/
	
	if (m==null) selectedMenu = null;
}



PopoverWindow.defaults.scrolling = false;
PopoverWindow.setPath('./popoverwindow/');
var yardtheme = {"width":"436","height":"260","left":"","top":"","title":"","icon":"","showClose":false,"drag":false,"resize":false,"roundedCorners":true,"scrolling":false,"fadeIn":true,"fadeOut":true,"overlayClose":true,"titleFont":"sans-serif","titleSize":"9pt","titleWeight":"normal","titleColor":"000000","titlePadding":"0","windowColor":"000000","windowPadding":"0","pageBorderSize":"1","pageBorderColor":"000000","pageColor":"FFFFFF","overlayColor":"000000","overlayOpacity":"0.7"};

var houseon = new Image();
houseon.src = 'house-on.gif';
var emailon = new Image();
emailon.src = 'email-on.gif';
var houseoff = new Image();
houseoff.src = 'house.gif';
var emailoff = new Image();
emailoff.src = 'email.gif';

