$(document).ready(function() {	

// product content module
$('#content > div').hide();
  $('#menu a').click(function() {
    var $this = $(this);
    var hash = $this.attr('href');
    $(hash).siblings(':visible').hide();
    $(hash).slideDown('fast');
    $('#navigation a').removeClass('active');
    $this.addClass('active');
    return false;
  });
  $('#content > div.show').show();
  
  // quick finder tabs module
$(function () {
	var tabContainers = $('div#quick-find > div.body');
	
	$('div#quick-find div.tabs a').click(function () {
		tabContainers.hide();
		tabContainers.filter(this.hash).show();
		$('div#quick-find div.tabs a').removeClass('active');
		$(this).addClass('active');
		return false;
	});
});

});


function gotoCountrySelection(currentselection) {
//takes user to selected country
}


var quicklinks_array = new Array(
	'#', 
	'#', 
	'http://betterturf.basf.us/products/index-products.html', 
	'http://betterturf.basf.us/reference/library/library-landing.html', 
	'http://basfturftalk.com/', 
	'http://betterturf.basf.us/contactUs.html',
	'http://betterturf.basf.us/safety-resources.html', 
	'#',
	'#',
	'http://betterplants.basf.us', 
	'http://www.pestcontrolfacts.org',
	'http://agproducts.basf.us', 
	'http://www.vmanswers.com', 
	'#', 
	'http://www.webfulfillment.com/theAlanCo/Basf/',
	'http://www.agro.basf.com/agr/AP-Internet/en/',
	'http://www2.basf.us/corporate/index.html', 
	'http://www.basfpublichealth.com/', 
	'http://www.pesweb.info/?mysite=BASF');

function gotoLocation(location) {
	document.location.href = location;
}
function gotoQuickLinks(currselection) {
	if (quicklinks_array[currselection.value] == '#') {
		//Do nothing for now
	} else {
		gotoLocation(quicklinks_array[currselection.value]);
	}
}

function popUp(URL) { 
	day = new Date();   
	id = day.getTime(); 
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=914,height=572,left = 503,top = 314');"); 
} 


function redirect(){
	var homepage = "http://betterturf.basf.us/";
	var currenturl = location.href;

	if( currenturl.lastIndexOf(homepage) < 0){
		var newurl = currenturl.substring(7);
		newurl = newurl.replace(newurl.substring(0, newurl.indexOf("/")+1), "");
		
		window.location = homepage + newurl;
	}

}

$(document).click(function(event) {
    if (event.target.tagName.toLowerCase() == "a") {
        eventCheck(event.target.getAttribute("href"));
    }
});

function eventCheck(href){
	if (href.match(/^https?\:/i) && !href.match(document.domain)) {
		_gaq.push(['_trackEvent', 'External', 'click', href]);
	} else if (href.match(/^mailto\:/i)) {
		_gaq.push(['_trackEvent', 'Email', 'click', href.substr(7)]);
	} else if (href.match(/^.*\.(pdf|jpg|png|gif|zip|mp3|txt|doc|rar)$/i)) {
		_gaq.push(['_trackEvent', 'Download', 'click', href]);
	}
}
