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;
}

/* this triggers on DOM ready */
$j().ready(function () {
			
/* ADD THE CHANGE FILTER JAVASCRIPT TO THE NEWS BLURB */
$j(".news_category .more").each(function(n){
 var _str_filter = $j(this).attr("href");
 $j(this).attr("href","javascript: changeFilter(\"" + _str_filter + "\");");
}
);

/* IF FLASH VIDEO, ADD THE MODAL WINDOW CALL TO THE URL */
$j(".cig_news_item").each(function(n){
 var _accessible_title = $j(this).find(".news_title a:first").text();
 $j(this).find(".news_type a:first").attr("title",_accessible_title);	
 		
 var _str_flash_video = $j(this).find(".news_item a:first").attr("href");
 	 if(_str_flash_video.indexOf(".flv")!=-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 = $j(this).find(".news_item a:first").attr("class");		
		var class_2 = $j(this).find(".news_title a:first").attr("class");	
 		var class_3 = $j(this).find(".news_description a:first").attr("class");	
 		var class_4 = $j(this).find(".news_type a:first").attr("class");	
 		var class_5 = $j(this).find(".breaking_news_temp a:first").attr("class");	
		
		$j(this).find(".news_item a:first").attr("href",_str_flash_video_js);		
		$j(this).find(".news_title a:first").attr("href",_str_flash_video_js);	
		$j(this).find(".news_description a:first").attr("href",_str_flash_video_js);		
 		$j(this).find(".news_type a:first").attr("href",_str_flash_video_js);
 		$j(this).find(".breaking_news_temp a:first").attr("href",_str_flash_video_js);	
		
		$j(this).find(".news_item a:first").attr("class", class_1 + " thickbox");		
		$j(this).find(".news_title a:first").attr("class", class_2 + " thickbox");	
 		$j(this).find(".news_description a:first").attr("class", class_3 + " thickbox");	
 		$j(this).find(".news_type a:first").attr("class", class_4 + " thickbox");	
 		$j(this).find(".breaking_news_temp a:first").attr("class", class_5 + " thickbox");
	}
}
);

/* CREATE BREAKING NEWS IF THERE ARE ANY */
if($j(".breaking_news_temp").length != 0){ 
 $j(".breaking_news_temp").each(function(n){
 if(this.getAttribute("display_bn")=="true"){
  var _news_div = $j(this).find("div:first");
  if($j(_news_div).attr("class").indexOf("important")!=-1){
   chrono_breaking_news.push('<div class="breaking_news_important">' + $j(_news_div).html() + '</div>');
  } else {
   chrono_breaking_news.push('<div class="breaking_news">' + $j(_news_div).html() + '</div>');
  }
 }
 });
 $j(".breaking_news_temp").remove();
 if(chrono_breaking_news.length>0){
 var _news_str = chrono_breaking_news[0];
 $j("#breaking_news_wrapper").append('<div id="headlines" style="position: relative;">' + _news_str + '</div>');
 $j("#breaking_news").attr("style","display: block;").animate({height: "18px"});
 $j("#news_container").animate({height: "258px"},{complete: changeBGHeight_258()});
 $j("#MIR_container").animate({height: "258px"},{complete: changeBGHeight_258()});
 showBreakingNews();
 } else {
 $j("#breaking_news").attr("style","display: block;");
 $j("#filtered").animate({height: "250px"},{complete: changeBGHeight_275()});
 $j("#MIR_OS_container").animate({height: "250px"},{complete: changeBGHeight_275()});
 } 
} else {
 //$j("#breaking_news").attr("style","display: block;");
 $j("#filtered").animate({height: "250px"},{complete: changeBGHeight_275()});
 $j("#MIR_OS_container").animate({height: "250px"},{complete: changeBGHeight_275()});
}

 //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")){
  $j(".breaking_news_temp").remove();
  
  var filter_category = $j("#filter_category").attr("category");
  filter_category = filter_category || "";
  var _blurbs_counter = 0;
  var _max_blurbs = $j("#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 _target_string = 'target="_self"';
  
  $j(".news_timestamp").each(function(n){
   _ts_arr.push(this.innerHTML);	
  });
  
  $j(".cig_news_item .news_item").each(function(n){
   _cat_arr.push(this.getAttribute("category"));	
   _type_arr.push(this.getAttribute("type"));		 
   var _img = $j(this).find(".news_img");
   var _img_src = $j(_img).attr("src") || "";
   _img_arr.push(_img_src);		
  });
  $j(".news_type a").each(function(n){
   var _href = this.getAttribute("href");
   var _target = this.getAttribute("target");
   if(_target=="_blank"){
    _target_string = 'target="_blank"';
   }
   _href = _href || "";
   while(_href.indexOf("\"")!=-1){
    _href = _href.replace("\"","'");
   }
   _urls_arr.push(_href);													
  });
  
  $j(".news_description").each(function(n){
   var a_txt = $j(this).text();
   try{
    a_txt = a_txt.substring(0,a_txt.lastIndexOf("...")+1)
   } catch(e){
   }
   _msg_arr.push(a_txt);												
  });
  
  var _new_html_arr = [];
  
  $j("#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;
   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 href="' + _urls_arr[i] + '" class="more thickbox">' + _cat_arr[i].capitalize() + '</a></div>';
    _new_html = _new_html + '<div class="news_type"><a href="' + _urls_arr[i] + '" class="thickbox"><img src="/jpmc/images/' + _type_arr[i] + '.gif" alt="' + _type_arr[i] + '" /></a></div>';
   } else {
    _new_html = _new_html + '<div class="news_category"><a href="' + _urls_arr[i] + '" class="more" ' + _target_string + '>' + _cat_arr[i].capitalize() + '</a></div>';
    _new_html = _new_html + '<div class="news_type"><a href="' + _urls_arr[i] + '" ' + _target_string + '><img src="/jpmc/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 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 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" href="' + _urls_arr[i] + '">Read More</a></div>';
	} else {
	 _new_html = _new_html + '<div class="news_msg">' + _msg_arr[i] + ' <a class="more" 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);
	$j("#right_content_text_wrapper").append(_new_html);
   }
  }
  document.getElementById("tl_right_column").style.display= "block";
 }
 
/* MAKE CSS ADJUSTMENTS IF THERE ARE NO THUMBNAILS */
$j(".cig_news_item").each(function(){
 try{
  if($j(this).find(".news_img").attr("is_empty")=="true"){
   $j(this).find(".news_copy").attr("style","width:620px; left:0;");
  }
 } catch(e){
 }
});

/* MAKE MIR ADJUSTMENTS IF THE BLURB HAS NO IMAGE */
$j(".MIR_PES").each(function(){
 try{
  var _s = $j(this).find(".MIR_OS_img").attr("src") || false;
  if(_s==false){
   $j(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($j.query.get("search_string")!=""){
try{
$j("#search_frame").attr("src","https://www.chase.com/ccp/index.jsp?pg_name=ccpmapp/shared/assets/page/JPMC_Search_Page&q=" + $j.query.get("search_string") + "&emptyQueryText=false");
}catch(e){
}
}

/* this shows the login button image if the user does not have flash */
function showLoginButton(){
 $j("#login_button").append('<a title="Primary Navigation Item" onmouseout="clearAndSet_tmout(\'nav_log_in\');" onmouseover="navHighlight(\'nav_log_in\'); clear_tmout();" onblur="clearAndSet_tmout(\'nav_log_in\');" onfocus="navHighlight(\'nav_log_in\'); clear_tmout();" href="javascript: clearAndSet_tmout(\'nav_log_in\')"><img src="/jpmc/images/log-in.gif" alt="login" /></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{
 $j("#logo_link img").focus();
} catch(e){
}

try{
if(!HAS_VALID_FLASH_VERSION){
 $j(".accessible").attr("style","filter: alpha(opacity=100); -khtml-opacity: 1; -moz-opacity: 1; opacity: 1; left: 0;");
 $j(".accessible img").attr("style","filter: alpha(opacity=100); -khtml-opacity: 1; -moz-opacity: 1; opacity: 1;");
}
} catch(e){
}
  
});
/* END on DOM ready */

/* THIS CAPTURES THE ENTER KEY FOR SEARCH */
$j(document).keydown(function(event){
 /*enter*/
 if(event.keyCode==13 && $j.trim(document.getElementById("searchfield").value)!=""){
  goToSearch();
 }
});

/* THIS GOES TO THE SEARCH PAGE */
function goToSearch(){
 document.location = "http://www.jpmorganchase.com/corporate/Home/search.htm?search_string=" + document.getElementById("searchfield").value;
}

/* THIS FUNCTION CREATE THE SECONDARY NAVIGATION COOKIE */
/* THE FORM OF THE COOKIE IS  TWF_navigation_helper = PRIMARYNAV_SECONDARYNAV_SECONDARYNAVSUBITEM*/
function createNavigationCookie(){
 //alert(current_nav_item + "\n" + current_left_nav_item + "\n" + current_left_subnav_item )
 $j.cookie("TWF_navigation_helper", (current_nav_item + "~" + current_left_nav_item + "~" + current_left_subnav_item ) );
}


function getNavElementFromCookie(_index){
 var TWF_navigation_helper =  $j.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 = $j(".title_blue").text();
   
   var _secondary_found = false;
   _page_title = _page_title || "";
   
   if(_page_title!=""){
   $j(".primaryLink").each(function(n){
    if($j.trim($j(this).text())==$j.trim(_page_title)){
	 this.style.background = "url(/jpmc/images/link_corporate_bg.jpg) repeat-y";
	 var _ret  = leftNavShowMore(this);
	 _secondary_found = true;
	}
   });
   }
   
   if(_page_title!="" && !_secondary_found){
	$j(".secondaryLink").each(function(n){
     if($j.trim(this.childNodes[0].nodeValue)==$j.trim(_page_title)){
	 var _parent = $j(this).parent();
	 var _t_counter = 0;
	 while($j(_parent).attr("class")!="left_nav_primary"){
	  if(_t_counter>100){
	   break;
	  }
	  _parent = $j(_parent).parent();
	  _t_counter = _t_counter + 1;
	 }
	 
	 //highlight and open left primary nav item
   	 $j(_parent).find(".primaryLink").each(function(n){
      this.style.background = "url(/jpmc/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
   $j(".primaryLink").each(function(n){
   if($j.trim(this.childNodes[0].nodeValue)==$j.trim(left_nav_item)){
	this.style.background = "url(/jpmc/images/link_corporate_bg.jpg) repeat-y";
	var _ret  = leftNavShowMore(this);
   }
   });  
   $j(".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("/jpmorganchase/")!=-1){
  current_nav_item = "nav_investor_relations";
 } 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";
 }
 $j.cookie('current_nav_item', current_nav_item);
 $j("#" + current_nav_item).attr("style","background-color: #8f8f91;");
 $j("#" + current_nav_item + " a:first").attr("style","color: #FFFFFF");
 $j("#" + current_nav_item + " a:first").attr("title","Current section location. Primary Navigation Item.");
 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){
 $j("#" + _section	 + " .nav_separator").attr("class","nav_separator hide");
 if(_section=="nav_about_us"){
  $j("#nav_home .nav_separator").attr("class","nav_separator hide");
 } else  if(_section=="nav_investor_relations"){
  $j("#nav_about_us .nav_separator").attr("class","nav_separator hide");
 } else  if(_section=="nav_corporate_responsibility"){
  $j("#nav_investor_relations .nav_separator").attr("class","nav_separator hide");
 } else  if(_section=="nav_careers"){
  $j("#nav_corporate_responsibility .nav_separator").attr("class","nav_separator hide");
 }
}

/* THIS FUNCTION SHOWS THE SEPARATORS OF CONTINGENT NAVIGATION ITEMS */
function showSeparators(_section){
 $j("#" + _section + " .nav_separator").attr("class","nav_separator show");
 if(_section=="nav_about_us" && current_nav_item!="nav_home"){
  $j("#nav_home .nav_separator").attr("class","nav_separator show");
 } else  if(_section=="nav_investor_relations" && current_nav_item!="nav_about_us"){
  $j("#nav_about_us .nav_separator").attr("class","nav_separator show");
 } else  if(_section=="nav_corporate_responsibility" && current_nav_item!="nav_investor_relations"){
  $j("#nav_investor_relations .nav_separator").attr("class","nav_separator show");
 } else  if(_section=="nav_careers" && current_nav_item!="nav_corporate_responsibility"){
  $j("#nav_corporate_responsibility .nav_separator").attr("class","nav_separator show");
 }
}

/* THIS FUNCTION CLOSES THE BREAKING NEWS */
/*
function closeBreakingNews(){
 $j("#breaking_news_wrapper").remove();
 $j("#close_breaking_news").remove();
 $j("#breaking_news").animate({height: "1px"});
 $j("#news_container").animate({height: "275px"},{complete: changeBGHeight_275()});
 $j("#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){ 
 $j("#headlines").attr("style", "position: relative; top: 0;");
} 
if(current_headline==headline_counter){
 $j("#headlines").animate({top: "0"});
 current_headline = -1;
} else {
 $j("#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(){
$j("#news_container").attr("style","background-image: url(/jpmc/images/bg_news_stories_258h.gif);");
$j("#MIR_container").attr("style","background-image: url(/jpmc/images/bg_news_stories_258h.gif);");
}

/* THIS FUNCTION CHANGES THE HEIGHT OF LATEST NEWS AND MAKING IT REAL TO 275PX */
function changeBGHeight_275(){
$j("#news_container").attr("style","background-image: url(/jpmc/images/bg_news_stories_275h.gif);");
$j("#MIR_container").attr("style","background-image: url(/jpmc/images/bg_news_stories_275h.gif);");
}

/* THIS FUNCTION SHOWS THE BREAKING NEWS */
function showBreakingNews(){
try{
if ($j.browser.safari) {
 $j("#breaking_news_wrapper").attr("style","display: block; top: 1px;").effect("slide",{ direction: "up" },1000);
 _news_scroll_height = 15;
} else {
 $j("#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){
 $j("#" + _section + "_secondary").attr("style", getMegamenuPosition(_section));
 if(_last_section!=_section && _last_section!=""){
  navResetHighlight(_last_section);
 }
 _last_section = _section;	
 $j("#" + _section + " .nav_arrow").attr("src","/jpmc/images/nav_arrow_black.gif");
 $j("#" + _section).attr("style","background-color: #FFFFFF;");
 $j("#" + _section + "_container a").attr("style","color: #000000");
 hideSeparators(_section);
 $j("#" + _section + "_secondary a:first").focus();
 $j("#hero_dimmer").attr("class","transparent_hero");
 $j("select").css("visibility","hidden");
}

/* THIS FUNCTION RESETS A NAVIGATITON ITEM TO ITS PREVIOUS STATE ON MOUSE OUT */
function navResetHighlight(_section){
 $j("#" + _section + "_secondary").attr("style","left: -50000px;");
 $j("#" + _section + " .nav_arrow").attr("src","/jpmc/images/nav_arrow_gray.gif");
 if(_section != current_nav_item){
  $j("#" + _section).attr("style","background-color: none;");
  $j("#" + _section + "_container a").attr("style","color: #FFFFFF");
  showSeparators(_section);
 } else {
  $j("#" + _section).attr("style","background-color: #CCCCCC;");
  $j("#" + _section + " a").attr("style","color: #333333");
 }
 $j("#hero_dimmer").attr("class","");
  setCurrentNavItem();
  $j("select").css("visibility","visible");
}


/* THIS FUNCTION RESETES ALL THE PRIMARY NAVIGATION ITEMS TO THEIR ORIGINAL STATES */
function resetNavSections(){
 $j(".nav_arrow").attr("src","/jpmc/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;
 }
 
 $j(".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;
   $j("#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);
   $j("#filter_label").html("Show Pages of This Type ");
  } else  if(_curr_cat_val=="archives"){
   document.location.href = "/corporate/Home/news_archive.htm";
   $j("#filter_label").html("Loading Archives... ");
  } else {
   _is_visibile_category = (_cat_val==_curr_cat_val);
   $j("#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;
 
 $j(".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(){
 $j(".left_nav_secondary").attr("style","display: none;");
 $j(".primaryLink").attr("style","background: none;");
 //$j(".primaryLink").attr("style","");
}

/* THIS FUNCTION SHOWS SECONDARY NAV ITEMS */
function showleftNavSubItem(_my_ele){
 //_my_ele.style.display = "block";
 $j(_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(/jpmc/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{
  $j(".primaryLink").attr("style","background: none;");
  var container_div = link_ele.parentNode;
  link_ele.style.background = "url(/jpmc/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(".j_tab").each(function(n){
	var original_class_left = $j(this).find("div:first").attr("class");	
	var original_class_right = $j(this).find("div:nth-child(2)").attr("class");						 
    $j(this).attr("original_class_left",original_class_left);
	$j(this).attr("original_class_right",original_class_right);
   });
   $j(".j_tab").bind("mouseover",function(evt){
    $j(this).find("div:first").attr("class","j_tab_left_hover");
	$j(this).find("div:div:nth-child(2)").attr("class","j_tab_right_hover");
   });
   $j(".j_tab").bind("mouseout",function(evt){
    var original_class_left = $j(this).attr("original_class_left");
	var original_class_right = $j(this).attr("original_class_right");
	$j(this).find("div:first").attr("class",original_class_left);
	$j(this).find("div:div:nth-child(2)").attr("class",original_class_right);
   });
 } catch(e){
 }
 
 var contentTabs = 0;
 
 $j(".tab_link").each(function(n){
  $j(this).attr("href","javascript: showTab(" + n + "); setActiveTab(" + n + ");");
  var _text = $j(this).find("div").text();
  _text = $j.trim(_text)
  if(_text.toLowerCase().indexOf("no text content entered...") != -1){
   _text = "";
  }
  $j(this).empty();
  $j(this).text(_text);
  if(!_text=="" ){
   contentTabs = contentTabs + 1;
  }
 });
 
 $j(".j_tab").each(function(n){
  if(n>=contentTabs){
   $j(this).remove();
  }
 });
 
 $j(".j_tab_content").each(function(n){
  if(n>=contentTabs){
   $j(this).remove();
  }
 });
 
 showTab(0);
 $j("#j_tabs").attr("style","display: block;");
}

/* THIS FUNCTION SETS THE ACTIVE TAB */
function setActiveTab(_tab_n){
 $j(".j_tab").each(function(n){
  var original_class_left = "j_tab_left";	
  var original_class_right = "j_tab_right";
  $j(this).find("div:first").attr("class",original_class_left);
  $j(this).find("div:nth-child(2)").attr("class",original_class_right);
  $j(this).attr("original_class_left",original_class_left);
  $j(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(".j_tab:nth-child(" + (_tab_n+1) + ") div:first").attr("class",original_class_left);
 $j(".j_tab:nth-child(" + (_tab_n+1) + ") div:nth-child(2)").attr("class",original_class_right);
 $j(".j_tab:nth-child(" + (_tab_n+1) + ") ").attr("original_class_left",original_class_left);
 $j(".j_tab:nth-child(" + (_tab_n+1) + ") ").attr("original_class_right",original_class_right);
}

/* THIS FUNCTION HIDES ALL TAB SECTIONS */
function hideTabs(){
 $j(".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(".j_tab_content")[i]).style.display = "block";
   } else {
	($j(".j_tab_content")[i]).style.display = "none";
   }
  }
  } catch(e){
  }
}

function imgRollover(loadImg, onImg)
{
	// prevent this routine from running twice
	if (! loadImg.outImg)
	{
		// set src of the "on" image
		loadImg.outImg = new Image();
		loadImg.outImg.src = loadImg.src;
		loadImg.onmouseout=img_mouseOut;

		// set the src of the "over" image
		loadImg.overImg = new Image();
		loadImg.overImg.src = onImg
		loadImg.onmouseover=img_mouseOver;
	}
}
     
// event handler for OnMouseOut
function img_mouseOut()  {this.src = this.outImg.src;}
     
// event handler for OnMouseOver
function img_mouseOver() {this.src = this.overImg.src;}

currentemail=0;
function email_link()
{
  if (currentemail==0)
  {
	$j("#bodyContent").hide();
	$j("#emailContent").show();
	currentemail=1;
  }
  else
  {
	$j("#bodyContent").show();
	$j("#emailContent").hide();
	currentemail=0;
  }
}


