



/********** 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
};


// init menu
window.addEvent('domready', function() {
	var mm = $('mainmenu');
	if(!mm) return;

	mm.getElements('td.menu-tab').each(function(el) {
		el.addEvent('mouseover', function() {
			this.addClass('menu-tab-on');

			if(this.hasClass('tab-0')) this.addClass('tab-0-on');
			else if(this.hasClass('tab-1')) this.addClass('tab-1-on');
			else if(this.hasClass('tab-2')) this.addClass('tab-2-on');
			else if(this.hasClass('tab-3')) this.addClass('tab-3-on');
			else if(this.hasClass('tab-4')) this.addClass('tab-4-on');
		});

		el.addEvent('mouseout', function() {
			this.removeClass('menu-tab-on');
			this.removeClass('tab-0-on');
			this.removeClass('tab-1-on');
			this.removeClass('tab-2-on');
			this.removeClass('tab-3-on');
			this.removeClass('tab-4-on');
			
		});

		if( el.getElement('a') ) {
			el.setStyle('cursor', 'pointer');

			el.addEvent('click', function() {
				document.forward(this.getElement('a').href);
			});

			el.getElement('a').addEvent('click', function() {
				this.parentNode.fireEvent('click');
				return false;
			});
		}
	});

//	$$('td.submenu-menuitem').each(function(el) {
//		el.addEvent('mouseover', function() {
//			showSubmenuDropdown(this);
//		});
//		el.addEvent('mouseout', function() {
//		showSubmenuDropdown(this);
//			hideSubmenuDropdown(this);
//		});
//	});
	initSubmenus();

	$$('div.select-region').each(function(el) {
		el.addEvent('click', function() {
			document.forward(this.getElement('a').href);
		});

		el.getElement('a').addEvent('click', function() {
			this.parentNode.fireEvent('click');
			return false;
		});

	});


	$$('div.submenu-dropdown td').each(function(el) {
		el.addEvent('mouseover', function() {
			this.addClass('over');
			clearSubmenuDropdownTimer();
		});

		el.addEvent('mouseout', function() {
			this.removeClass('over');
			startSubmenuDropdownTimer();
		});

		el.addEvent('click', function() {
			var a = this.getElement('a');
			if(a) window.open(a.href, a.getAttribute('target'));
		});
	});

	if($('divRegionSelectMenu')) {
		var t = $(document).getElement('div.submenu td.submenu-title');
		if(t) {
			t.addEvent('mouseover', function() {
				clearTimeout(window.__region_select_timer__);

				showRegionSelectMenu();

			});


			t.addEvent('mouseout', function() {
				clearTimeout(window.__region_select_timer__);
				window.__region_select_timer__ = setTimeout(function() {
					if($('divRegionSelectMenu').getAttribute('sticky') != 'true') hideRegionSelectMenu();
				}, 400);
			});

			$('divRegionSelectMenu').addEvent('mouseover', function() {
				clearTimeout(window.__region_select_timer__);
			});

			$('divRegionSelectMenu').addEvent('mouseout', function() {
				window.__region_select_timer__ = setTimeout(function() {
					if($('divRegionSelectMenu').getAttribute('sticky') != 'true') hideRegionSelectMenu();
				}, 400);
			});

		}
	}

});

function showRegionSelectMenu() {
	if(!$('divRegionSelectMenu')) return;
	if( $('divRegionSelectMenu').getStyle('display') == 'none' ) {
		$('divRegionSelectMenu').setStyles({
			'display': 'block',
			'opacity': 0
		});
		new Fx.Tween($('divRegionSelectMenu'), {
			duration: 300
		}).start('opacity', 0.94);
	}
}

function hideRegionSelectMenu() {
	if(!$('divRegionSelectMenu')) return;
	if( $('divRegionSelectMenu').getStyle('display') != 'none' ) {
		$('divRegionSelectMenu').setStyle('display', 'none');
	}
}

function toggleRegionSelectMenu() {
	if(!$('divRegionSelectMenu')) return;
	if( $('divRegionSelectMenu').getStyle('display') == 'none' ) {
		showRegionSelectMenu();
		return 1;
	}
	else {
		hideRegionSelectMenu();
		return 0;
	}
}

function toggleBranchMenu() {
	var div = $(document).getElement('div.submenu');
	if(!div) return;

	var td = null;
	var lst = div.getElements('td.submenu-menuitem');
	for(var i=0; i<lst.length; ++i) {
		var a = lst[i].getElement('a');
		if(a && a.href.indexOf('toggleBranchMenu') > -1) {
			td = lst[i];
			break;
		}
	}
	if(toggleRegionSelectMenu()) {
		if($('divRegionSelectMenu')) $('divRegionSelectMenu').setAttribute('sticky', 'true');
		if(td) td.addClass('on2');
	}
	else {
		if($('divRegionSelectMenu')) $('divRegionSelectMenu').setAttribute('sticky', 'false');
		if(td) td.removeClass('on2');
	}

	//test(td);
}


function showSubmenuDropdown(that) {
	doHideSubmenuDropdown();

	that.addClass('over');

	var dd = $(that.getAttribute('showmenu'));
	if(dd) {
		dd.store('trigger', that);
		dd.setStyles({
			'left': that.getLeft(),
			'display': 'block'
		});
	}
}

function hideSubmenuDropdown(that) {
	clearSubmenuDropdownTimer;
	var dd = $(that.getAttribute('showmenu'));
	if(dd) startSubmenuDropdownTimer();
	else that.removeClass('over');
}
function startSubmenuDropdownTimer() {
	window.__hideSubmenuDropdownTimer = setTimeout(doHideSubmenuDropdown, 1000);
}
function clearSubmenuDropdownTimer() {
	clearTimeout(window.__hideSubmenuDropdownTimer);
}
function doHideSubmenuDropdown() {
	clearSubmenuDropdownTimer();
	$$('div.submenu-dropdown').each(function(el) {
		el.setStyle('display', 'none');
		var t = el.retrieve('trigger');
		if(t) t.removeClass('over');
	});
}


window.addEvent('domready', function() {

	// 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 test(v) {
	try {
		console.log(v);
	} catch(e) {};
}














window._mainmenutimer;

function initSubmenus() {

	var div = $('submenu');
	var tblmainmenu = (div) ? div.getElement('table') : false;
	if(!tblmainmenu) return;

	var lst = tblmainmenu.getElements('td.submenu-menuitem');
	for(var i=0; i<lst.length; ++i) {
		var menuname = lst[i].id.substr(17);
		lst[i].setAttribute('menuname', menuname);

		lst[i].addEvent('mouseover', function() {
			this.addClass('over');
			clearHideSubMenusTimer();
			showSubMenu(this.getAttribute('menuname'));
		});

		lst[i].addEvent('mouseout', function() {
			//if(!$('submenu-dropdown-'+this.getAttribute('menuname'))) this.removeClass('over');
			this.removeClass('over');
			startHideSubMenus();
		});
	}

	var lst = $$('div.submenu-dropdown');
	for(var i=0; i<lst.length; ++i) {
		sdiv = $(lst[i]);

		sdiv.addEvent('mouseover', function() {
			clearHideSubMenusTimer();
		});

		sdiv.addEvent('mouseout', function() {
			startHideSubMenus();
		});


		var items = sdiv.getElements('td');
		for(var z=0; z<items.length; ++z) {
			items[z].addEvent('mouseover', function() {
				var lst = $(this.parentNode.parentNode).getElements('td');
				for(var i=0; i<lst.length; ++i) {
					doHideSubMenu( lst[i].getAttribute('showsubmenu') );
				}

				//this.addClass('hover');
				showSubSubMenu(this);
			});

			items[z].addEvent('mouseout', function() {

			});

			/*
			try {
				$(items[z].childNodes[0]).addEvent('click', function() {
					return false;
				});
			} catch(e) {}
			*/
			
			items[z].addEvent('click', 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) {
	that = $(that);
	var menuname = that.getAttribute('showsubmenu');

	div = that;
	while(div.tagName != 'DIV') div = div.parentNode;


	var sub = $('submenu-dropdown-'+menuname);
	if(!sub) return;

	sub.setStyles({
		top: that.getTop(),
		left: div.getLeft() + div.offsetWidth - 1,
		display: 'block'
	});
}


function showSubMenu(menuname) {
	hideAllSubMenus();

	var m = $('submenu-menuitem-'+menuname);
	if(!m) return;

	var sub = $('submenu-dropdown-'+menuname);
	if(sub) {

		var o = (Browser.Engine.trident) ? 7 : 4;

		sub.setStyles({
			top: m.getTop() + m.offsetHeight,
			left: m.getLeft(),
			display: 'block'
		});

	}

}


function hideAllSubMenus() {
	clearHideSubMenusTimer();

	var div = $('submenu');
	var tblmainmenu = (div) ? div.getElement('table') : false;
	if(!tblmainmenu) return;

	var lst = tblmainmenu.getElements('td.submenu-menuitem');
	for(var i=0; i<lst.length; ++i) {
		doHideSubMenu( lst[i].id.substr(17) );
	}
}


function startHideSubMenus() {
	clearHideSubMenusTimer();
	window._mainmenutimer = setTimeout('hideAllSubMenus();', 1000);
}


function clearHideSubMenusTimer() {
	clearTimeout(window._mainmenutimer);
}

function doHideSubMenu(menuname) {
	var s = $('submenu-dropdown-'+menuname);
	if(s) s.setStyle('display', 'none');

	//try { $('submenu-menuitem-'+menuname).removeClass('over'); } catch(e) {};
}





























