var $tltp;
var tltpTimeouts = new Array();

var $sldTimer = [];

var clrTimer = function(ind){
	clearTimeout($sldTimer[ind]);
	$sldTimer[ind] = false;
} // end clrTimer

var clearTimeouts = function(){
	for(key in tltpTimeouts) clearTimeout(tltpTimeouts[key]);
	tltpTimeouts.length = 0;
} // end clearTimeouts

var hideTltp = function(){
	$('#tltp').stop().fadeTo(125, 0, function(){ $(this).hide(); });
} // end hideTltp

$(document).ready(function(){
	/*
	if($.browser.msie && parseInt(jQuery.browser.version, 10) == 6){
		$('#container').supersleight({shim: '/PublishingImages/x.gif'});
	}
	*/
	// nav
	var currpath = $(location).attr('pathname');
	var pageString = currpath.substring(currpath.lastIndexOf('/') + 1, currpath.indexOf('.')).replace(/-/g,'_');
	if($('#tn_' + pageString).length){
		$('#tn_' + pageString).addClass('active');
		$('#ln_' + pageString).removeClass('hide_ln');
	} else {
		$('#sn_' + pageString).parents('.drpdn').prev('a').addClass('active');
		$('#ln_' + pageString).addClass('active').parents('.hide_ln').removeClass('hide_ln');
	}
	
	$('.topnav li').hover(
		function(){ $(this).addClass('hvr'); },
		function(){ $(this).removeClass('hvr'); }
	);
			
	// text sizing
	var activeStyle = getActiveStyleSheet();
	$('#txtSize a[title="' + $.trim(activeStyle) + '"]').addClass('active')
	$('#txtSize a').click(function(e){
		e.preventDefault();
		$('#txtSize a').removeClass('active');
		setActiveStyleSheet($(this).attr('title'), 1);
		$(this).addClass('active');
		return false;
	});
	
	//track
	$("a.track").click(function(){
		var me = $(this);
		webtrends_track(me.attr("href"), $.trim(me.text()) || $.trim($("img", me).attr("alt")) || $.trim(me.attr("title")) || me.attr("href"));
	});
	
	//popup
	$('a.popup').click(function(e){
		e.preventDefault();
		window.open($(this).attr('href'),'','width=400,height=400,toolbar=no,menubar=no,location=no,scrollbars=yes,status=no,resizable=yes');
	});
	
	// modal
	$('.modal').colorbox({ opacity:0.65, initialWidth:100, initialHeight:100 });
	
	// modal interstitial
	$('.mdl_int').click(function(e){
		e.preventDefault();
		var title = $.trim($(this).text()) || $.trim($("img", $(this)).attr("alt")) || $.trim($(this).attr("title")) || $(this).attr("href");
		$(this).colorbox({
			opacity:0.65, 
			innerWidth: 702, 
			innerHeight: 263, 
			initialWidth: 602, 
			initialHeight: 213, 
			iframe: true, 
			fastIframe: false, 
			scrolling: false, 
			href: '/Pages/modal_interstitial.aspx?URL=' + encodeURIComponent($(this).attr('href')) + '&TITLE=' + encodeURIComponent(title), 
			onLoad: function(){ $('#cboxClose').hide(); }
		});
	});
	
	// tooltip
	if($('.tltp').length){
		var tltphtml = '<div id="tltp">'+
			'<div class="top"></div>'+
			'<div class="main">'+
				'<div class="arw"><span></span></div>'+
			'</div>'+
			'<div class="btm"></div>'+
		'</div>';
		
		$('body').append(tltphtml);
		$tltp = $('#tltp');
		$tltp.hover(
			clearTimeouts, // mouseover
			function(){ // mouseout
				tltpTimeouts['tltp'] = setTimeout(function(){ $tltp.stop().fadeTo(125, 0, function(){ $(this).hide(); }); }, 125);
			}
		);
	
		$('.tltp').hover(
			function(){ // mouseover
				clearTimeouts();
				var $l = $(this);
				$tltp.find('.for_tltp').remove();
				$tltp.find('.main').prepend($l.next('.for_tltp').clone());
				var addSpan = '<span class="title">' + $l.attr('href') + '</span>';
				if($tltp.find('.for_tltp').length){
					$tltp.find('.for_tltp').append(addSpan);
				} else {
					$tltp.find('.main').prepend('<div class="for_tltp">' + addSpan + '</div>');
				}
				
				var pos = $l.offset();
					pos.h = $l.outerHeight();
					pos.w = $l.outerWidth();
				var tltpdims = { w: $tltp.outerWidth(), h: $tltp.outerHeight() };
				var scrltop = $(window).scrollTop();
				
				var mvleft = pos.left + pos.w + 32;
				var mvtop = pos.top - 78;
				
				if(jQuery.browser.msie && parseInt(jQuery.browser.version.substr(0,1)) <= 7){
					$tltp.css({top: mvtop + 'px', left: mvleft + 'px'}).show();
				} else {
					$tltp.css({top: mvtop + 'px', left: mvleft + 'px'}).stop().fadeTo(125, 1);
				}
				
			},
			function(){ // mouseout
				if(jQuery.browser.msie && parseInt(jQuery.browser.version.substr(0,1)) <= 7){
					$('#tltp').hide();
				} else {
					var rand = Math.floor(Math.random() * 11);
					tltpTimeouts[rand] = setTimeout(hideTltp, 125);
					$(this).data('timeoutId', tltpTimeouts[rand]);
				}
			}
		);
	}
	// end tooltip
	
	// home tabs
	if($('.sld3 .blk_safety').length){
		if($.browser.msie && parseInt(jQuery.browser.version, 10) == 6){
			$('.sld3').css('height','auto');
			var blkSafeHeight = $('.sld3 .blk_safety').height() + 'px';
			$('.sld3').css('height', blkSafeHeight);
		} else {
			$('.sld3').css('height', $('.sld3 .blk_safety').outerHeight() + 'px');
		}
	}
	if($('.rlvr').length){
		$('.rlvr').each(function(i){ $sldTimer[i] = false; });
		$('.rlvr').hover(
			function(){
				var $tind = $('.rlvr').index($(this));
				if($sldTimer[$tind]) clrTimer($tind); // clr
				var $sld = $(this).parent('.tab').next('.slide');
				if(!$sld.data('origH')) $sld.data('origH', $sld.css('height')); // store height
				var $nHeight = (parseInt($sld.data('origH')) + parseInt($sld.find('a img').attr('height'))) + 'px';
				$sld.stop().animate({
					height: $nHeight
				}, 500);
			},
			function(){
				var $tind = $('.rlvr').index($(this));
				var $sld = $(this).parent('.tab').next('.slide');
				var $reHeight = ($sld.data('origH')) ? $sld.data('origH') : 0;
				var $this = $(this);
				$sldTimer[$tind] = setTimeout(function(){
					$sld.stop().animate({height: $reHeight}, 350);
				}, 125, clrTimer($tind));
			}
		);
		
		$('.slide a').hover(
			function(){
				var $tind = $('.slide').index($(this).parent());
				if($sldTimer[$tind]) clrTimer($tind); // clr
			},
			function(){
				var $tind = $('.slide').index($(this).parent());
				var $sld = $(this).parent('.slide');
				var $reHeight = ($sld.data('origH')) ? $sld.data('origH') : 0;
				$sldTimer[$tind] = setTimeout(function(){
					$sld.stop().animate({height: $reHeight}, 350);
				}, 125, clrTimer($tind));
			}
		);
	}
	// end home tabs
	
}); // THE END
