var _tmout;
var _last_section = "";
var _news_string = "";
var breaking_news = [];
var breaking_news_important = [];
var chrono_breaking_news = [];
var headline_count = 0;
var headline_counter = 0;
var headline_interval;
var current_headline = 0;
var _headline_level = 0;
var _news_scroll_height = 16;
var left_nav_ele;
var current_nav_item = "";
var current_left_nav_item = "";
var current_left_subnav_item = "";
var current_mega_menu_item = "";
var twfVideoData = [];
var _flvs = undefined;
var HAS_VALID_FLASH_VERSION = false;

/* this defines a global variable HAS_VALID_FLASH_VERSION to display alternative content to flash*/
try{
 _flvs = new SWFObject("/corporate/includes/multimedia/login.swf", "login", "256px", "22px", "9");
 HAS_VALID_FLASH_VERSION = _flvs.installedVer.versionIsValid(_flvs.getAttribute("version"));
} catch(e){
 HAS_VALID_FLASH_VERSION = false;
}

function tagYouAreIt(){
	try{
	$("a[href*=.pdf]").addClass("chaseanalytics-opt-doc-dnld");
	$("a[href*=.doc]").addClass("chaseanalytics-opt-doc-dnld");
	}catch(e){
	}
}

/* this triggers on DOM ready */
$().ready(function () {
			
/* if user clicked the back button when we had a modal window, redirect him */		
try{
var redirect_to_page =  $.cookie("redirect_to_page");
redirect_to_page = redirect_to_page || "";
$.cookie("redirect_to_page", null, {path:'/', expires:-1});
if(redirect_to_page!=""){
 document.location = redirect_to_page;
}	
} catch(e){
}

/* set the lang to en for accessibility and add the skip to main content link */
$("html").attr("lang","en");
try{
$("#tmp_header").append("<a name='main_content_area' id='main_content_area' tabindex='0'></a>");
$("#menustart").focus();
} catch(e){
}

/* AJAX CALL FOR QUOTES */
try{
if(FastQuote.FastQuote[0].last){
 var _quote = FastQuote.FastQuote[0].last;
 try{
	_quote = _quote + "";
	if(_quote.indexOf(".")!=-1){
	 var _quote_arr = _quote.split(".");
	 if(_quote_arr.length>1){
	  if(_quote_arr[1].length==1){
	   _quote = _quote_arr[0] + "." + _quote_arr[1] + "0";
	  } else if(_quote_arr[1].length>2){
	   _quote = _quote_arr[0] + "." + _quote_arr[1].substring(0,2);
	  }
	 }
	} else {
	  _quote = _quote + ".00";
	}
	} catch(e){
	}
	$("#quote").html("<strong style='font-size: 0.9em;'>JPM</strong> <span style='color: green;'>" + _quote + "</span>");
}
} catch(e){
 //$("#quote").html("<strong style='font-size: 0.9em;'>JPM</strong> <span style='color: green;'>N/A</span>");
}

/* ADD THE CHANGE FILTER JAVASCRIPT TO THE NEWS BLURB */
$(".news_category .more").each(function(n){
 var str_txt = $(this).text();
 var _parent = $(this).parent();
 $(this).remove();
 $(_parent).append(str_txt);
 //var _str_filter = $(this).attr("href");
 //$(this).attr("href","javascript: changeFilter(\"" + _str_filter + "\");");
}
);

/* IF FLASH VIDEO, ADD THE MODAL WINDOW CALL TO THE URL */
$(".cig_news_item").each(function(n){
 var _accessible_title = $(this).find(".news_title a:first").text();
 $(this).find(".news_type a:first").attr("title",_accessible_title);	
 		
 var _str_flash_video = $(this).find(".news_item a:first").attr("href");
 	 if(_str_flash_video.indexOf(".flv")!=-1 || _str_flash_video.indexOf(".mp4")!=-1){
 		//_str_flash_video_js = "javascript: showVideoPage(\"" + _str_flash_video + "\");";
		//&modal=true
 		_str_flash_video_js = "/corporate/Home/showMovie.htm?flv=" + _str_flash_video + "&TB_iframe=true&height=560&width=800";
		
		var class_1 = $(this).find(".news_item a:first").attr("class");		
		var class_2 = $(this).find(".news_title a:first").attr("class");	
 		var class_3 = $(this).find(".news_description a:first").attr("class");	
 		var class_4 = $(this).find(".news_type a:first").attr("class");	
 		var class_5 = $(this).find(".breaking_news_temp a:first").attr("class");	
		
		$(this).find(".news_item a:first").attr("href",_str_flash_video_js);		
		$(this).find(".news_title a:first").attr("href",_str_flash_video_js);	
		$(this).find(".news_description a:first").attr("href",_str_flash_video_js);		
 		$(this).find(".news_type a:first").attr("href",_str_flash_video_js);
 		$(this).find(".breaking_news_temp a:first").attr("href",_str_flash_video_js);	
		
		$(this).find(".news_item a:first").attr("class", class_1 + " thickbox");		
		$(this).find(".news_title a:first").attr("class", class_2 + " thickbox");	
 		$(this).find(".news_description a:first").attr("class", class_3 + " thickbox");	
 		$(this).find(".news_type a:first").attr("class", class_4 + " thickbox");	
 		$(this).find(".breaking_news_temp a:first").attr("class", class_5 + " thickbox");
	}
}
);

/* CREATE BREAKING NEWS IF THERE ARE ANY */
if($(".breaking_news_temp").length != 0){ 
 $(".breaking_news_temp").each(function(n){
 if(this.getAttribute("display_bn")=="true"){
  var _news_div = $(this).find("div:first");
  if($(_news_div).attr("class").indexOf("important")!=-1){
   chrono_breaking_news.push('<div class="breaking_news_important">' + $(_news_div).html() + '</div>');
  } else {
   chrono_breaking_news.push('<div class="breaking_news">' + $(_news_div).html() + '</div>');
  }
 }
 });
 $(".breaking_news_temp").remove();
 if(chrono_breaking_news.length>0){
 var _news_str = chrono_breaking_news[0];
 $("#breaking_news_wrapper").append('<div id="headlines" style="position: relative;">' + _news_str + '</div>');
 $("#breaking_news").attr("style","display: block;").animate({height: "18px"});
 //$("#news_container").animate({height: "575px"},{complete: changeBGHeight_575()});
 //$("#MIR_container").animate({height: "575px"},{complete: changeBGHeight_575()});
 $("#news_container").animate({height: "575px"});
 $("#MIR_container").animate({height: "575px"});
 showBreakingNews();
 } else {
 $("#breaking_news").attr("style","display: block;");
 //$("#filtered").animate({height: "550px"},{complete: changeBGHeight_575()});
 //$("#MIR_OS_container").animate({height: "550px"},{complete: changeBGHeight_575()});
 $("#filtered").animate({height: "550px"});
 $("#MIR_OS_container").animate({height: "550px"});
 } 
} else {
 //$("#breaking_news").attr("style","display: block;");
 //$("#filtered").animate({height: "550px"},{complete: changeBGHeight_575()});
 //$("#MIR_OS_container").animate({height: "550px"},{complete: changeBGHeight_575()});
 $("#filtered").animate({height: "550px"});
 $("#MIR_OS_container").animate({height: "550px"});
}

 //this should execute on 3rd level pages only
 /* ON 3RD LEVEL PAGES */
 /* EXTRACT AND CREATE A NEW DOM ELEMENT OUT OF THE NEWS BLURB */
 if(document.getElementById("right_content_text_wrapper")){
  $(".breaking_news_temp").remove();
  
  var filter_category = $("#filter_category").attr("category");
  filter_category = filter_category || "";
  var _blurbs_counter = 0;
  var _max_blurbs = $("#filter_category").attr("max_articles") || 3;
  if(_max_blurbs=="all"){
   _max_blurbs = 100000;
  }
  _max_blurbs = _max_blurbs - 0;
  var _ts_arr = [];
  var _cat_arr = [];
  var _type_arr = [];
  var _img_arr = [];
  var _msg_arr = [];
  var _urls_arr = [];
  var _ids_arr = [];
  var _target_string = 'target="_self"';
  
  $(".news_timestamp").each(function(n){
   _ts_arr.push(this.innerHTML);	
  });
  
  $(".cig_news_item .news_item").each(function(n){
   _cat_arr.push(this.getAttribute("category"));	
   _type_arr.push(this.getAttribute("type"));		 
   var _img = $(this).find(".news_img");
   var _img_src = $(_img).attr("src") || "";
   _img_arr.push(_img_src);		
  });
  $(".news_type a").each(function(n){
   var _href = this.getAttribute("href");
   var _target = this.getAttribute("target");
   var _id = this.getAttribute("id") || "";
   if(_target=="_blank"){
    _target_string = 'target="_blank"';
   }
   _href = _href || "";
   while(_href.indexOf("\"")!=-1){
    _href = _href.replace("\"","'");
   }
   _ids_arr.push(_id);
   _urls_arr.push(_href);													
  });
  
  $(".news_description").each(function(n){
   var a_txt = $(this).text();
   try{
    a_txt = a_txt.substring(0,a_txt.lastIndexOf("...")+1)
   } catch(e){
   }
   _msg_arr.push(a_txt);												
  });
  
  var _new_html_arr = [];
  
  $("#right_content_text_wrapper").empty();
  
  for(i=0;i<_ts_arr.length;i++){
   if(_cat_arr[i]==filter_category && _blurbs_counter<(_max_blurbs-1)){
   _blurbs_counter = _blurbs_counter + 1;
   var isThickbox = _urls_arr[i].indexOf(".flv")!=-1 || _urls_arr[i].indexOf(".mp4")!=-1;
   var _new_html = "";
   _new_html = _new_html + '<div class="news_content">';

   _new_html = _new_html + '<div class="news_content_wrapper">';
   _new_html = _new_html + '<div class="news_header">';
   _new_html = _new_html + '<div class="news_header_wrapper">';
   _new_html = _new_html + '<div class="news_date">' + _ts_arr[i] + '</div>';
   if(isThickbox){
    _new_html = _new_html + '<div class="news_category"><a id="' + _ids_arr[i] + '" pcg="" href="' + _urls_arr[i] + '" class="more thickbox">' + _cat_arr[i].capitalize() + '</a></div>';
    _new_html = _new_html + '<div class="news_type"><a id="' + _ids_arr[i] + '" pcg="" href="' + _urls_arr[i] + '" class="thickbox"><img src="/corporate/includes/images/' + _type_arr[i] + '.gif" alt="' + _type_arr[i] + '" /></a></div>';
   } else {
    _new_html = _new_html + '<div class="news_category"><a id="' + _ids_arr[i] + '" pcg="" href="' + _urls_arr[i] + '" class="more" ' + _target_string + '>' + _cat_arr[i].capitalize() + '</a></div>';
    _new_html = _new_html + '<div class="news_type"><a id="' + _ids_arr[i] + '" pcg="" href="' + _urls_arr[i] + '" ' + _target_string + '><img src="/corporate/includes/images/' + _type_arr[i] + '.gif" alt="' + _type_arr[i] + '" /></a></div>';
   }
   _new_html = _new_html + '</div>';
   _new_html = _new_html + '</div>';
   _new_html = _new_html + '<div class="news_body">';
   _new_html = _new_html + '<div class="news_body_wrapper">';
   if(isThickbox && _img_arr[i]!=""){
     _new_html = _new_html + '<div class="news_img"><a id="' + _ids_arr[i] + '" pcg="" href="' + _urls_arr[i] + '" class="thickbox"><img src="' + _img_arr[i] + '" alt="" /></a></div>';
	} else if(_img_arr[i]!=""){
	 _new_html = _new_html + '<div class="news_img"><a id="' + _ids_arr[i] + '" pcg="" href="' + _urls_arr[i] + '" ' + _target_string + '><img src="' + _img_arr[i] + '" alt="" /></a></div>';
	}
	if(isThickbox){
	 _new_html = _new_html + '<div class="news_msg">' + _msg_arr[i] + ' <a class="more thickbox" id="' + _ids_arr[i] + '" pcg="" href="' + _urls_arr[i] + '">Read More</a></div>';
	} else {
	 _new_html = _new_html + '<div class="news_msg">' + _msg_arr[i] + ' <a class="more" id="' + _ids_arr[i] + '" pcg="" href="' + _urls_arr[i] + '" ' + _target_string + '>Read More</a></div>';
	}
   _new_html = _new_html + '</div>';
   _new_html = _new_html + '</div>';
   _new_html = _new_html + '</div>';
   _new_html = _new_html + '</div>';
    //_new_html_arr.push(_new_html);
	$("#right_content_text_wrapper").append(_new_html);
   }
  }
  document.getElementById("tl_right_column").style.display= "block";
 }
 
/* MAKE CSS ADJUSTMENTS IF THERE ARE NO THUMBNAILS */
$(".cig_news_item").each(function(){
 try{
  if($(this).find(".news_img").attr("is_empty")=="true"){
   $(this).find(".news_copy").attr("style","width:620px; left:0;");
  }
 } catch(e){
 }
});

/* MAKE MIR ADJUSTMENTS IF THE BLURB HAS NO IMAGE */
$(".MIR_PES").each(function(){
 try{
  var _s = $(this).find(".MIR_OS_img").attr("src") || false;
  if(_s==false){
   $(this).find(".MIR_OS_story").attr("style","width:280px;");
  }
 } catch(e){
 }
});

/* HIGHLIGHT CURRENT PRIMARY NAVIGATION ITEM */
setCurrentNavItem();
/* IF ON SECONDARY PAGE, EXTRAPOLATE THE NAVIGATION DATA FROM THE COOKIE */
readNavigationCookie();
/* BEFORE UNLOAD, CREATE THE SECONDARY NAVIGATION COOKIE */
window.onbeforeunload = function(){createNavigationCookie()};
/* SHOW TABS IF THEY ARE PRESENT */
prepareTabs();

/* IF WE HAVE A QUERY STRING (search_string) CHANGE THE FRAME SRC TO POINT TO THE SEARCH PAGE */
if($.query.get("search_string")!=""){
try{
$("#search_frame").attr("src","https://www.chase.com/ccp/index.jsp?pg_name=ccpmapp/shared/assets/page/JPMC_Search_Page&q=" + $.query.get("search_string") + "&emptyQueryText=false");
}catch(e){
}
}

/* this shows the login button image if the user does not have flash */
function showLoginButton(){
 $("#login_button").html('<a id="lnk_login" onmouseout="clearAndSet_tmout(\'nav_log_in\');" onmouseover="navHighlight(\'nav_log_in\'); clear_tmout(); setCurrentNavLocationTitle(this.id);" onblur="clearAndSet_tmout(\'nav_log_in\');" onfocus="navHighlight(\'nav_log_in\'); clear_tmout(); closeMenu(\'nav_log_in\',\'menuend\');" href="javascript: clearAndSet_tmout(\'nav_log_in\')"><img src="/corporate/includes/images/log-in.gif" alt="Looking to Log In?" /></a>');
}

/* this creates the flahs login button */
/*
try{
 var fo = new SWFObject("/corporate/includes/multimedia/login.swf", "login", "256px", "22px", "9");
 fo.addParam("scale", "noscale");
 fo.addParam("wmode", "transparent");
 fo.write("login_button"); 
 if(!HAS_VALID_FLASH_VERSION){
  showLoginButton();
 }
} catch(e){
 showLoginButton();
}
*/

showLoginButton();

/* this focuses the first div for tabbings */
try{
 $("#logo_link img").focus();
} catch(e){
}

try{
if(!HAS_VALID_FLASH_VERSION){
 $("object[wmode]").remove();
 $("embed[wmode]").remove();
 $(".accessible").attr("style","filter: alpha(opacity=100); -khtml-opacity: 1; -moz-opacity: 1; opacity: 1; position: relative; left: 0;");
 $(".accessible img").attr("style","filter: alpha(opacity=100); -khtml-opacity: 1; -moz-opacity: 1; opacity: 1; position: relative; left: 0;");
 //make the home page hero fit the alt image height
 $("#hero").height($("#hero .accessible img").height());
}
} catch(e){
}

try{
 if ((navigator.userAgent.indexOf("iPad") > -1) || (navigator. userAgent.indexOf("iPhone") > -1))
 {
 $("#filtered").jScrollTouch();
 $("#MIR_OS_container").jScrollTouch();
 }
} catch(e){
}

triggerFlashMovie();
tagYouAreIt();

});
/* END on DOM ready */

/* THIS CAPTURES THE ENTER KEY FOR SEARCH */
$(document).keydown(function(event){
 /*enter*/
 if(event.keyCode==13 && $.trim(document.getElementById("searchfield").value)!=""){
  goToSearch();
 }
});

/* THIS GOES TO THE SEARCH PAGE */
function goToSearch(){
 document.location = "/corporate/Home/search.htm?search_string=" + document.getElementById("searchfield").value;
}

/* THIS FUNCTION CREATES THE SECONDARY NAVIGATION COOKIE */
/* THE FORM OF THE COOKIE IS  TWF_navigation_helper = PRIMARYNAV_SECONDARYNAV_SECONDARYNAVSUBITEM*/
function createNavigationCookie(){
 $.cookie("TWF_navigation_helper", (current_nav_item + "~" + current_left_nav_item + "~" + current_left_subnav_item ) );
}

/* THIS FUNCTION CREATES A COOKIE TO STORE THE CURRENT LOCATION OF THE PAGE*/
function redirectFromBackButtonCookie(){
 $.cookie("redirect_to_page", document.location.href, {path:'/', expires:10} );
}


function getNavElementFromCookie(_index){
 var TWF_navigation_helper =  $.cookie("TWF_navigation_helper");
 var TWF_nav_arr;
 try{
	 TWF_nav_arr = TWF_navigation_helper.split("~");
 } catch(e){
 }
 if(TWF_nav_arr){
  var _ret_val = "";
  try{
	_ret_val = TWF_nav_arr[_index];
  } catch(e){
   _ret_val = "";
  }
 }
 return _ret_val;
}

/* THIS FUNCTION READS THE NAVIGATITON COOKIE AND DIPLAYS THE RIGHT SECONDARY NAVIGATION ELEMENT */
function readNavigationCookie(){
  try{
   var main_nav_item = getNavElementFromCookie(0);
   var left_nav_item = getNavElementFromCookie(1);
   var left_subnav_item = getNavElementFromCookie(2);

   var _page_title = $(".title_blue").text();
   
   var _secondary_found = false;
   _page_title = _page_title || "";
   
   if(_page_title!=""){
   $(".primaryLink").each(function(n){
    if($.trim($(this).text())==$.trim(_page_title)){
	 this.style.background = "url(/corporate/includes/images/link_corporate_bg.jpg) repeat-y";
	 var _ret  = leftNavShowMore(this);
	 _secondary_found = true;
	}
   });
   }
   
   if(_page_title!="" && !_secondary_found){
	$(".secondaryLink").each(function(n){
     if($.trim(this.childNodes[0].nodeValue)==$.trim(_page_title)){
	 var _parent = $(this).parent();
	 var _t_counter = 0;
	 while($(_parent).attr("class")!="left_nav_primary"){
	  if(_t_counter>100){
	   break;
	  }
	  _parent = $(_parent).parent();
	  _t_counter = _t_counter + 1;
	 }
	 
	 //highlight and open left primary nav item
   	 $(_parent).find(".primaryLink").each(function(n){
      this.style.background = "url(/corporate/includes/images/link_corporate_bg.jpg) repeat-y";
	  var _ret  = leftNavShowMore(this);
	 });
	 
	 this.style.color = "#FFFFFF";
	 this.style.backgroundColor = "#648ABB";
	 _secondary_found = true;
	}
   });
   }
   
   if(!_secondary_found){
   //highlight and open left primary nav item
   $(".primaryLink").each(function(n){
   if($.trim(this.childNodes[0].nodeValue)==$.trim(left_nav_item)){
	this.style.background = "url(/corporate/includes/images/link_corporate_bg.jpg) repeat-y";
	var _ret  = leftNavShowMore(this);
   }
   });  
   $(".secondaryLink").each(function(n){
    if(this.childNodes[0].nodeValue==left_subnav_item){
	 this.style.color = "#FFFFFF";
	 this.style.backgroundColor = "#648ABB";
	}
   });
   }

  } catch(e){
  }
 
}

/* THIS FUNCTION HIGHLIGHTS THE PRIMARY NAVIGATION ITEM */
function setCurrentNavItem(){
 //nav item names
 //nav_home
 //nav_about_us
 //nav_investor_relations
 //nav_corporate_responsibility
 //nav_careers
 try{
 var _loc = document.location.pathname;
 var current_nav_item = "nav_home";
 if(_loc.toLowerCase().indexOf("/home/")!=-1){
  current_nav_item = "nav_home";
 } else if(_loc.toLowerCase().indexOf("/about-jpmc/")!=-1){
  current_nav_item = "nav_about_us";
 } else if(_loc.toLowerCase().indexOf("/corporate-responsibility/")!=-1){
  current_nav_item = "nav_corporate_responsibility";
 } else if(_loc.toLowerCase().indexOf("/way-forward/")!=-1){
  current_nav_item = "nav_home";
 } else {
  current_nav_item = "nav_home";
 }
 $.cookie('current_nav_item', current_nav_item);
 $("#" + current_nav_item).attr("style","background-color: #8f8f91;");
 $("#" + current_nav_item + " a:first").attr("style","color: #FFFFFF");
 hideSeparators(current_nav_item);
 } catch(e){
 }
}

/* THIS FUNCTION CHANGES THE FILTER IN THE FILTER DROPDOWN */
function changeFilter(_category){
 try{
 for(i=0;i<document.getElementById("category").options.length;i++){
  var _opt = document.getElementById("category").options[i].value;
  if(_category==_opt){
    document.getElementById("category").selectedIndex = i;
	break;
  }
 }
 } catch(e){
 }
 filter();
}

/* THIS FUNCTION HIDES THE SEPARATORS FROM CONTINGENT NAVIGATION ITEMS */
function hideSeparators(_section){
 $("#" + _section	 + " .nav_separator").attr("class","nav_separator hide");
 if(_section=="nav_about_us"){
  $("#nav_home .nav_separator").attr("class","nav_separator hide");
 } else  if(_section=="nav_investor_relations"){
  $("#nav_about_us .nav_separator").attr("class","nav_separator hide");
 } else  if(_section=="nav_corporate_responsibility"){
  $("#nav_investor_relations .nav_separator").attr("class","nav_separator hide");
 } else  if(_section=="nav_careers"){
  $("#nav_corporate_responsibility .nav_separator").attr("class","nav_separator hide");
 }
}

/* THIS FUNCTION SHOWS THE SEPARATORS OF CONTINGENT NAVIGATION ITEMS */
function showSeparators(_section){
 $("#" + _section + " .nav_separator").attr("class","nav_separator show");
 if(_section=="nav_about_us" && current_nav_item!="nav_home"){
  $("#nav_home .nav_separator").attr("class","nav_separator show");
 } else  if(_section=="nav_investor_relations" && current_nav_item!="nav_about_us"){
  $("#nav_about_us .nav_separator").attr("class","nav_separator show");
 } else  if(_section=="nav_corporate_responsibility" && current_nav_item!="nav_investor_relations"){
  $("#nav_investor_relations .nav_separator").attr("class","nav_separator show");
 } else  if(_section=="nav_careers" && current_nav_item!="nav_corporate_responsibility"){
  $("#nav_corporate_responsibility .nav_separator").attr("class","nav_separator show");
 }
}

/* THIS FUNCTION CLOSES THE BREAKING NEWS */
/*
function closeBreakingNews(){
 $("#breaking_news_wrapper").remove();
 $("#close_breaking_news").remove();
 $("#breaking_news").animate({height: "1px"});
 $("#news_container").animate({height: "275px"},{complete: changeBGHeight_275()});
 $("#MIR_container").animate({height: "275px"},{complete: changeBGHeight_275()});
}
*/

/* THIS FUNCTION ROTATES BREAKING NEWS HEADLINES */
/*
function headline_rotate() {
current_headline = (current_headline + 1);
if(current_headline==0){ 
 $("#headlines").attr("style", "position: relative; top: 0;");
} 
if(current_headline==headline_counter){
 $("#headlines").animate({top: "0"});
 current_headline = -1;
} else {
 $("#headlines").animate({top: (((current_headline) * -(_news_scroll_height) )) + "px"});
}
}
*/

/* THIS FUNCTION CHANGES THE HEIGHT OF LATEST NEWS AND MAKING IT REAL TO 258PX */
function changeBGHeight_258(){
$("#news_container").attr("style","background-image: url(/corporate/includes/images/bg_news_stories_258h.gif);");
$("#MIR_container").attr("style","background-image: url(/corporate/includes/images/bg_news_stories_258h.gif);");
}

function changeBGHeight_575(){
	$("#news_container").attr("style","background-image: url(/corporate/includes/images/bg_news_stories_575h.gif);");
	$("#MIR_container").attr("style","background-image: url(/corporate/includes/images/bg_news_stories_575h.gif);");
}

/* THIS FUNCTION CHANGES THE HEIGHT OF LATEST NEWS AND MAKING IT REAL TO 275PX */
function changeBGHeight_275(){
$("#news_container").attr("style","background-image: url(/corporate/includes/images/bg_news_stories_275h.gif);");
$("#MIR_container").attr("style","background-image: url(/corporate/includes/images/bg_news_stories_275h.gif);");
}

/* THIS FUNCTION SHOWS THE BREAKING NEWS */
function showBreakingNews(){
try{
if ($.browser.safari) {
 $("#breaking_news_wrapper").attr("style","display: block; top: 1px;").effect("slide",{ direction: "up" },1000);
 _news_scroll_height = 15;
} else {
 $("#breaking_news_wrapper").attr("style","display: block;").effect("slide",{ direction: "up" },1000);
}
} catch(e){
}  
}

/* THIS FUNCTION CLEARS THE TIMEOUT FOR MEGAMENUS */
function clear_tmout(){
 clearTimeout(_tmout);
}

/* THIS FUNCTION SETS THE TIMEOUT FOR THE MEGAMENUS */
function clearAndSet_tmout(_section){
 clearTimeout(_tmout);
 _tmout = setTimeout("navResetHighlight('" + _section + "')",500);  
}

function getMegamenuPosition(_section){
 var _pos = "left: -150px";
 if(_section=="nav_about_us"){
  _pos = "left: -150px";
 } else if(_section=="nav_investor_relations"){
  _pos = "left: -200px";
 } else if(_section=="nav_corporate_responsibility"){
  _pos = "left: -580px";
 } else if(_section=="nav_careers"){
  _pos = "left: -180px";
 } else if(_section=="nav_log_in"){
  _pos = "left: -280px";
 }
 return _pos;
}

/* THIS FUNCTION HIGHLIGHTS A PRIMARY NAVIGATION ITEM */
function navHighlight(_section){
 $("#" + _section + "_secondary").attr("style", getMegamenuPosition(_section));
 if(_last_section!=_section && _last_section!=""){
  navResetHighlight(_last_section);
 }
 _last_section = _section;	
 $("#" + _section + " .nav_arrow").attr("src","/corporate/includes/images/nav_arrow_black.gif");
 $("#" + _section).attr("style","background-color: #FFFFFF;");
 $("#" + _section + "_container a").attr("style","color: #000000");
 hideSeparators(_section);
 //$("#" + _section + "_secondary a:first").focus();
 $("#hero_dimmer").attr("class","transparent_hero");
 $("select").css("visibility","hidden");
}

/* THIS FUNCTION RESETS A NAVIGATITON ITEM TO ITS PREVIOUS STATE ON MOUSE OUT */
function navResetHighlight(_section){
 $("#" + _section + "_secondary").attr("style","left: -50000px;");
 $("#" + _section + " .nav_arrow").attr("src","/corporate/includes/images/nav_arrow_gray.gif");
 if(_section != current_nav_item){
  $("#" + _section).attr("style","background-color: none;");
  $("#" + _section + "_container a").attr("style","color: #FFFFFF");
  showSeparators(_section);
 } else {
  $("#" + _section).attr("style","background-color: #CCCCCC;");
  $("#" + _section + " a").attr("style","color: #333333");
 }
 $("#hero_dimmer").attr("class","");
  setCurrentNavItem();
  $("select").css("visibility","visible");
}


/* THIS FUNCTION RESETES ALL THE PRIMARY NAVIGATION ITEMS TO THEIR ORIGINAL STATES */
function resetNavSections(){
 $(".nav_arrow").attr("src","/corporate/includes/images/nav_arrow_gray.gif");
}

/* THIS FUNCTIONS SHOWS A MEGA MENU  */
function showNavSection(_section){
 resetNavSections();
 navHighlight(_section);
}

/* THIS FUNCTION RETURNS A RANDOM NUMBER */
function getRandom(seed,avoid_zero){ 
 var _num = Math.floor(Math.random()*seed);
 if(avoid_zero){
  _num = num+1;
 }
 return _num;
}


/* THIS FUNCTION CAPITALIZES ANY STRING */
String.prototype.capitalize = function(){
    return this.replace(/\w+/g, function(a){
        return a.charAt(0).toUpperCase() + a.substr(1).toLowerCase();
    });
};


/* THIS FUNCTION FILTERS ON THE CATEGORY */
function filter(){
 var _curr_cat_val = document.getElementById("category").options[document.getElementById('category').selectedIndex].value;
 
 if(_curr_cat_val=="separator"){
  return;
 }
 
 $(".news_item").each(function(n){
  var _cat_val = this.getAttribute("category");
  var _type_val = this.getAttribute("type");
 
  var _is_visibile_category = false;
  
  if(_curr_cat_val=="all"){
   _is_visibile_category = true;
   $("#filter_label").html("Sort By");
  } else if(_curr_cat_val=="video" || _curr_cat_val=="article" || _curr_cat_val=="pdf") {
   _is_visibile_category = (_type_val==_curr_cat_val);
   $("#filter_label").html("Show Pages of This Type ");
  } else  if(_curr_cat_val=="archives"){
   document.location.href = "/corporate/Home/news_archive.htm";
   $("#filter_label").html("Loading Archives... ");
  } else {
   _is_visibile_category = (_cat_val==_curr_cat_val);
   $("#filter_label").html("Sort By");
  }
  var _is_visible = ( _is_visibile_category);
  if(!_is_visible){
   this.style.display = "none";
  } else {
   this.style.display = "block";
  }  
 });
 
  var found_filters = false;
 
 $(".news_item").each(function(n){
  if(this.style.display == "block"){
   found_filters = true;
  }
 });
 
 if(!found_filters){
  document.getElementById("not_found").style.display = "block";
 } else {
  document.getElementById("not_found").style.display = "none";
 }
 
}

/* THIS FUNCTION HIDE SECONDARY NAV ITEMS */
function hideLeftNavItems(){
 $(".left_nav_secondary").attr("style","display: none;");
 $(".primaryLink").attr("style","background: none;");
 //$(".primaryLink").attr("style","");
}

/* THIS FUNCTION SHOWS SECONDARY NAV ITEMS */
function showleftNavSubItem(_my_ele){
 //_my_ele.style.display = "block";
 $(_my_ele).slideDown(500);
}

/* THIS FUNCTION SETS A SECONDARY SUB NAV ITEM */
function setSubnavItem(link_ele){
 var _my_ele_text = link_ele.childNodes[0].nodeValue;
 current_left_subnav_item = _my_ele_text;
 return true;
}

/* THIS FUNCTION OPENS A SECONDARY SUB NAV ITEM IF THERE ARE SUB ITEMS */
function leftNavShowMore(link_ele){
 try{
 if(left_nav_ele!=link_ele){
  hideLeftNavItems();
  var container_div = link_ele.parentNode;
  link_ele.style.background = "url(/corporate/includes/images/link_corporate_bg.jpg) repeat-y";
  var _my_ele = container_div.getElementsByTagName("div")[0];
  var _my_ele_text = container_div.getElementsByTagName("a")[0].childNodes[0];
  current_left_nav_item = _my_ele_text.nodeValue;
  showleftNavSubItem(_my_ele);
 }
 left_nav_ele = link_ele;
 return true;
 } catch(e){
  return true;
 }
}

/* THIS FUNCTION OPENS A SECONDARY SUB NAV ITEM IF THERE ARE SUB ITEMS onfocus*/
function leftNavShowMoreFocus(link_ele){
 try{
  $(".primaryLink").attr("style","background: none;");
  var container_div = link_ele.parentNode;
  link_ele.style.background = "url(/corporate/includes/images/link_corporate_bg.jpg) repeat-y";
  var _my_ele = container_div.getElementsByTagName("div")[0];
  var _my_ele_text = container_div.getElementsByTagName("a")[0].childNodes[0];
  current_left_nav_item = _my_ele_text.nodeValue;
  left_nav_ele = link_ele;
 return true;
 } catch(e){
  return true;
 }
}

/* THIS FUNCTION OPENS THE MODAL WINDOW FOR THE VIDEO PLAYER */
function showVideoPage(_m_name){
 /*
 _m_name = _m_name.substring(_m_name.lastIndexOf("/")+1);
 var _picture_name = _m_name.substring(0, _m_name.length-4)+".jpg";
 twfVideoData = [_m_name, _picture_name, 620, 350];
 tb_show("flv_window","/corporate/Home/showMovie.htm?KeepThis=true&TB_iframe=true&height=560&width=800&modal=true","");
 */
 tb_show("flv_window","/corporate/Home/showMovie.htm?flv=" + _m_name + "&TB_iframe=true&height=560&width=800","");
}

/* THIS FUNCTION SETS THE STYLES FOR TABS LINKS AND REMOVES UNUSED TABS */
function prepareTabs(){
 try{
   $(".j_tab").each(function(n){
	var original_class_left = $(this).find("div:first").attr("class");	
	var original_class_right = $(this).find("div:nth-child(2)").attr("class");						 
    $(this).attr("original_class_left",original_class_left);
	$(this).attr("original_class_right",original_class_right);
   });
   $(".j_tab").bind("mouseover",function(evt){
    $(this).find("div:first").attr("class","j_tab_left_hover");
	$(this).find("div:div:nth-child(2)").attr("class","j_tab_right_hover");
   });
   $(".j_tab").bind("mouseout",function(evt){
    var original_class_left = $(this).attr("original_class_left");
	var original_class_right = $(this).attr("original_class_right");
	$(this).find("div:first").attr("class",original_class_left);
	$(this).find("div:div:nth-child(2)").attr("class",original_class_right);
   });
 } catch(e){
 }
 
 var contentTabs = 0;
 
 $(".tab_link").each(function(n){
  $(this).attr("href","javascript: showTab(" + n + "); setActiveTab(" + n + ");");
  var _text = $(this).find("div").text();
  _text = $.trim(_text);
  if(_text.toLowerCase().indexOf("no text content entered...") != -1){
   _text = "";
  }
  $(this).empty();
  $(this).text(_text);
  if(!_text=="" ){
   contentTabs = contentTabs + 1;
  }
 });
 
 $(".j_tab").each(function(n){
  if(n>=contentTabs){
   $(this).remove();
  }
 });
 
 $(".j_tab_content").each(function(n){
  if(n>=contentTabs){
   $(this).remove();
  }
 });
 
 showTab(0);
 $("#j_tabs").attr("style","display: block;");
}

/* THIS FUNCTION SETS THE ACTIVE TAB */
function setActiveTab(_tab_n){
 $(".j_tab").each(function(n){
  var original_class_left = "j_tab_left";	
  var original_class_right = "j_tab_right";
  $(this).find("div:first").attr("class",original_class_left);
  $(this).find("div:nth-child(2)").attr("class",original_class_right);
  $(this).attr("original_class_left",original_class_left);
  $(this).attr("original_class_right",original_class_right);
 });
 
 var original_class_left = "j_tab_left_active";	
 var original_class_right = "j_tab_right_active";
 $(".j_tab:nth-child(" + (_tab_n+1) + ") div:first").attr("class",original_class_left);
 $(".j_tab:nth-child(" + (_tab_n+1) + ") div:nth-child(2)").attr("class",original_class_right);
 $(".j_tab:nth-child(" + (_tab_n+1) + ") ").attr("original_class_left",original_class_left);
 $(".j_tab:nth-child(" + (_tab_n+1) + ") ").attr("original_class_right",original_class_right);
}

/* THIS FUNCTION HIDES ALL TAB SECTIONS */
function hideTabs(){
 $(".j_tab_content").attr("style","display: none");
}

/* THIS FUNCTION SHOWS A TAB SECTION */
function showTab(_section_num){
  try{
  for(i=0;i<5;i++){
   if(i==_section_num){
    ($(".j_tab_content")[i]).style.display = "block";
   } else {
	($(".j_tab_content")[i]).style.display = "none";
   }
  }
  } catch(e){
  }
}

/* this sets the top level title for accessibility */
function setCurrentNavLocationTitle(ele_id){
	$("a[title=Current Selection Location]").attr("title","Primary Section");
	$("#" + ele_id).attr("title","Current Selection Location");
}

/* ACCESSIBILITY NOTE: The following function uses the Escape or Spacebar key to close menu flyouts and put focus on next element. Next element is an anchor tag defined by second variable in closeMenu function call. Hidden text is placed just prior to the first flyout menu item to inform screen reader users how to operate the mega-menu elements. Also note this function is called by both primary and secondary menu links. An additional hidden <a> tag was added after final log in menu link, but within the megamenu coding to keep this functionality within the megamenu element. See additional comments with ACCESSIBILITY NOTE: for more information. */
function closeMenu(act1,loc){
	var elem = document.getElementById(loc);
	document.onkeypress=function(e)
	{	
		var e=window.event || e;
		var keyunicode=e.charCode || e.keyCode || e.which;
		if ((keyunicode=="27")||(keyunicode=="32")){
			clearAndSet_tmout(act1);
			elem.focus();
			return false;
		}
	};
}

/* added to display movie on any page */
function triggerFlashMovie(){
 try{
 var flv_movie_name = $.query.get("flv_movie_name");
 var ad_modal = $.query.get("ad_modal");

 if(flv_movie_name){
	 tb_show("","/corporate/Home/showMovie.htm?flv=/corporate/includes/multimedia/" + flv_movie_name + "&TB_iframe=true&height=560&width=800","");
 } else if(ad_modal){
         tb_show("","/corporate/" + ad_modal + "?TB_iframe=true&height=560&width=800","");
 }
 } catch(e){
 }
}
