$(function() {
	$('#inpopup').hover(function(){ $(this).show(); },function(e){ $(this).hide(); });
	$('#uspopup').hover(function(){ $(this).show(); },function(e){ $(this).hide(); });
	$('#sepopup').hover(function(){ $(this).show(); },function(e){ $(this).hide(); });
	$('#sepopup2').hover(
		function(e){ $(this).show(); $('#sepopup').show(); },
		function(e){ $(this).hide(); $('#sepopup').hide(); }
	);
	$('#topnav a img').hover( 
		function(e) { 
			var sp = $(this).attr('src').split('/').pop().split('.'); 
	
			if( sp[0] == 'innovations' || sp[0] == 'innovations-h' ) $('#inpopup').show();
			else if( sp[0] == 'aboutus' || sp[0] == 'aboutus-h' ) $('#uspopup').show();
			else if( sp[0] == 'services' || sp[0] == 'services-h' ) $('#sepopup').show();
			else $(this).attr('src','/images/links/'+sp[0]+'-h.'+sp[1]); 
		},
		function(e) {
			var sp = $(this).attr('src').split('/').pop().split('.');

			if( sp[0] == 'innovations' || sp[0] == 'innovations-h' ) { $('#inpopup').hide(); }
			else if( sp[0] == 'aboutus' || sp[0] == 'aboutus-h' ) { $('#uspopup').hide(); }
			else if( sp[0] == 'services' || sp[0] == 'services-h' ) { $('#sepopup').hide(); }
			else $(this).attr('src','/images/links/'+sp[0].split('-')[0]+'.'+sp[1]); 
	});
	$('#topmenu td:first').addClass('first');
	$('#topmenu td:last').addClass('last');
	$('#topmenu td').hover(function() {
		if ($(this).hasClass('item')) {
			$(this).addClass('hover');
		}
		$('#inpopup, #uspopup, #sepopup, #sepopup2').hide();
		if ($(this).find('a').html() == "Services") {
			$('#sepopup').show();
		}
		if ($(this).find('a').html() == "Integrations") {
			$('#inpopup').show();
		}
		if ($(this).find('a').html() == "About Us") {
			$('#uspopup').show();
		}
		if ($(this).find('a').html() == "Consulting") {
			$('#sepopup2').show();
		}
	}, function() {
		$(this).removeClass('hover');
	});

	$('#consulting_link').hover(function() {
		if ($(this).hasClass('item')) {
			$(this).addClass('hover');
		}
		$('#sepopup2').show();
	}, function() {
		$(this).removeClass('hover');
		$('#sepopup2').hide();
	});

	if (document.location.href.indexOf('services') >= 0) {
		$('#topmenu .item.services').addClass('active');
	} else if (document.location.href.indexOf('innovations') >= 0) {
		$('#topmenu .item.innovations').addClass('active');
	} else if (document.location.href.indexOf('clients') >= 0) {
		$('#topmenu .item.clients').addClass('active');
	} else if (document.location.href.indexOf('contact_us') >= 0) {
		$('#topmenu .item.contactus').addClass('active');
	} else if (document.location.href.indexOf('about_us') >= 0) {
		$('#topmenu .item.aboutus').addClass('active');
	} else if (document.location.href.indexOf('resources') >= 0) {
		$('#topmenu .item.resources').addClass('active');
	} else {
		$('#topmenu .item.home').addClass('active');
	}
});

