var navTimer;
var showing = 0;

function showMenu(name) {
  showing = 1;
  $('.topMenu').removeClass('on');
  $('#' + name).addClass('on');
  $('.subMenuPosition').hide();
  $('#subMenu-' + name).show();
  checkNavTimer();
}

function checkNavTimer() {
	if (navTimer) clearTimeout(navTimer);
	navTimer = setTimeout('closeAll()',4000);
}

function closeAll() {
	if(showing) {
	  $('.topMenu').removeClass('on');
	  $('.subMenuPosition').hide();
	  showing = 0;
	}
}

$(function() {

	$('a[rel=external]').click(function() {
		window.open(this.href);
		return(false);
	});

	$('.portalusForm :text:first').focus();

	$('.portalusForm :text').keypress(function (e) {
		if(e.which == 13) {
			
			var next_button = $(".portalusForm :input[value='next']");
			if(next_button) {
				next_button.trigger('click');
				return(false);
			}
		}
	});

	// wrapper for google analytics page tracker
	// assign links the class 'trackme' and provide a name attribute to track clicks in google analytics
	$('a.trackme').click(function() {
		if(this.name) {
			_gaq.push(['_trackPageview', '/' + this.name]);
		}
	});
	
	$('a.track-download-event').click(function() {
		var action = $(this).data('action');
		var label = 	$(this).data('label');
		
		if(action) {
			if(!label) label = this.href;
			_gaq.push(['_trackEvent', 'Downloads', action, label]);
		}
	});


	// TASEX - Ask an expert modal popup 
	// Any link that for the following id will open ask an expert dialog
	// this is a little fragile if the id changes ask an expert will not work
	// unfortunately cannot add a class attribute in links via the cms as this would have been MUCH more preferable
	$('a[href*="id=203976"]').click(function() {
		openDialog();
		return(false);
	});

	
	// TASEX - If they click on the video link in the nav menu it will open the video tab page if its 
	// on the home page
	$('a#videolink').click(function() {
		if($('#hometab2').size() > 0) {
			window.location='#video';
			$('#tabs-container').triggerTab(2);
			return(false);
		}
	});


});


function NewWindow(mypage, myname, w, h, props)
{
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+','+props
  win = window.open(mypage, myname, winprops)
  if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

var qs = location.search.substring(1);
var nv = qs.split('&');
var url = new Object();
for(i = 0; i < nv.length; i++)
{
  eq = nv[i].indexOf('=');
  url[nv[i].substring(0,eq).toLowerCase()] = unescape(nv[i].substring(eq + 1));
}

