﻿/* Add delay to top nav drop down */
/* Top Navigation Rollover Delay - Works with jQuery hoverIntent */
$(document).ready(function() {
						   
$(".rollover_delay").addClass("inactive_state");						   
						   
//On Hover Over
function megaHoverOver(){
    $(this).addClass("active_state");
	$(this).removeClass("inactive_state");
}
//On Hover Out
function megaHoverOut(){
	$(this).removeClass("active_state");
  	$(this).addClass("inactive_state");
}

//Set custom configurations
var config = {
     sensitivity: 4, // number = sensitivity threshold (must be 1 or higher)
     interval: 200, // number = milliseconds for onMouseOver polling interval
     over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
     timeout: 500, // number = milliseconds delay before onMouseOut
     out: megaHoverOut // function = onMouseOut callback (REQUIRED)
};

$(".rollover_delay").hoverIntent(config); //Trigger Hover intent with custom configurations

});

/* Code to all hover dropdown for IE6 - Currently used for country nav and top navigation dropdown */

//Conditional to put script in IE6 browsers
var isIE6 = (navigator.userAgent.toLowerCase().substr(25,6)=="msie 6") ? true : false;

if (isIE6 == true ) {

	// JS used to make 
	
	function sfHover(element_id) {
		  var sfEls = document.getElementById(element_id).getElementsByTagName("li");
		  for (var i=0; i<sfEls.length; i++) {
              sfEls[i].onmouseover=function() {
                 this.className+=" sfhover";
              }
              sfEls[i].onmouseout=function() {
                 this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
    	}
 	  }
	}
// Add the IDs that you want to use the hover function below - CSS must have a hover "sfhover" class too
	function sfStart() {
	  sfHover("countrynav");
	  sfHover("navbar");
	}
	if (window.attachEvent) window.attachEvent("onload", sfStart);
}

/* Pop-up Window */
function openWindow ( url, width, height, options, name ) {
  if ( ! width ) width = 640;
  if ( ! height ) height = 420;
  if ( ! options ) options = "scrollbars=yes,menubar=yes,toolbar=yes,location=yes,status=yes,resizable=yes";
  if ( ! name ) name = "outsideSiteWindow";
  var newWin = window.open( url, name, "width=" + width + ",height=" + height + "," + options );
} // end function openWindow

function checkSiteSearchLanguage(){
  var form_name = 'search';
  var lang = document.forms[form_name].elements['search_lang_selection'].value;

  if (lang == 'en'){
     document.forms[form_name].setAttribute("target","_blank");
     submit_action = 'http://www.mathworks.com/cgi-bin/texis/webinator/search/';
  }else{
     document.forms[form_name].removeAttribute("target");
     submit_action = '/cgi-bin/texis/webinator/search_jp/';
  }

  document.forms[form_name].action = submit_action;
}

/* Print this Page */
function printWindow () {
   bV = parseInt(navigator.appVersion)
   if (bV >= 4) window.print()
} // end function printWindow


/* Onclick Omniture Code for Auto-Redirect testing */
function addOmnitureCode(txt) {
	 var s =s_gi(s_account);  
	s.linkTrackVars='prop36';
//	s.linkTrackEvents='event56';
	
	s.prop36= domain + "_" + txt; //please pick appropriate value from the spreadsheet
	//s.events='event56';
	s.tl(this,'o','Redirects Cookie');
	
}
/* This adds classes of even and odd for datatables with the zebra class */
$(document).ready(function(){
	$(".zebra tbody tr:nth-child(even)").addClass("even");
	$(".zebra tbody tr:nth-child(odd)").addClass("odd");
}); 

/*This is for toggling content (expand/collapse) */
$(document).ready(function(){
	$(".toggle_content").hide();
	$(".toggle_container .toggle_selector").toggle(function(){
		$(this).addClass("active");
		}, function () {
			$(this).removeClass("active");
		});
	$(".toggle_container .toggle_selector").click(function(){
		$(this).next(".toggle_content").slideToggle("slow,");
	});
});
