

window._slideShowDelay = 5000;
window._slideShowTransitionDuration = 1500;


/********** 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: 	'#ffffff',
	fontcolor:	'#2F2F2F',
	border:		'solid gray 1px',
	padding:	'10px',
	image_dir:	'gallery-light',
	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;
}






function initMenu() {
	var div = $('mainmenu');
	if(!div) return;

	$$('div#mainmenu div.menuitem').each(function(el) {
		if(el.getAttribute('showmenu')) {
			el.addEvent('click', function() {
				return ( expandMenu(this.getAttribute('showmenu').toInt()) ) ? false : true;
			});
		}
	});

}


function expandMenu(menuid) {
	div = $('submenu-'+menuid);
	if(!div) return false;

	var menuitemcount = $$('div#'+div.id+' div.menuitem').length;
	if(!menuitemcount) return false;

	var duration = menuitemcount * 80;

	if(div.getStyle('display') == 'none') {

		$$('div#mainmenu div.submenu').each(function(el) {
			if(el == div) return;
			if($(el).getStyle('display') == 'none') return;

			var id = el.id.substring( el.id.indexOf('-')+1 ).toString();
			if(id) contractMenu(el);
		});

		div.setStyles({
			overflow: 'hidden',
			height: 1,
			opacity: 0,
			display: 'block'
		});

		new Fx.Tween(div, {
			duration: duration,
			onComplete: function() {
				new Fx.Tween(div, {
					duration: duration
				}).start('opacity', 1);
			}
		}).start('height', div.getScrollSize().y);

	} else {
		contractMenu(div);
	}

	return true;
}



function contractMenu(div, chain) {
	div = $(div);
	if(!div) return;

	if(div.getStyle('display') == 'none') return;


	var menuitemcount = $$('div#'+div.id+' div.menuitem').length;
	if(!menuitemcount) return false;

	var duration = menuitemcount * 80;

	div.setStyles({
		overflow: 'hidden'
	});

	new Fx.Tween(div, {
		duration: duration,
		onComplete: function() {
			new Fx.Tween(this.element, {
				duration: duration,
				onComplete: function() {
					this.element.setStyle('display', 'none');
				}
			}).start('height', 1);
		}
	}).start('opacity', 0);
}



function startSlideShow(slideShowImg, imgs) {
	slideShowImg = $(slideShowImg);
	if(!slideShowImg) return;
	if(!imgs.length) return;

	var i = slideShowImg.clone();
	i.id = '_slideShowImgClone';
	i.setStyles({
		display: 'none',
		position: 'absolute',
		'z-index': 99
	});
	i.injectBefore(slideShowImg);

	window._slideShowImg = slideShowImg;
	window._slideShowImgClone = i;
	window._slideShowImages = imgs;
	window._slideShowIndex = 0;


	for(var i=0; i<window._slideShowImages.length; ++i) {
		var n = new Image();
		n.src = window._slideShowImages[i];
	}

	setTimeout(slideShowGo, window._slideShowDelay);
}

function slideShowGo() {
	if(++window._slideShowIndex >= window._slideShowImages.length) window._slideShowIndex = 0;

	var img = window._slideShowImg;
	var clone = window._slideShowImgClone;

	curImg = window._slideShowImages[window._slideShowIndex];
	clone.src = curImg;

	clone.setStyles({
		opacity: 0,
		display: 'block'
	});

	new Fx.Tween(clone, {
		duration: window._slideShowTransitionDuration,
		onComplete: function() {
			img.src = clone.src;
			clone.setStyle('display', 'none');
			setTimeout(slideShowGo, window._slideShowDelay);
		}
	}).start('opacity', 1);

}


//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';
//}


