var tabkeypressed = false;
var keyOnLogon = false;
var modaltabpressed = false;
var triggerMousemove = false;
var oldX = 0;
var oldY = 0;
//var focusedElementIndex = 0;

function resetAccessibilityNav(){
	//alert('resetAccessibilityNav');
	triggerMousemove = false;
	tabkeypressed = false;
	keyOnLogon = false;
	
	$('a').css('outline','');
	$('a').has('img').css('float','');
	$('#r1c1r1c1').hide();
	$('.shadow1, .shadow2, .shadow3, .outline').hide();
	//$('div#localedoormat').hide();
	//$('div#locale .dropdownlink').removeClass('show')
	$('div#logondoormat').hide();
	$('div#logon .dropdownlink').removeClass('show');
	$('#overlay').click();
	$('#navigation a').removeAttr('href');
	$("html").animate({ scrollTop: 0 }, "fast");
	$('div#focusindicator').remove();
	$('div#helptip').remove();
	$('div#closemodaltip').remove();
	$('#tabhelptip').remove();
	
	if ($.browser.msie){
		 $('#accessibilitynav').hide();
	}
	else{
		$('#accessibilitynav').slideUp('fast');
	}
	
	$('#accessibilitynav a').blur();
	//START Reset Tabbed content tabs
	$('ul#tabslist li a').css('text-decoration','none');
	$('ul#tabslist li a').css('background-image','');
	$('ul#tabslist li a').find('span').css('background-image','');
	$('ul#tabslist li.current').prev('li').find('span').css('background-image','none');
	//END Reset Tabbed content tabs
	
	$('#slideshow').cycle('resume');//resume the banner rotate
	
	$('div.shareIcons').hide();
	$('div.sendEmail').hide();
}

$(document).mousemove(function(e){
	 if(oldX == 0 && oldY == 0){
	 oldX = e.clientX;
	 oldY = e.clientY;
	 }
	 else if(oldX != e.clientX || oldY != e.clientY){
		 if(tabkeypressed == true){
			$('#head').click();
			//var e = jQuery.Event("keypress");
			var e = jQuery.Event("keydown");
			e.keyCode = 27; 
			$(document).trigger(e);		
		 };
	 }
	 oldX = e.clientX;
	 oldY = e.clientY;
	 
});
$(document).click(function(e){
	//alert(tabkeypressed);
	if(tabkeypressed == true){
		if((!$(e.target).is('div#accessibilitynav')) && $(e.target).parent('div#accessibilitynav').length == 0 && !$(e.target).is('a')){
			resetAccessibilityNav();
		}
	}
});

$(document).keydown(function(e) {
	if(($.browser.msie && $.browser.version.substr(0,1) < 7) && tabAccessReady == false && e.keyCode == 9){return false;}							  
		if(tabkeypressed == false){
			if (e.keyCode == 9) {				
				e.preventDefault();
				tabkeypressed = true;
				if($('div#accessibilitynav').length == 0){
					$('div.expander').before('<div id="accessibilitynav" style="width: 100%; background-color: #ccc; color: #000; font-weight: bold; display:none;overflow:hidden;float:left;border-bottom:solid 1px #f5f5f5;"><span style="padding:10px 20px;float:left;">Go to:</span><a href="#" id="navigationaccess" style="color: #000; padding:10px;outline:0 !important;float:left;">Navigation</a><a href="#" id="contentaccess" style="color: #000;padding:10px;outline:0 !important;float:left;">Content</a><span style="float: right; font-size: 12px; padding: 10px 20px 10px 10px;">Keyboard accessibility ( <strong style="background-color: #e6e6e6; font-size: 11px; font-weight: normal; padding: 2px 4px; line-height: 16px; border: medium outset;">Tab</strong> to navigate forward, <strong style="background-color: #e6e6e6; font-size: 11px; font-weight: normal; padding: 2px 4px; line-height: 16px; border: medium outset;">Shift</strong>+<strong style="background-color: #e6e6e6; font-size: 11px; font-weight: normal; padding: 2px 4px; line-height: 16px; border: medium outset;">Tab</strong> key to navigate back, <strong style="background-color: #e6e6e6; font-size: 11px; font-weight: normal; padding: 2px 4px; line-height: 16px; border: medium outset;">Enter</strong> to access link, and <strong style="background-color: #e6e6e6; font-size: 11px; font-weight: normal; padding: 2px 4px; line-height: 16px; border: medium outset;">Esc</strong> to reset )</span></div>');
				}
				$('#accessibilitynav').show();
				$('#accessibilitynav a').focus(function(){$(this).css({'background-color':'#db0011','color':'#fff'}).siblings('#accessibilitynav a').blur();});
				$('#accessibilitynav a').blur(function(){$(this).css({'background-color':'transparent','color':'#000'})});
				$('#accessibilitynav a').keydown(function(e){
					if (e.keyCode == 9){
						$(this).siblings('a').focus();
						return false;
					}
				});			
				$('a#navigationaccess').keydown(function(e){
					if(e.keyCode == 13){
						if($('div#focusindicator').length==0){
							$('div.expander').before('<div id="focusindicator" style="background:transparent url(/gbm/images/common/focus-indicator.gif) no-repeat left top scroll;position:absolute;width:10px;height:10px;z-index:9998;left:-9999%">');
						}
						if($('div#tabhelptip').length==0){
							$('div.expander').before('<div id="tabhelptip" style="color: #fff; background-color: #0c0; font-size: 11px; padding: 5px 0; float:left; text-align:center; position:absolute; left:-9999%; z-index:9998; width:auto">Press ENTER to<br />access tab</div>');
						}
						
						$('#navigation a').attr('href','#');
						if(!$.browser.msie){
							$('a').has('img').css('float','left');
						}						
						$('#accessibilitynav').hide(function(){
							$('#accessibilitynav a').blur();
							$('#head a, #head input:not(:hidden)').eq(0).trigger('focus');//FOCUS ON FIRST FOCUSABLE ELEMENT IN THE HEADER
						});
						return false;
					}
				});
				$('a#contentaccess').keydown(function(e){
					if(e.keyCode == 13){
						if($('div#focusindicator').length==0){
							$('div.expander').before('<div id="focusindicator" style="background:transparent url(/gbm/images/common/focus-indicator.gif) no-repeat left top scroll;position:absolute;width:10px;height:10px;z-index:9998;left:-9999%">');
						}
						if($('div#tabhelptip').length==0){
							$('div.expander').before('<div id="tabhelptip" style="color: #fff; background-color: #0c0; font-size: 11px; padding: 5px 0; float:left; text-align:center; position:absolute; left:-9999%; z-index:9998; width:auto">Press ENTER to<br />access tab</div>');
						}
						$('#accessibilitynav').hide(function(){
							$('#accessibilitynav a').blur();
							if(!$.browser.msie){
								$('a').has('img').css('float','left');
							}						
							if($('#slideshow').length > 0){
								$('#slideshow').cycle('pause');
								$('ul#carouselnav li a:first').focus();//FOCUS ON FIRST CAROUSEL TAB IF PAGE HAS BANNER ROTATE
							}
							else{						
								$('#r1c1r1c2 a:first').trigger('focus');//FOCUS ON FIRST ANCHOR IN ZONE 1
							}
						});
						return false;
					}
				});
				
				$('a#navigationaccess').focus();
				$("html").animate({ scrollTop: 0 }, "fast");
				return false;
			}
		}
		
		if (e.keyCode == 27){
			//alert($(e.target).toSource())
			//$("a, input").eq(focusedElementIndex).blur();
			document.activeElement.blur();
			resetNavTabs();
			resetAccessibilityNav();
		}
});

function showFocusIndicator(elem){
	var offset = elem.offset();
	
	if($.trim($('#focusindicator').css('background-image')).indexOf("-right")>-1){
		var reseturl = $.trim($('#focusindicator').css('background-image')).replace('-right','')
		$('#focusindicator').css('background-image',reseturl);
	}
	
	if(elem.parents('div#modalbody').length > 0){
		if($("#modalcontent").contents().find('div#modalfocusindicator').length == 0){
			$("#modalcontent").contents().find("body").prepend('<div id="modalfocusindicator" style="background:transparent url(/gbm/images/common/focus-indicator.gif) no-repeat left top scroll;position:absolute;width:10px;height:10px;z-index:9998;left:-9999%">');
		}	
		$("#modalcontent").contents().find('div#modalfocusindicator').offset({top:(offset.top+(elem.outerHeight())/4),left:(offset.left-7)});
		return false;
	}
	if(elem[0] == $('a.logoBrand')[0] || elem.parents('div#navigation').length > 0 || elem.parents('div.bannercarousel').length > 0 || elem.has('img')){
		$('div#focusindicator').offset({top:(offset.top+(elem.outerHeight())/2)-5,left:offset.left-7});
	}
	else{
		$('div#focusindicator').offset({top:offset.top+(elem.outerHeight())/4,left:offset.left-7});
	}
	
	if(elem.parents('ul#carouselnav').length > 0){
		if(elem[0]==$('ul#carouselnav a')[0]){
			$('div#focusindicator').css('background-image','url(/gbm/images/common/focus-indicator-right.gif)');
			$('div#focusindicator').offset({top:(offset.top+(elem.outerHeight())/2)-5,left:offset.left+(elem.outerWidth())});
		}
		else{
			$('div#focusindicator').css('background-image','url(/gbm/images/common/focus-indicator.gif)');
			$('div#focusindicator').offset({top:(offset.top+(elem.outerHeight())/2)-5,left:offset.left-7});
		}
	}
}

function showHelpTip(tiptext){
	if($('div#helptip').length == 0){
		$('div.expander').before('<div id="helptip" style="background-color:#0c0;position:absolute;z-index:9998;padding:5px;color:#fff;font-size:11px;left:-9999%;text-align:center"></div>');				
		$('div#helptip').html(tiptext);
		var helptipwidth = $('div#helptip').outerWidth();
		var helptipheight = $('div#helptip').outerHeight();
		var offset = $('#focusindicator').offset();
		if($.trim($('#focusindicator').css('background-image')).indexOf("-right")>-1){
			$('div#helptip').offset({top:offset.top-((helptipheight/2)-5),left:offset.left+5});
		}
		else{
			$('div#helptip').offset({top:offset.top-((helptipheight/2)-5),left:offset.left-(helptipwidth)});
		}
	}
}

function showCloseModalTip(){
	if($('div#closemodaltip').length == 0){
		$('div.expander').before('<div id="closemodaltip" style="background-color:#0c0;position:absolute;z-index:99998;padding:5px;color:#fff;font-size:11px;left:-9999%;text-align:center"></div>');				
		$('div#closemodaltip').html('Press ESC to close');
		var helptipwidth = $('div#closemodaltip').outerWidth();
		var helptipheight = $('div#closemodaltip').outerHeight();
		var offset = $('#modalclose').offset();
		$('div#closemodaltip').offset({top:offset.top+5,left:offset.left-(helptipwidth)});
	}
}

$(document).ready(function() {

//	$('#head a, #head input:not(:hidden)').eq(0).focus(function(){
//		$("html").animate({ scrollTop: 0 }, "fast");
//	});


//	$("a, input").live("focus", function(){
//		if(tabkeypressed == true){
//			focusedElementIndex = $("a, input").index(this);
//		}
//	});
	$('a:not(".expandcollapse"), input').focus(function(){													   
		if(tabkeypressed == true){
		  $(this).trigger('mouseenter');
//		  $(this).css('outline','1px solid #0c0');
		  showFocusIndicator($(this));
		}
	});
	$('select').focus(function(){													   
		if(tabkeypressed == true){
		  $(this).trigger('mouseenter');
//		  $(this).css('outline','1px solid #0c0');
		  showFocusIndicator($(this));
		}
	});
	
	$('a.expandcollapse').focus(function(){													   
		if(tabkeypressed == true){
		  $(this).trigger('mouseenter');
		  $(this).css('border','1px solid #0c0');
		  //showFocusIndicator($(this));
		}
	}).blur(function(){$(this).css('border','');});
	

	$('ul.tabs li.off a').focus(function(){
		if(tabkeypressed == true){
			$(this).trigger('hover');
			if ($.browser.msie){
				$(this).addClass('focus');
			}
		}
	});
	$('ul.tabs li.off a').blur(function(){
		if(tabkeypressed == true){
			$(this).trigger('mouseleave');								
			if ($.browser.msie){
				$(this).removeClass('focus');
			}
		}
	});

	$('#sitesearchcontainer input#searchbox').focus(function(){
		if(tabkeypressed == true){
			showHelpTip('Press ENTER to search');			
		}
	}).blur(function(){
		if(tabkeypressed == true){
			$('div#helptip').remove();
		}
	});
	$('#sitesearchcontainer input#searchbox').keydown(function(event){
			if (event.keyCode == 9) {
				if(tabkeypressed == true){
				document.getElementById("logonbtn").focus();
				return false;
				}
			}
	});

	$('div#foot input#footersearch').focus(function(){
		if(tabkeypressed == true){
			showHelpTip('Press ENTER to search');
		}
	}).blur(function(){
		if(tabkeypressed == true){
			$('div#helptip').remove();
		}
	});	
	$('div#foot input#footersearch').keydown(function(e){
			if (e.keyCode == 9){
				if(tabkeypressed == true){
				//document.getElementById("logonbtn").focus();
				$('div#helptip').remove();
				$('div#foot div#links a:first').focus();
				return false;
				}
			}			
	});
	
	$("#logonbtn").focus(function(){
		if(tabkeypressed == true){
			showHelpTip('Press ENTER to to access sub items');
		}
	}).blur(function(){
		if(tabkeypressed == true){
			$('div#helptip').remove();
		}
	});
    $("#logonbtn").keydown(
		function(e){
			if(tabkeypressed == true){
				if(e.keyCode == 13){
					if($('#r1c1r1c1').siblings('.shadow1').css('display') == 'block'){
						resetNavTabs();
						$('#r1c1r1c1').hide();
						$('#r1c1r1c1').siblings('.shadow1, .shadow2, .shadow3, .outline').hide();
					}
					if($('#logondoormat').css('display') == 'none'){
						$(this).addClass('show');
						$('#logondoormat').show();
						$('#logondoormat').siblings('.shadow1, .shadow2, .shadow3, .outline').show();
					}
					$(this).blur();
					//setTimeout("$('#logondoormat a').eq(0).focus()",250);
					setTimeout("$('#logondoormat a, #logondoormat input:not(:hidden)').eq(0).trigger('focus');",250);
					
					return false;
				}
				if(e.keyCode == 9 && !e.shiftKey){
					$("#logonbtn").removeClass('show');
					$('#logondoormat').hide();
					$('#logondoormat').siblings('.shadow1, .shadow2, .shadow3, .outline').hide();
					
					setTimeout("document.getElementById('brand').getElementsByTagName('a')[0].focus()",250);
					return false;
				}
			}
	});
	
	$('form#gbmForm input#userid').focus(function(){
		if(tabkeypressed == true){
			showHelpTip('Press ENTER to log on');			
		}
	}).blur(function(){
		if(tabkeypressed == true){
			$('div#helptip').remove();
		}
	});
	
	$('#logondoormat a:last').keydown(function(e){
			if(tabkeypressed == true){
				if(e.keyCode == 9 && !e.shiftKey){
					$("#logonbtn").removeClass('show');
					$('#logondoormat').hide();
					$('#logondoormat').siblings('.shadow1, .shadow2, .shadow3, .outline').hide();
					$(this).blur();
					document.getElementById('brand').getElementsByTagName('a')[0].focus();
					return false;
				}
			}
	});	
	

//START HEADER NAVIGATION TABS
	$('div#navigation li:not(".toolName") a').focus(function(){
		if(tabkeypressed == true){
			showHelpTip('Press ENTER to access<br/>sub items');		
			$(this).trigger('mouseenter');
		}
	}).blur(function(){
		if(tabkeypressed == true){
//			resetNavTabs();
//			if ($.browser.msie){
//				$('#r1c1r1c1 .doormat .roundcorner').hide();//hide all elements with rounded corners
//			}
//			$('#r1c1r1c1').hide();
//			$('#r1c1r1c1').siblings('.shadow1, .shadow2, .shadow3, .outline').hide();
			$('div#helptip').remove();
		}
	});	
	
	$('div#navigation li:not(".toolName") a').keydown(function(e){
		//if ($.browser.msie) {
			index = $('#navigation li:not(".toolName") a.subNav').index($(this));
			if (e.keyCode == 9 && !e.shiftKey){
				if(tabkeypressed == true){
					if(index == $('#navigation li:not(".toolName") a.subNav').index($('#navigation li:not(".toolName") a.subNav:last'))){//if last navigation tab and tab key is pressed
						$('#r1c1r1c1').hide();
						$('.shadow1, .shadow2, .shadow3, .outline').hide();
						resetNavTabs();
						//$(this).css('outline','0');
						$('div#helptip').remove();
						$("html").animate({ scrollTop: $(document).height() }, "fast");
						$('#foot').find('a').eq(0).focus();
						return false;
					}
				}
			}			
			if (e.keyCode == 13){
				//$(this).css('outline','0');
				$('div#helptip').remove();
				$('.doormatcontent').eq(index).find('a').eq(0).focus();
				return false;
			}
		//}
	});
//END HEADER NAVIGATION TABS

//START NAVIGATION DOORMATS
	$('.doormatcontent a').keydown(function(e){/*FOR IE ONLY*/
			if(tabkeypressed == true){
				var index;
				index = $('.doormatcontent').index($(this).parents('.doormatcontent'));
				if (e.keyCode == 9){
					index = $('.doormatcontent').index($(this).parents('.doormatcontent'));
					if($('.doormatcontent:eq('+index+') a').index($(this)) == $('.doormatcontent:eq('+index+') a').index($('.doormatcontent:eq('+index+') a:last'))){
						if(index < $('#navigation li:not(".toolName") a').length - 1){
							$('#navigation li:not(".toolName") a').eq(index+1).focus();
							return false;
						}
						else{
							$('#r1c1r1c1').hide();
							$('.shadow1, .shadow2, .shadow3, .outline').hide();
							resetNavTabs();
							$("html").animate({ scrollTop: $(document).height() }, "fast");
							$('#foot').find('a').eq(0).focus();
							return false;
						}
					}
				}
				if(e.keyCode == 37 || e.keyCode == 38){//if left or up key			
					anchorIndex = $('.doormatcontent:eq('+index+') a').index($(this));
					if(anchorIndex-1 < 0){
						$('.doormatcontent:eq('+index+') a:last').focus();
						return false;
					}
					else{
						$('.doormatcontent:eq('+index+') a').eq(anchorIndex-1).focus();
						return false;
					}
				}
				if(e.keyCode == 39 || e.keyCode == 40){//if right or down key			
					anchorIndex = $('.doormatcontent:eq('+index+') a').index($(this));
					if(anchorIndex == $('.doormatcontent:eq('+index+') a').index($('.doormatcontent:eq('+index+') a:last'))){
						$('.doormatcontent:eq('+index+') a:first').focus();
						return false;
					}
					else{
						$('.doormatcontent:eq('+index+') a').eq(anchorIndex+1).focus();
						return false;
					}
				}
			}
	});	
//END NAVIGATION DOORMATS

	$('#carouselnav a').focus(function(){
		if(tabkeypressed == true){
			showHelpTip('Press ENTER to access slide');			
		}
	}).blur(function(){
		if(tabkeypressed == true){
			$('div#helptip').remove();
		}
	});
	$('#carouselnav a').keydown(function(e){
			if(tabkeypressed == true){
				var index = $('#carouselnav a').index($(this));
				if (e.keyCode == 13){
					$('#slideshow').cycle('pause');				
					
					$('.slide').css('left','-960px');
					$('div.carouseltab').removeClass('current');
					$('span.arrowpoint').removeClass('current');
					$('#carouselnav a').removeClass('current');
					
					$('.slide').eq(index).css({'left':'0px','display':'block'});
					$('div.carouseltab').eq(index).addClass('current');
					$('span.arrowpoint').eq(index).addClass('current');
					$(this).addClass('current');
					setTimeout(function(){$('.slide').eq(index).find('a').focus();$('div#helptip').remove();},250);
					return false;
				}
				if(e.keyCode == 9 && e.shiftKey && index == 0){
					return false;
				}
			}
	});
	
	$('.slide a:not(:hidden):last').keydown(function(e){
			if(tabkeypressed == true){
				if (e.keyCode == 9){
					var index = $('.slide').index($(this).parents('.slide'));
					$('#carouselnav a').eq(index).focus();
					return false;
				}
			}
	});
	
	$('li.slider a').keydown(function(e){
			if(tabkeypressed == true){
				if (e.keyCode == 13){
					var index = $('.featurecarousel ul').index($('.featurecarousel ul:visible'));
					if($.trim($(this).attr('id'))=="nextset"){
						$('.featurecarousel').cycle("next");
						setTimeout(function(){$('.featurecarousel ul').eq(index+1).find('a').eq(0).focus()},700);
						return false;
					}
					else{
						$('.featurecarousel').cycle("prev");
						setTimeout(function(){$('.featurecarousel ul').eq(index-1).find('a').eq(0).focus()},700);
						return false;
					}
				}
			}
	});
	$('li.slider a').focus(function(){
		if(tabkeypressed == true){
			if($.trim($(this).attr('id'))=="prevdisabled"){
				$('li.slider a#nextset').focus();
			}
			else if($.trim($(this).attr('id'))=="nextdisabled"){
				$('.featurecarouselnav a:not(".articleset a"):first').focus();			
			}			
		}
	});
	$('div#tableexpander a').keydown(function(e){
			if (e.keyCode == 13){
				//$(this).click();
				$(this).focus();
				return false;
			}
	});
	
	$('div#foot a:first').keydown(function(e){
			if(tabkeypressed == true){
				if(e.keyCode == 9 && e.shiftKey){
					$('div#navigation a:last').focus();
					return false;
				}
			}
	});
	
	$('div#foot div#links a').keydown(function(e){
			if(tabkeypressed == true){
				if(e.keyCode == 37 || e.keyCode == 38){			
					anchorIndex = $('div#foot div#links a').index($(this));
					if(anchorIndex-1 < 0){
						$('div#foot div#links a:last').focus();	
						return false;
					}
					else{
						$('div#foot div#links a').eq(anchorIndex-1).focus();
						return false;
					}					
				}
				if(e.keyCode == 39 || e.keyCode == 40){			
					anchorIndex = $('div#foot div#links a').index($(this));
					if(anchorIndex == $('div#foot div#links a').index($('div#foot div#links a:last'))){
						$('div#foot div#links a:first').focus();	
						return false;
					}
					else{
						$('div#foot div#links a').eq(anchorIndex+1).focus();
						return false;
					}					
				}				
			}
	});
	
	
	$('div#foot div#meta a:last').keydown(function(e){
			if (e.keyCode == 9){
				//$('body a:first').focus();
				$(this).css('outline','0');
				//$('ul.tabs li.off a').trigger('focus');
				$("html").animate({ scrollTop: 0 }, "fast");
				$('#head a, #head input:not(:hidden)').eq(0).trigger('focus');//FOCUS ON FIRST FOCUSABLE ELEMENT IN THE HEADER
				return false;
			}
	});
	$('div#foot div#meta a').keydown(function(e){
			if(tabkeypressed == true){
				if(e.keyCode == 37 || e.keyCode == 38){
					$(this).blur();
					anchorIndex = $('div#foot div#meta a').index($(this));
					if(anchorIndex-1 < 0){
						$('div#foot div#meta a:last').focus();
						return false;
					}
					else{
						$('div#foot div#meta a').eq(anchorIndex-1).focus();
						return false;
					}					
				}
			}
	});
	
	$('a.expandcollapse').keydown(function(e){
			if (e.keyCode == 13){
				$(this).parents('.section a:first').focus();
			}
	});

	$('ul#tabslist li a').focus(function(e){
		 //$(this).css('outline','1px solid #0c0');
		if(tabkeypressed == true){										 
			//if($(this).parent().hasClass('current') && $.browser.msie){
			if($(this).parent().hasClass('current')){				
				$('ul#tabslist').css('height','58px');
				$('div.tabcontentarea').css('margin-top','57px');
				$('ul#tabslist a').css('margin-top','2px');
			}
			
			$(this).css('text-decoration','underline');
			$(this).css('background-image','none');
			$(this).find('span').css('background-image','none');
			
			var tabOffset = $(this).parents('li').offset();
			var helTipTop = tabOffset.top - 36;
			var helpTipWidth = $(this).parents('li').outerWidth();
			if($('div#tabhelptip').length==0){
				strtest = '<div id="tabhelptip" style="color: #fff; background-color: #0c0; font-size: 11px; padding: 5px 0; float:left; text-align:center; position:absolute; left:'+tabOffset.left+'px; top:'+helTipTop+'px; z-index:9998; width:'+helpTipWidth+'px">Press ENTER to<br />access tab</div>'
				$("div.expander").before(strtest);
			}
			else{
				$('div#tabhelptip').css({"left":tabOffset.left+"px","top":helTipTop+"px","width":helpTipWidth+"px"});
			}
		}
	});
	$('ul#tabslist li a').blur(function(e){
		$(this).css('text-decoration','none');
		$(this).css('background-image','');
		$(this).find('span').css('background-image','');
		if($('div#tabhelptip').length>0){
			$('#tabhelptip').remove();
		}
	});
	$('ul#tabslist li a').keydown(function(e){
			var index = $('ul#tabslist li a').index($(this));											
			if (e.keyCode == 13){
				if($(this).parent('li').hasClass('current')){
					if($('.tabcontentarea').eq(index).find('a').length >0){
						$(this).blur();
						setTimeout("$('.tabcontentarea').eq("+index+").find('a:first').focus()",250);
						return false;
					}
					else{
						$(this).focus();
						return false;
					}
				}
			}
			if (e.keyCode == 9 && !e.shiftKey){
				if(index == $('ul#tabslist li:not(".tabnav") a').length - 1){
					var tabcontentanchorindex = $('body a').index($('div.tabcontentarea:visible').find('a:last'));
					//alert(tabcontentanchorindex);
					$(this).blur();
					if(tabcontentanchorindex < 0){						
						tabcontentanchorindex = $('body a:visible').index($(this));
						$('body a:visible').eq(tabcontentanchorindex+1).focus();
					}
					else{
						//$('body a').eq(tabcontentanchorindex+1).focus();
						$('#r1c2 a').eq(0).focus();
					}
					
					//$('.primarytabs #tabslist a span').removeAttr('style');
					$('.primarytabs #tabslist li.current').prev('li').find('span').css('background-image','none');
					return false;
				}
			}
			if(e.keyCode == 37){
				$(this).blur();
				if(index == 0){//if first tabbedcontent tab
					$('ul#tabslist li:not(".tabnav"):last a').focus();
					return false;
				}
				else{
					$('ul#tabslist li a').eq(index-1).focus();
					return false;
				}
			}
			if(e.keyCode == 39){
				$(this).blur();
				if(index == $('ul#tabslist li:not(".tabnav") a').index($('ul#tabslist li:not(".tabnav"):last a'))){//if last tabbedcontent tab
					$('ul#tabslist li:not(".tabnav"):first a').focus();
					return false;
				}
				else{
					$('ul#tabslist li a').eq(index+1).focus();
					return false;
				}
			}			
	});
	$('ul#tabslist li a:visible:last').keydown(function(e){
			if(tabkeypressed == true){
				if(e.keyCode == 9 && e.shiftKey){
					$('ul#tabslist li a:visible:first').focus();
					return false;
				}
			}
	});
	
	$('div.tabcontentarea a').keydown(function(e){
			if (e.keyCode == 9){
				var index = $('.tabcontentarea').index($(this).parents('.tabcontentarea'));
				var anchorIndex = $('.tabcontentarea:eq('+index+') a').index($(this));
				
				if(anchorIndex == $('.tabcontentarea:eq('+index+') a').index($('.tabcontentarea:eq('+index+') a:last'))){
					if(index < $('.tabcontentarea').length - 1){
						$(this).blur();
						$('ul#tabslist li a').eq(index+1).focus();
						return false;
					}
				}
			}
	});
	
	$('#r1c1r1c2 a:not(:hidden):first').keydown(function(e){
			if(tabkeypressed == true){
				if (e.keyCode == 9 && e.shiftKey){
					return false;
				}
			}
	});
	
	$('#r1c2 a').keydown(function(e){
			if(tabkeypressed == true){
				var index = $('#r1c2 a:visible').index($(this));
				if (e.keyCode == 9 && !e.shiftKey){
					if(index == $('#r1c2 a:visible').index($('#r1c2 a:visible:last'))){
						$(this).blur();
						if($('.bannercarousel').length>0){
							$('#carouselnav a:first').trigger('focus');
						}
						else if($('.rightcolcontent').length>0){
							$('.rightcolcontent a:first').trigger('focus');
						}
						else{
							$('#r1c1r1c2 a:visible:first').trigger('focus');//FOCUS ON FIRST ANCHOR IN ZONE 1
						}
						return false;
					}
				}
			}
	});
	
	$('.rightcolcontent a').keydown(function(e){
			if(tabkeypressed == true){
				var index = $('.rightcolcontent a:visible').index($(this));
				if (e.keyCode == 9 && !e.shiftKey){
					if(index == $('.rightcolcontent a:visible').index($('.rightcolcontent a:visible:last'))){
						$(this).blur();
						if($('.bannercarousel').length>0){
							$('#carouselnav a:first').trigger('focus');
						}
						else{
							$('#r1c1r1c2 a:visible:first').trigger('focus');//FOCUS ON FIRST ANCHOR IN ZONE 1
						}
						return false;
					}
				}
			}
	});
	
	$('a.shareLink').keydown(function(e){
			if(tabkeypressed == true){
				var index = $('#r1c1r1c2 a:visible').index($(this));
				$('div.shareIcons a').focus(function(){
					$(this).css('color','#db0011');
				}).blur(function(){
					$(this).css('color','');
				});
				if (e.keyCode == 13){
					//$(this).next('div.sendEmail').hide();
					$(this).next('div.shareIcons').find('div.sendEmail').hide();
					$(this).next('div.shareIcons').show();
					
					return false;
				}
				if (e.keyCode == 9 && $(this).next('div.shareIcons').css('display') != "none"){					
					//alert();
					//$(this).blur();
					//$(this).next('div.shareIcons').hide();
					$(this).next('div.shareIcons').find('a').eq(0).trigger('focus');
					return false;
				}
				if (e.keyCode == 9 && !e.shiftKey){
					$('#r1c1r1c2 a:visible').eq(index+1).trigger('focus');
					return false;
				}
			}
	});
	
	$('div.shareIcons a.mail').live('keydown', function(e){
			//alert(tabkeypressed)
			if(tabkeypressed == true){
				var index = $('#r1c1r1c2 a:visible').index($(this).parents('.secondarybutton').find('a.shareLink'));
				if (e.keyCode == 9 && $(this).next('div.sendEmail').css('display') != "none"){	
					$(this).blur();
					$(this).parent().find('input.mailbox').focus();
					return false;
				}
				if (e.keyCode == 9 && !e.shiftKey){					
					$(this).blur();
					//$(this).next('div.shareIcons').hide();
					$(this).parent().hide();
					$('#r1c1r1c2 a:visible').eq(index+1).trigger('focus');				
					return false;
				}
				if (e.keyCode == 13){
					$(this).next('div.sendEmail').show();
					return false;
					
				}
			}
	});
	
	$('div.sendEmail a.roundcorner').live('keydown', function(e){
			if(tabkeypressed == true){
				if (e.keyCode == 9 && !e.shiftKey){					
					$(this).blur();
					//$(this).next('div.shareIcons').hide();
					$(this).parents('div.shareIcons').hide();
					$(this).parents('div.sendEmail').hide();
					//addthis_close();
					$(this).parent().parent().parent().find("a.shareLink").focus();
					return false;
				}
			}
	});
	
	var anchorindexbeforemodal = 0;
	var javascriptStatement = '';
	$('a[onclick*="showModalDialog"]').keydown(function(e){
			if(tabkeypressed == true){				
				if(e.keyCode == 13){
					anchorindexbeforemodal = $('body a:visible').index($(this));
					javascriptStatement = $(this)[0].getAttributeNode('onclick').value;
					javascriptStatement = javascriptStatement.substr(0,javascriptStatement.indexOf('return'));					
					eval(javascriptStatement);
					modaltabpressed = true;
					setTimeout(setFocusModal, 3000);
					return false;
				}
			}
	});
	$('a[onclick*="showCrossDomainModalDialog"]').keydown(function(e){
			if(tabkeypressed == true){
				if(e.keyCode == 13){
					anchorindexbeforemodal = $('body a:visible').index($(this));
					javascriptStatement = $(this)[0].getAttributeNode('onclick').value;
					javascriptStatement = javascriptStatement.substr(0,javascriptStatement.indexOf('return'));
					eval(javascriptStatement);
					setTimeout(setFocusModalCrossDomain, 3000);
					return false;
				}
			}
	});
	
	function setFocusModal() {
		try{
		var iframe = $("#modalcontent")[0];
		iframe.contentWindow.focus();
		
		iframe.contentWindow.$('a:visible, input:not(:hidden), select, textarea').focus(function(){
			showFocusIndicator($(this));
			return false;
		});
		iframe.contentWindow.$('a:visible, input:not(:hidden), select, textarea').last().keydown(function(e){
				var index = iframe.contentWindow.$('a:visible, input:not(:hidden), select, textarea').index($(this));
				var indexLast = iframe.contentWindow.$('a:visible, input:not(:hidden), select, textarea').index(iframe.contentWindow.$('a:visible, input:not(:hidden), select, textarea').last());
				if(e.keyCode == 9 && !e.shiftKey){
					iframe.contentWindow.scrollTo(0, iframe.contentWindow.$('a:visible, input:not(:hidden), select, textarea').eq(0).offset().top);
					$(this).blur();
					//iframe.contentWindow.$('a, input:not(:hidden)').eq(0).focus();
					if(index==indexLast){
						if(iframe.contentWindow.$('object').length>0){
							var objectId = iframe.contentWindow.$('object').attr('id');
							iframe.contentWindow.document.getElementById(objectId).focus(); 
						}
						else{
							$('#modalcontent').contents().find('a:visible, input:not(:hidden), select, textarea').first().focus();
						}
					}
					return false;
				}
		});		
		iframe.contentWindow.$('a:visible, input:not(:hidden), select, textarea').first().keydown(function(e){
				if(e.keyCode == 9 && e.shiftKey){
//					alert('');
					iframe.contentWindow.scrollTo(0, iframe.contentWindow.$('a:visible, input:not(:hidden), select, textarea').last().offset().top);
					$(this).blur();
//					iframe.contentWindow.$('a, input:not(:hidden)').last().focus();
					$('#modalcontent').contents().find('a, input:not(:hidden), select, textarea').last().focus();
					return false;
				}
		});
		$(iframe.contentWindow.document).keydown(function(e){
				if(e.keyCode == 27){
					modaltabpressed = false;
					$('div#closemodaltip').remove();					
					top.$('body a:visible').eq(anchorindexbeforemodal+1).focus();
					top.closeModalDialog();
					return false;
				}
			//}
		});
		showCloseModalTip();
		if(iframe.contentWindow.$('object').length > 0){
			var objectId = iframe.contentWindow.$('object').attr('id');
			iframe.contentWindow.document.getElementById(objectId).focus(); 
			return false;
		}
		
		if(iframe.contentWindow.$('a:visible, input:not(:hidden), select, textarea').length > 0){
			//alert($('#modalcontent').contents().find('a, input:not(:hidden)').length);
			$('#modalcontent').contents().find('a:visible, input:not(:hidden), select, textarea').eq(0).focus();
			//iframe.contentWindow.$('a, input:not(:hidden)').eq(0).focus();
			//alert(iframe.contentWindow.$('a:visible, input:not(:hidden)').last().html());
			return false;
		}
		else{
			$(iframe.contentWindow.document).keydown(function(e){
					if(e.keyCode == 9){
						$('div#closemodaltip').remove();						
						top.$('body a:visible').eq(anchorindexbeforemodal+1).focus();
						top.closeModalDialog();
						return false;
					}
			});
		}
		

		return false;
		}
		catch(err){
			//alert(err.toSource());
		}
	}
	
	function setFocusModalCrossDomain() {
		try{
		var iframe = $("#modalcontent")[0];
		iframe.contentWindow.focus();		
		return false;
		}
		catch(err){
			//alert(err.toSource());
		}
	}
	
	
});
