$(function() {
	// open all photo links in a lightbox window
	$('.zoom a').lightBox();
	
	// open the general conditions link in a new window
	$('#footer .bayer-global a').click(function(event){
		window.open('http://www.bayer.com/');	
		event.preventDefault();			// don't follow the link
	});

	// open the general conditions link in a new window
	$('#footer .bayer-us a').click(function(event){
		window.open('http://www.bayerus.com/');	
		event.preventDefault();			// don't follow the link
	});

	// open the general conditions link in a new window
	$('#footer .bayer-care a').click(function(event){
		window.open('http://www.bayercare.com/');	
		event.preventDefault();			// don't follow the link
	});

	// open the general conditions link in a new window
	$('#footer .terms a').click(function(event){
		window.open('http://bayercare.com/generalprivacypages/General-Conditions-of-Use.html','popup1','width=290,height=330,scrollbars=yes,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0');	
		event.preventDefault();			// don't follow the link
	});

	// open the privacy policy link in a new window
	$('#footer .privacy a').click(function(event){
		window.open('http://bayercare.com/generalprivacypages/Privacy-Statement.html','popup2','width=290,height=330,scrollbars=yes,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0');	
		event.preventDefault();			// don't follow the link
	});

	// open the imprint link in a new window
	$('#footer .imprint a').click(function(event){
		window.open('http://bayercare.com/generalprivacypages/Imprint.html','popup3','width=290,height=330,scrollbars=yes,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0');
		event.preventDefault();			// don't follow the link
	});

	// open the forward to a friend link in a new window
	$('#tellafriend a').click(function(event){
		window.open('/forward_friend.php','forwardfriend','width=475,height=475,menubar=no,toolbar=no,scrollbars=no,location=no,status=no,resizable=no');
		event.preventDefault();			// don't follow the link
	});

	// accordion function for faq page
	$('.faq dd').hide();				// hide faq contents on page load
	$('.faq dt').click(function(event){	// when we click on a faq question:
		$('.faq dd').slideUp();			// close all open faqs
		$(this).next('dd').slideDown();	// open this faq
	});

	// prevent tabbed nav clicks from doing anything
	$('#nav a').click(function(event){
		event.preventDefault();			// don't follow the link
	});
	
	// set the default visible tab and nav
	visibleNav = "nav1";
	visibleTab = "tab1";

	// get tab id from url if exists and display that tab
	var tab = gup('tab');
	if(tab) displayTab(tab);
});

// read URL parameters
function gup( name ){
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null )
		return "";
	else
		return results[1];
}

// display a tab
function displayTab(id) {
	navId = "nav" + id;
	tabId = "tab" + id;
	if (visibleNav != navId) {
		if (visibleNav) {
			document.getElementById(visibleTab).className = "hidden";
			document.getElementById(visibleNav).className = "off";
		}
		document.getElementById(tabId).className = "visible";
		document.getElementById(navId).className = "on";
		visibleNav = navId;
		visibleTab = tabId;
	}
}