(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

var product_tabs_cat	= 0;
var product_tabs_prod	= 0;
var persona_box			= 0;
var brandbox_tabs		= 0;

	$j = jQuery.noConflict();
	
	var cfg = ($j.hoverintent = {
		sensitivity: 5,
		interval: 20
	});
	
	$j.event.special.hoverintent = {
		setup: function() {
			$j(this).bind("mouseover", jQuery.event.special.hoverintent.handler);
		},
		teardown: function() {
			$j(this).unbind("mouseover", jQuery.event.special.hoverintent.handler);
		},
		handler: function(event) {
			event.type = "hoverintent";
			var self = this,
				args = arguments,
				target = $j(event.target),
				cX, cY, pX, pY;
			
			function track(event) {
				cX = event.pageX;
				cY = event.pageY;
			};
			pX = event.pageX;
			pY = event.pageY;
			function clear() {
			target.unbind("mousemove", track).unbind("mouseout", arguments.callee);
				clearTimeout(timeout);
			}
			function handler() {
				if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
					clear();
					jQuery.event.handle.apply(self, args);
				} else {
					pX = cX; pY = cY;
					timeout = setTimeout(handler, cfg.interval);
				}
			}
			var timeout = setTimeout(handler, cfg.interval);
			target.mousemove(track).mouseout(clear);
			return true;
		}
	};
	
	$j(document).ready(function(){
//  		brandbox_tabs = 0;
		$j("#product-tabs").tabs({
			event: 'hoverintent',
			selected: product_tabs_cat
		});
  		$j("#pfam-1").tabs({
			event: 'hoverintent'
		});
  		$j("#pfam-2").tabs({
			event: 'hoverintent'
		});
  		$j("#pfam-3").tabs({
			event: 'hoverintent'
		});
  		$j("#pfam-4").tabs({
			event: 'hoverintent'
		});
		$j("#pfam-5").tabs({
			event: 'hoverintent'
		});
		$j("#pfam-6").tabs({
			event: 'hoverintent'
		});
		$j("#pfam-7").tabs({
			event: 'hoverintent'
		});
  		$j("#pfam-8").tabs({
			event: 'hoverintent'
		});
		$j("#pfam-9").tabs({
			event: 'hoverintent'
		});
		$j("#pfam-10").tabs({
			event: 'hoverintent'
		});



		$j("#pfam-"+(product_tabs_cat+1)).tabs("select",product_tabs_prod);

  		$j(".persona-box").tabs({
			event: 'hoverintent',
			selected: persona_box
		});
		
		$j(".brandbox-tabs").tabs({ 
			event: 'click',
			selected: brandbox_tabs,
			fx: {opacity: 'toggle'}
		}).tabs("rotate",16000);
		$j("div.brandbox-tab-backdrop").css('opacity',0.53); //set opacity of layer behind the tabs to 53%
		
		//Feature Tabs
		$j(".feature-tabs").tabs({ //construct tabs and capture clicks, assign transition effect
			event: 'click',
			fx: {opacity: 'toggle'}
		}).tabs("rotate",10000);
		$j("div.feature-tab-backdrop").css('opacity',0.53); //set opacity of layer behind the tabs to 53%

		//Info-Box tabs
		$j("div.info-box").tabs({ //construct tabs and capture clicks, assign transition effect
			event: 'hoverintent'
		});

		$j(".jump-right").click(function() { //handle next button - mouseovers handled with script for ie6
			jump('next');
		 }).mouseover(function() {
			$j(this).addClass("jump-over");
		 }).mouseout(function() {
			$j(this).removeClass("jump-over"); 
		 });
		$j(".jump-left").click(function() { //handle previous button - mouseovers handled with script for ie6
			jump('prev');
		 }).mouseover( function() {
			$j(this).addClass("jump-over");
		 }).mouseout( function() {
			$j(this).removeClass("jump-over"); 
		 });

		function jump(direction){ //next and previous function
			if($j(".brandbox-tabs").length > 0) {
				var $jtabs = $j(".brandbox-tabs").tabs();
			} else {				
				var $jtabs = $j(".feature-tabs").tabs();
			}
			t = $jtabs.tabs('option', 'selected');
			tlength = $jtabs.tabs('length');
			if(t == 'undefined'){t = 0}
			if(direction == "next"){
				t = ++t < tlength ? t : 0;	
			} else {
				t = --t > -1 ? t : (tlength - 1);
			}
			$jtabs.tabs('select',t);
		}		
	
//for eventual modification of resource pages to use jQuery instead of prototaculous
/*
		$j("a.details_link").click(function(){
			var detail_link_id = $j(this).attr('id');
			var detail_link = $j("#"+detail_link_id);
			var detail_selector = "#details_" + detail_link_id.substr(5);
			var detail_box = $j(detail_selector);
			if(detail_box.css('display') == "none"){
				detail_link.addClass('details_link_expanded');
				detail_box.slideDown('fast');
			} else {
				detail_link.removeClass('details_link_expanded');
				detail_box.slideUp('fast');
			}
		 });
*/		

	//Menu system behavior, based on existing iSOL navigation code.
	$j("ul#nav_L1").attr("class","menu").find("a").removeAttr("title"); //Strip unnecessary and annoying title attribute from 'a' tags in the nav
	$j('ul ul', '#header').css({display: 'none'}).attr("class","baby"); //Hide child menu lists and assign a class to them we can leverage for animation effects

	function menuDriver(obj,dir){
		var ul = $j('ul:first', obj);
		if (ul.length) {	//if menu list exists, determine width and height values
			if (!ul[0].wid) {
				ul[0].wid = ul.width();
				ul[0].hei = ul.height();
			}
			var menWid = ul[0].wid;
			var menHei = 0;
			if(obj.parent().hasClass("baby")){ //switch animation dimension if list is a child menu
				menWid = 0;
				menHei = ul[0].hei;
			} 
			if(dir == "on"){ //animate list on or off
				ul.css({
					width: menWid,
					height: menHei,
					overflow: 'hidden',
					display: 'block'
				}).animate({					
					width: ul[0].wid,
					height: ul[0].hei
				},
				{
					duration: 300,
					easing: 'easeOutSine',
					complete: function(){ul.css('overflow', 'visible')}
				});
			} else {
			var css = {
				display: 'none',
				width: ul[0].wid,
				height: ul[0].hei
			};
			ul.stop().css('overflow', 'hidden').animate({
					width: menWid,
					height: menHei			
				},
				{
					duration: 300,
					easing: 'easeInSine',					
					complete: function (){$j(this).css(css)}
				});				
			}
		}		
	}
	$j('li', '#header').hoverIntent({
		over: function(){menuDriver($j(this),"on")},
		out: function(){menuDriver($j(this),"off")},
		interval: 100, 
		sensitivity: 5
	});
	$j("span#main-navigation").removeClass("ui-helper-hidden");
	});

