



/********** tell a friend *************/
window.form_friend_options = {
	duration:		700,
	transition:		Fx.Transitions.Cubic.easeOut,
	transition_types:	['morph', 'fade'], // morph, fade
	overlay:		{ color: '#000000', opacity: 0.5, close_on_click: false }
};


/********** optin *************/
window.form_subscribe_options = {
	duration:		700,
	transition:		Fx.Transitions.Cubic.easeOut,
	transition_types:	['morph', 'fade'], // morph, fade
	overlay:		{ color: '#000000', opacity: 0.5, close_on_click: true }
};

/******** gallery **********/
window.gallery_options = {
	overlay: 	{ color: '#000000', opacity: 0.5, close_on_click: false },
	background: 	'#2F2F2F',
	fontcolor:	'#ffffff',
	border:		'solid gray 1px',
	padding:	'10px',
	image_dir:	'gallery-dark',
	fade_duration:	500,
	morph_duration:	400,
	enable_slideshow: true,
	slideshow_delay: 7000
};



window.addEvent('domready', function() {
	initMenu();

	// handle navlinkhover boxes
	$$('div.navlinkbox').each(function(el) {
		el.addEvent('mouseover', function() {
			this.addClass('navlinkboxhover');
		});
		el.addEvent('mouseout', function() {
			this.removeClass('navlinkboxhover');
		});
	});
});


// handle rollover images
window.addEvent('load', function() {
	var imgLst = document.getElementsByTagName('img');
	for(var i=0; i<imgLst.length; ++i) {
		if(imgLst[i].getAttribute('hover') == 'true') {
			var pimg = new Image(); pimg.src = imgLst[i].src.replace(/\.png/, '-over.png'); // preload hover image

			$(imgLst[i]).addEvent('mouseover', function() {
				this.src = this.src.replace(/\.png/, '-over.png');
			});
			$(imgLst[i]).addEvent('mouseout', function() {
				this.src = this.src.replace(/-over\.png/, '.png');
			});
		}
	}
});

// handle pngs with the alphapng="true" attribute
window.addEvent('domready', function() {
	if(document.all) {
		var lst = document.getElementsByTagName('img');
		for(var i=0; i<lst.length; ++i) {
			if(lst[i].getAttribute('alphapng')=='true') {
				lst[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale src='" + lst[i].src + "')";
				lst[i].src = "assets/images/xparent.png";
			}
		}
	}
});





function validate_contact(f) {
	var e = new Errors();
	if(!f.firstname.value) e.add("Please enter your first name.");
	if(!f.lastname.value) e.add("Please enter your last name.");
	if(!validate_email(f.email.value)) e.add("Sorry, Invalid Email Address!");
	//if(!f.address.value) e.add("Please enter your address.");
	//if(!f.city.value) e.add("Please enter your city.");
	//if(f.state.selectedIndex <= 0) e.add("Please select your state.");
	//if(!f.zip.value) e.add("Please enter your zip.");
	//if(f.country.selectedIndex <= 0) e.add("Please select your country.");
	//if(!f.comments.value) e.add("Please enter your comments.");

	return e.alert() ? false : true;
}













window._mainmenutimer;

function initMenu() {
	var tblmainmenu = $('mainmenu'); if(!tblmainmenu) return;
	var lst = tblmainmenu.getElementsByTagName('td');
	for(var i=0; i<lst.length; ++i) {
		var menuname = lst[i].id.substr(9);
		lst[i].setAttribute('menuname', menuname);


		lst[i].onmouseover = function() {
			clearHideSubMenusTimer();
			showSubMenu(this.getAttribute('menuname'));
		}

		lst[i].onmouseout = function() {
			startHideSubMenus();
		}
	}

	var lst = $$('div.submenu');
	for(var i=0; i<lst.length; ++i) {
		sdiv = lst[i];

		sdiv.onmouseover = function() {
			clearHideSubMenusTimer();
		}
		sdiv.onmouseout = function() {
			startHideSubMenus();
		}


		var items = sdiv.getElementsByTagName('td');
		for(var z=0; z<items.length; ++z) {
			items[z].onmouseover = function() {

				var lst = this.parentNode.parentNode.getElementsByTagName('td');
				for(var i=0; i<lst.length; ++i) {
					doHideSubMenu(lst[i].getAttribute('showsubmenu'));
				}


				this.className = 'hover';
				showSubSubMenu(this);
			}
			items[z].onmouseout = function() {
				this.className = '';

			}

			try {
				items[z].childNodes[0].onclick = function() {
					return false;
				}
			} catch(e) {}
			
			items[z].onclick = function() {
				try {
					var t = ( this.childNodes[0].getAttribute('target') ) ? this.childNodes[0].getAttribute('target') : '_self';
					window.open(this.childNodes[0].getAttribute('href'), t);
				} catch(e) {}
			}
		}
	}

}



function showSubSubMenu(that) {
	var menuname = that.getAttribute('showsubmenu');

	that = $(that);
	var div = that;
	while(div.tagName != 'DIV') {
		div = div.parentNode;
	}

	var sub = $('submenu-'+menuname);
	if(!sub) return;


	sub.style.top = ( that.getTop() - 4 ) + 'px';
	sub.style.left = ( div.getLeft() + div.offsetWidth ) + 'px';
	sub.style.display = 'block';
	
}


function showSubMenu(menuname) {
	hideAllSubMenus();

	var m = $('mainmenu-'+menuname);
	if(!m) return;

	var sub = $('submenu-'+menuname);
	if(sub) {

		var o = (navigator.appName.indexOf('Microsoft') != -1) ? 7 : 4;

		sub.style.top = ( m.getTop() + m.offsetHeight ) + 'px';
		sub.style.left = ( m.getLeft() ) + 'px';
		sub.style.display = 'block';
		//sub.style.top = ( m.getTop()  - sub.offsetHeight - o ) + 'px';
	}

}


function hideAllSubMenus() {
	clearHideSubMenusTimer();

	var tblmainmenu = $('mainmenu');

	//var lst = tblmainmenu.getElementsByTagName('td');
	//for(var i=0; i<lst.length; ++i) {
	//	doHideSubMenu( lst[i].id.substr(9) );
	//}


	var lst = $$('div.submenu');
	for(var i=0; i<lst.length; ++i) {
		doHideSubMenu( lst[i].id.substr(8) );
	}
}


function startHideSubMenus() {
	clearHideSubMenusTimer();
	window._mainmenutimer = setTimeout('hideAllSubMenus();', 1000);
}


function clearHideSubMenusTimer() {
	clearTimeout(window._mainmenutimer);
}

function doHideSubMenu(menuname) {
	var s = $('submenu-'+menuname);
	if(s) s.style.display = 'none';
}

function test(v) {
	try {
		console.log(v);
	} catch(e) {};
}




