$(document).ready(function() {

	// Preload Rollover Images for IE6
	var preload = [ '/fileadmin/media/home/young_adults.jpg',
					'/fileadmin/media/home/getting_married.jpg',
					'/fileadmin/media/home/family_life.jpg',
					'/fileadmin/media/home/living_single.jpg',
					'/fileadmin/media/home/retirement.jpg',
				   '/fileadmin/templates/images/design/ya_arrow.png', 
	               '/fileadmin/templates/images/design/gm_arrow.png',
				   '/fileadmin/templates/images/design/fl_arrow.png',
				   '/fileadmin/templates/images/design/ls_arrow.png',
				   '/fileadmin/templates/images/design/r_arrow.png',
				   '/fileadmin/templates/images/icons/health_expense_calculator3.gif',
				   '/fileadmin/templates/images/icons/baby_expense_calculator3.gif',
				   '/fileadmin/templates/images/icons/health_benefits_quizzo3.gif',
				   '/fileadmin/templates/images/icons/health_plan_match_maker3.gif',
				   '/fileadmin/templates/images/icons/healthy_retirement3.gif',
				   '/fileadmin/templates/images/icons/navigating_your_health_benefits3.gif',
				   '/fileadmin/templates/images/icons/glossary_icon.gif'];
	$.preloadImages(preload);
	
	$('#mainnav ul li a').bind('mouseover',function(e){
           Cufon.replace( this, {
	         fontFamily: 'FrutigerLT55Roman',
	         separate: 'words',
	         hover: true
           });
           
	}).bind('mouseout',function(e){
           Cufon.replace( this, {
	         fontFamily: 'FrutigerLT55Roman',
	         separate: 'words',
	         hover: true
           });
	});


	$(".frontEndEditIcons").parent().addClass("editIconLink");	// Add a class to the a tag surrounding the pencil edit icons
	$("a[rel|=external]").attr('target', '_blank');	// Add open in new window functionality
	if ($(".jqtransform").length){
		$("select.jqtransform").jqTransSelect();// Style forms(input and checkboxes)
		$(".checkBox.jqtransform").each(function(){
			var $th = $(this);
			
			var lbl =  $th.next('label');
			if( lbl.attr('for') == $th.attr('id') )
			{
				lbl.bind('click',function(){
					$th.trigger('click');
				});
			}
			$th.jqTransCheckBox();
			
			$('.submitLink').click(function(e){
				e.stopPropagation();
				e.preventDefault();
				$(this).parents('form').submit();
			});
			
		});// Style forms(input and checkboxes)
		
		$('.formButton.jqtransform').jqTransInputButton();

		$('textarea').css({'resize':'none'});
		
		//ie6 png fix
		if ($.browser.msie && ($.browser.version <= "6.0")) { 
			$('body').pngFix();
		}
		
			// Form validation [START]
			$(".validate").each(function() {
				$(this).validate({
					focusInvalid: false,
					rules: {
						email_address: {
							email: true
						}
					},
					messages: {
						email_address: "Please enter a valid email address."
					},
					errorLabelContainer: $(this).find('.errorLog'),
					onfocusout: false,
					onkeyup: false,
					onclick: false,
					errorPlacement: function(error, element) {
						if ($(element).is('select')) {
							var ulel = element.parent().parent();
							error.appendTo(ulel);
						}
						else{
							error.insertAfter(element);
						}
					}
				});
			});
			
			$.validator.addMethod("comfirm_email_address", function(value, element) {
				var mail = document.getElementById('email_address').value;
				if (mail) {
					return (($(element).val().length > 0) && $(element).val() == mail);
				} else {
					return ($(element).val().length > 0);
				}
			}, "The email addresses do not match. Please re-enter the same email address in both fields.");

			$.validator.addMethod("zipcodevalid", function(value, element) {
				if ($(element).val().length > 0) {
					var strValue = $(element).val();
					var objRegExp = /(^\d{5}$)|(^\d{5}-\d{4})$/
						if(!objRegExp.test(strValue)) {
							return false;
						} else {
							return true;
						}
				} else {
					return true;
				}
			}, "Please enter a valid Zip Code");
			
			$.validator.addMethod("datevalid", function(value, element) {
				if ($(element).val().length > 0) {
					var strValue = $(element).val();
					var objRegExp = /^\d{1,2}(\/)\d{1,2}\1\d{4}$/
					  if(!objRegExp.test(strValue))
						return false;
					  else{
						var strSeparator = strValue.substring(2,3) 
						var arrayDate = strValue.split(strSeparator); 
						var arrayLookup = { '01' : 31,'03' : 31, 
											'04' : 30,'05' : 31,
											'06' : 30,'07' : 31,
											'08' : 31,'09' : 30,
											'10' : 31,'11' : 30,'12' : 31}
						var intDay = parseInt(arrayDate[1],10); 
						if(arrayLookup[arrayDate[0]] != null) {
						  if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0)
							return true;
						}
						var intMonth = parseInt(arrayDate[0],10);
						if (intMonth == 2) { 
						   var intYear = parseInt(arrayDate[2]);
						   if (intDay > 0 && intDay < 29) {
							   return true;
						   }
						   else if (intDay == 29) {
							 if ((intYear % 4 == 0) && (intYear % 100 != 0) || 
								 (intYear % 400 == 0)) {
								 return true;
							 }   
						   }
						}
					  }  
					  return false;
				} else {
					return true;
				}
			}, "Please enter a valid Date (mm/dd/yyyy)");
			
			// Form validation [END]
	}
	
	$("#tools li:last, ul.footerlinks li a:last, .tools ul li:last, .glossaryNav ul.all li:last, .column1 .quizzes ul li:last, .column2 .quizzes ul li:last, #other_nav ul li:last").addClass('last');
	
	$(".news-latest-item:odd, .tools_list li:odd").addClass('odd'); //Add arternative row colors
	
	$(".newspanes ul, ul.page_nav").each(function(){
		$(this).find('li span:last').addClass('last');
		$(this).find("li:first").addClass('first');
	});
	
	// Home Page Tools Pod
	if ($('#tools').length) {
		var iClass = $('#tools .list li:first').attr('class');
		$('#tools #icon').addClass(iClass+"_icon");
		
		$('#tools .list li').mouseover(function() {
			$('#tools #icon').removeClass(iClass+"_icon");
			if ($(this).hasClass('benefits_quizzo')){$(this).parentsUntil('#tools').find('#icon').addClass('benefits_quizzo_icon').stop(true,true).fadeIn('slow');}
			else if ($(this).hasClass('plan_match_maker')){$(this).parentsUntil('#tools').find('#icon').addClass('plan_match_maker_icon').stop(true,true).fadeIn('slow');}
			else if ($(this).hasClass('expense')){$(this).parentsUntil('#tools').find('#icon').addClass('expense_icon').stop(true,true).fadeIn('slow');}
			else if ($(this).hasClass('baby')){$(this).parentsUntil('#tools').find('#icon').addClass('baby_icon').stop(true,true).fadeIn('slow');}
			else if ($(this).hasClass('retirement_rediness')){$(this).parentsUntil('#tools').find('#icon').addClass('retirement_rediness_icon').stop(true,true).fadeIn('slow');}
			else if ($(this).hasClass('health_benefits')){$(this).parentsUntil('#tools').find('#icon').addClass('health_benefits_icon').stop(true,true).fadeIn('slow');}
			else if ($(this).hasClass('glossary_page')){$(this).parentsUntil('#tools').find('#icon').addClass('glossary_page_icon').stop(true,true).fadeIn('slow');}
		});
		$('.list ul','#tools').mouseout(function(){
			$(this).parentsUntil('#tools').find('#icon').removeClass();
			$('#tools #icon').addClass(iClass+"_icon");
		});	
	}
	
	// transform submit buttons to links
	$("input.submit").each(function(){
		$(this).replaceWith('<a href="#" class="sendit"><span>' + $(this).attr('value') + '</span></a>');
	});
	$(".sendit").click(function(event) {
		event.preventDefault();
		$(this).parents('form').submit();
	});

	// Remove default text from input on focus
	$('.guide').each(function() {
		var def_value = this.value;
		$(this).focusin(function() {
			if(this.value == def_value) {
				this.value = '';
			}
		});
		$(this).focusout(function() {
			if(this.value == '') {
				this.value = def_value;
			}
		});
	});
	
	//Tooltip
	$(".tooltip").tooltip({
	   offset: [10, 2],
	   tipClass:"tooltipContent",
	   effect: 'slide',
	   slideFade:'!$.browser.msie',
	   predelay:200,
	   delay:200
	}).dynamic({ bottom: {direction: 'down', bounce: true} });
	
	//Tooltip in modal/tools
	$(".toolinfo").tooltip({
	   offset: [0, 160],
	   tipClass:"tooltipContent",
	   effect: 'slide',
	   slideFade:'!$.browser.msie',
	   predelay:200,
	   delay:200,
	   position: 'top left',
	   relative: true
	});
	
	//Jump To Top
	$('.totop a, .csc-linkToTop a').click(function(){
        $('html, body').animate({scrollTop:0}, 'slow');
        return false;
    });

	$(".choose_option").hover(function() {
		$(this).find("p").addClass('active');
		$(this).find("#other_nav").stop(true, true).slideToggle("slow");  
	}, function(){
		$(this).find("#other_nav").stop(true, true).slideToggle("slow", function() {
    		$(".choose_option").find("p").removeClass('active');
  		});
	});
	
		
	
	

$(function() {
	
	//Home Page Tab Module
	var $tabsLi = $('#tabModule ul.tabs');
	var homeTabs = $("ul.tabs").tabs("div.panes > div",{
		api:true,
		effect: 'fadeHome',
		event:'mouseover',
		rotate:false,
		onBeforeClick: function(e,o){
			$tabsLi.find('.current').removeClass('current');
			$tabsLi.find('li:eq('+o+') a').addClass('current');
			
			if(mInterval && e.altKey!=undefined) clearInterval(mInterval);
			
			Cufon.replace('#tabModule ul.tabs li', {
				fontFamily: 'FrutigerLT55Roman',
				separate: 'words',
				hover: true
			});	
		}
	});
	
	//custom slideshowfunc 
	if( homeTabs ){
		var mInterval=false;
		setTimeout( function() {
			mInterval = setInterval(function(){ 
				if( homeTabs.getIndex()===4 ){ 
					clearInterval(mInterval);
					mInterval=false;
					homeTabs.click(2); 
					return false;
				}
				else 
					homeTabs.next(); 
			},2600);
		}, 1024);
	}
	
	// Add hover effect on tab module on homepage for IE6
/*	if ($.browser.msie && $.browser.version == "6.0") {
		$("ul.tabs li a").mouseover(function() {
			$(this).find('.pointer').show();  
		}).mouseout(function(){
			if ($(this).hasClass('current')){
				$(this).find('.pointer').show();
			} else{
				$(this).find('.pointer').hide();	
			}
		});
	}*/

	// News Tab module
	var $newTabsLi = $('ul.newstabs');
	$("ul.newstabs").tabs("div.newspanes > div",{
		effect: 'fade',
		fadeOutSpeed:'slow',
		onBeforeClick: function(e,o){
			$newTabsLi.find('.current').removeClass('current');
			$newTabsLi.find('li:eq('+o+') a').addClass('current');
			
			Cufon.replace('ul.newstabs li', {
				fontFamily: 'FrutigerLT55Roman',
				separate: 'words',
				hover: true
			});	
		}
    });
	
	// Related Articles Tab Module
	if( $('.relpanes').length > 0)
	{
		var te = $('.article_content');
		te.css('position','relative');
		var height = te.height();
		te.css({'position':'absolute'});
		$('.relpanes').css({'height': height});
	}
	
	var $relTabsLi = $('.reltabs');
	$("ul.reltabs").tabs("div.relpanes > div",{
		onBeforeClick: function(e,o){
			$relTabsLi.find('.current').removeClass('current');
			$relTabsLi.find('li:eq('+o+') a').addClass('current');
			
			Cufon.replace('.reltabs li', {
				fontFamily: 'FrutigerLT55Roman',
				separate: 'words',
				hover: true
			});	
		},
		effect: 'articlesFade'
    });
	
	$("ul.subnav").tabs("div.articles_wrap div.article_list",{
		effect: 'articlesFade'
    });

	$(".relpanes ul.page_nav").each(function(){
		var obj = this;
		
		this.api = $(this).tabs( $(this).parent().prev().find(' > div'),{
			api: true,
			effect: 'articlesFade',
			initialIndex:0,
			onBeforeClick: function(e,o){
				if( o === 0 )
				{
					$(this.getTabs()[o]).parent().parent().prev().find('li.prev').addClass('p_inactive');
					$(this.getTabs()[o]).parent().parent().prev().find('li.next').removeClass('n_inactive');
				}
				else if( o === (this.getTabs().length-1) )
				{
					$(this.getTabs()[o]).parent().parent().prev().find('li.prev').removeClass('p_inactive');
					$(this.getTabs()[o]).parent().parent().prev().find('li.next').addClass('n_inactive');
				}
				else
				{
					$(this.getTabs()[o]).parent().parent().prev().find('li.next').removeClass('n_inactive');
					$(this.getTabs()[o]).parent().parent().prev().find('li.prev').removeClass('p_inactive');
				}
			}
		});
		
		
		
		$(this).prev().find('li.next a').click(function(e) {
			e.preventDefault();
			
			if( obj.api.getIndex() < obj.api.getPanes().length ) {
				obj.api.next();
				if( obj.api.getIndex()===(obj.api.getPanes().length-1) )
				{
					$(this).parent().addClass('n_inactive');
				}
				else
					this.parentNode.className='next';
			
				$(this).parent().siblings('.p_inactive').removeClass('p_inactive');
			
			}
			else
			{
				$(this).parent().addClass('n_inactive');
			}
		});

		$(this).prev().find('li.prev').addClass('p_inactive').find('a').click(function(e) {
			e.preventDefault();
			if( obj.api.getIndex() > 0 ) {
				obj.api.prev();
				
				if( obj.api.getIndex()===0 )
					$(this).parent().addClass('p_inactive');
				else
					this.parentNode.className='prev';
				
				$(this).parent().siblings('.n_inactive').removeClass('n_inactive');
			}
			else
			{
				$(this).parent().addClass('p_inactive');
			}
		});
	});

	//News Accordion Menu
	var newsDefault = $('#healthNewsAccordion').find('.open');
	var initIndex=0;
	if( newsDefault.length > 0 )
	{
		initIndex = newsDefault.index()/2;
	}
	var newsAcc = $("#healthNewsAccordion").tabs("#healthNewsAccordion dd", {
		tabs: 'dt', 
		effect: 'slide', 
		initialIndex: initIndex
	});
	
	// FAQs
	var faqDefault = $('#faqsAccordion').find('.open');
	initIndex=0;
	if( faqDefault.length > 0 )
	{
		initIndex = faqDefault.index()/2;
	}
	$("#faqsAccordion").tabs("#faqsAccordion dd", {
		tabs: 'dt', 
		effect: 'slide', 
		initialIndex: initIndex
	});
	
});
	
	//Add hover effect on articles list view and make the whole pod clickable
	$(".article").mouseover(function() {
		$(this).addClass('hover');  
	}).mouseout(function(){
		$(this).removeClass('hover');	
	}).click(function(){
		var url = $(this).find("a:first").attr("href");
		window.location.href = url;
	});	
	
	// Add hover effect on buttons
	$("p.button a").mouseover(function() {
		$(this).parent().addClass('hover');  
	}).mouseout(function(){
		$(this).parent().removeClass('hover');	
	});
	
	//making sure that addThis won't throw an error if it is undefined on ie6
	if(!addthis) var addthis = { error: true };
	
	$(function() {
		if ($.browser.msie && ($.browser.version <= "6.0")) {
			var modalOpen = function( wrap, href ){
					$.get( href, function(data) {
                                          data = data.substr( (data.indexOf('<body>')+6) );
                                          data = data.substr( 0 , data.indexOf('</body>') );
                                          
                                          wrap.html( data );
                                        });
				}
		}
		else
		{
			var modalOpen = function( wrap, href ){
				wrap.load( href );
			}
		}
	
		$("a[rel|=#overlay]").overlay({
			mask: {
				color: '#000000',
				loadSpeed: 'fast',
				closeSpeed: 'normal',
				opacity: 0.3
			},
			onBeforeLoad: function() {
				if (this.getTrigger().attr("class") == "book"){
					this.getOverlay().width(870);
				} else {
					this.getOverlay().width(640);	
				}
				
				var wrap = this.getOverlay().find(".contentWrap");
				modalOpen( wrap, this.getTrigger().attr("href") );
				
				if( !($.browser.msie && ($.browser.version == "6.0") ) )
				{
					window.modal = true;
					if( document.getElementById('at20mc') ) {
						document.getElementById('at20mc').className = "modalWindow";
						document.getElementById('overlay').appendChild( document.getElementById('at20mc') );
					}
				}
				else
					window.modal = false;
			},
			onClose: function() {
				
				var wrap = this.getOverlay().find(".contentWrap");
				wrap.empty();
				window.modal = false;
				if( document.getElementById('at20mc') ) {
					document.getElementById('at20mc').className = "";
					document.getElementsByTagName('body')[0].appendChild( document.getElementById('at20mc') );
				}
			}		
		});
		
	});
	
	
}); // DOM End

function resizeSurveys(size){
	$("#survey_swf").attr("height" , size);
	if (size > 110){
		$('#survey_swf').parents('.pod').addClass('survey');
	} else {
		$('#survey_swf').parents('.pod').removeClass('survey');
	}
}

// Home Tabs Effect
if ($.browser.msie && $.browser.version <= "8.0"  && $.browser.version != "7.0") {
	if( $.browser.version <= "6.0") {
		$.tools.tabs.addEffect("fadeHome", function(i, done){
			var oldPane = $(this.getCurrentPane());
			var currPane = $(this.getPanes()[i]);
			oldPane.fadeOut(940).find('.inner');
			currPane.stop(true,true).fadeIn(700,function(){
				done.call();
			});
		});
	}
	else if( $.browser.version == "8.0" )
	{
		$.tools.tabs.addEffect("fadeHome", function(i, done){
			var oldPane = $(this.getCurrentPane());
			var currPane = $(this.getPanes()[i]);
			currPane.stop(true,true).show();
			oldPane.hide();
			done.call();
		});
	}

}
else
{

$.tools.tabs.addEffect("fadeHome", function(i, done){
	var oldPane = $(this.getCurrentPane());
	var currPane = $(this.getPanes()[i]);
	oldPane.fadeOut(940).find('.inner').stop(true,true).fadeOut(700);
	currPane.stop(true,true).fadeIn(700).find('.inner').stop(true,true).fadeIn(790,function(){
		done.call();
	});
});

}
// Slide Effects (for flow tabs)
if( $.browser.msie && $.browser.version <= 7){
	$.tools.tabs.addEffect("articlesFade", function(i, done){
		var perPage = 10;
		var oldPane = $(this.getCurrentPane());
		var currPane = $(this.getPanes()[i]);
		oldPane.removeClass('act');

		if( currPane.hasClass('article_content') ){
			currPane.show();
			oldPane.hide();
			
			currPane.siblings().removeClass('act');
			
			if( currPane.hasClass('section') )
				var total = currPane.find('.act').outerHeight()+8;
			else
				var total = currPane.addClass('act').find('.article_list').outerHeight()+32;
				
			if(total==8)
				total = currPane.addClass('act').find('.article_list.act').outerHeight()+8;
				
			currPane.hide();
			oldPane.show();
			i = currPane.find('.actPage').index();
			var fadeOutCnt = 290;
			var fadeInCnt = 40;
			var animCount = 282;
			var animCount2 = 300;
		}
		else if( currPane.hasClass('article_list') ){
			currPane.show();
			oldPane.hide();
			var total = currPane.addClass('act').find('.pages').innerHeight()+42;
			
			
			
			currPane.hide();
			oldPane.show();
			i = currPane.find('.actPage').index();
			var fadeOutCnt = 290;
			var fadeInCnt = 40;
			var animCount = 280;
			var animCount2 = 350;
		}
		else
		{
			currPane.show().addClass('actPage');
			oldPane.hide().removeClass('actPage');
			var total = currPane.parentsUntil('.pages').innerHeight()+42;
			
			currPane.hide();
			oldPane.show();
		
			var kept=currPane.find('.article_list');
			if( kept.length > 0 ){
				if(kept.find('.pages')){
						currPane.show();
						//var total = kept.innerHeight();
						currPane.hide();
				}
				else
				{
					currPane.show();
					//var total = kept.outerHeight();
					currPane.hide();
					
					var fadeOutCnt = 280;
					var fadeInCnt = 40;
					var animCount = 250;
					var animCount2 = 300;
				}
			}
			else
			{
				if( !currPane.hasClass('article_list') )
				{
					var noinit = true;
					if( $(this.getPanes()[i]).attr('class').indexOf('pag')>= 0 )
					{
						currPane = $(this.getPanes()[i]);
						currPane.show().addClass('act');
						if(oldPane.length > 0){ 
							oldPane.hide().removeClass('act');
							
							currPane.parents('.relpanes').stop(true).css({"height": currPane.innerHeight()+45 });
							var txt = currPane.parents('.pages').next().find('p strong');
							var indT = $(txt[1]).html();
							indT = (((i*perPage))+perPage)<indT ? (((i*perPage))+perPage) : indT;
							$(txt[0]).html( (1+(i*perPage)) + ' to ' + indT );
							
							return false;
						}
						else
						{
							currPane.siblings().hide();
							if( currPane.outerHeight() >= 40 ){
								currPane.parents('.relpanes').stop(true).css({"height": currPane.innerHeight()+45 });
								
								var txt = currPane.parents('.pages').next().find('p strong');
								var indT = $(txt[1]).html();
								indT = (((i*perPage))+perPage)<indT ? (((i*perPage))+perPage) : indT;
								$(txt[0]).html( (1+(i*perPage)) + ' to ' + indT );
							}
							return false;
						}
					}
					else
						currPane=currPane.parents('.article_list');
				}
				//var total = $(this.getPanes()[i]).height();
				
				currPane = $(this.getPanes()[i]);
				var fadeOutCnt = 260;
				var fadeInCnt = 40;
				var animCount = 250;
				var animCount2 = 300;
			}
		}
		
		if( oldPane.length ==0 ){
			$(this.getPanes()).hide();
			if(noinit){
				currPane.show();
				
				if( currPane.outerHeight()>100 && currPane.parents('.relpanes').outerHeight() < currPane.outerHeight() )
					currPane.parents('.relpanes').stop(true).animate({"height": currPane.find('.page1').innerHeight()+16 },animCount2);
					
				return false;
			}
			currPane.show();
			
			if( currPane.hasClass('article_content') ) var checker = currPane.find('.article_list');
			else var checker = currPane;
		
			//console.log( checker );
			
			currPane.addClass('act');
			
			if( currPane.parents('.relpanes').outerHeight() < checker.outerHeight() )
				currPane.parents('.relpanes').stop(true).animate({"height": checker.innerHeight()+16 },animCount2);
				
			
		}
		
		var oldtotal = oldPane.outerHeight();   
		var that = this;
		
		if( total > oldtotal ){
			if( (total-oldtotal) > 300)
			{
				
					setTimeout( function(){
						oldPane.removeClass('act').hide();
						oldPane.parents('.relpanes').stop(true).animate({"height": total},animCount2, function(){
						
								var txt = currPane.find('.paging').find('p strong'); 
								var indT = $(txt[1]).html();
								indT = (((i*perPage))+perPage)<indT ? (((i*perPage))+perPage) : indT;
								$(txt[0]).html( (1+(i*perPage)) + ' to ' + indT );
						
							currPane.addClass('act').show();
							//currPane.addClass('act').stop(true,true).fadeIn(fadeInCnt, function(){
								done.call();
							//});
						});
					},10);
			}
			else
			{
				
				setTimeout( function(){
					oldPane.removeClass('act').hide();
					oldPane.parents('.relpanes').stop(true).animate({"height": total},animCount, function(){
					
								var txt = currPane.find('.paging').find('p strong'); 
								var indT = $(txt[1]).html();
								indT = (((i*perPage))+perPage)<indT ? (((i*perPage))+perPage) : indT;
								$(txt[0]).html( (1+(i*perPage)) + ' to ' + indT );
					
						currPane.addClass('act').show();
						//currPane.addClass('act').stop(true,true).fadeIn(fadeInCnt, function(){
						
								done.call();
						//});
					});
				},10);
			}
		}else{
			if( (oldtotal-total) > 300)
			{	
				
				setTimeout( function(){
					oldPane.removeClass('act').hide();
					oldPane.parents('.relpanes').stop(true).animate({"height": total},animCount2, function(){
					
							var txt = currPane.find('.paging').find('p strong');
							var indT = $(txt[1]).html();
							indT = (((i*perPage))+perPage)<indT ? (((i*perPage))+perPage) : indT;
							$(txt[0]).html( (1+(i*perPage)) + ' to ' + indT );
						currPane.addClass('act').show();
						//currPane.addClass('act').stop(true,true).fadeIn(fadeInCnt, function(){
						
							done.call();
						//});
					});
				},10);
			}
			else
			{
				
				setTimeout( function(){
					oldPane.hide();
					oldPane.parents('.relpanes').stop(true).animate({"height": total},animCount, function(){
					
								var txt = currPane.find('.paging').find('p strong');
								var indT = $(txt[1]).html();
								indT = (((i*perPage))+perPage)<indT ? (((i*perPage))+perPage) : indT;
								$(txt[0]).html( (1+(i*perPage)) + ' to ' + indT );
						currPane.addClass('act').show();		
						//currPane.stop(true,true).stop(true,true).fadeIn(fadeInCnt, function(){
								done.call();
						//});
					});
				},10);
			}
		}
		
	});
}
else
{
	$.tools.tabs.addEffect("articlesFade", function(i, done){
		var perPage = 10;
		var oldPane = $(this.getCurrentPane());
		var currPane = $(this.getPanes()[i]);
		
		oldPane.removeClass('act');
		
		if( currPane.hasClass('article_content') ){ //top level page clicked
			currPane.addClass('act').show();
			oldPane.hide();
			
			currPane.siblings().removeClass('act');
			
			if( currPane.hasClass('section') )
				var total = currPane.find('.article_list.act').outerHeight()+12;
			else
				var total = currPane.find('.article_list').outerHeight()+34;
			
			currPane.hide();
			oldPane.show();
			i = currPane.find('.actPage').index();
			
			var fadeOutCnt = 290;
			var fadeInCnt = 360;
			var animCount = 362;
			var animCount2 = 410;
		}
		else if( currPane.hasClass('article_list') ){
			currPane.show();
			oldPane.hide();
			var total = currPane.addClass('act').find('.pages').innerHeight()+45;
             
			currPane.hide();
			oldPane.show();
			i = currPane.find('.actPage').index();
			var fadeOutCnt = 290;
			var fadeInCnt = 360;
			var animCount = 362;
			var animCount2 = 410;
		}
		else
		{	//page clicked
			currPane.show().addClass('actPage');
			oldPane.hide().removeClass('actPage');
			var total = currPane.parentsUntil('.pages').innerHeight()+42;
			
			currPane.hide();
			oldPane.show();
		
			var kept=currPane.find('.article_list');
			if( kept.length > 0 ){
				if(kept.find('.pages')) {
				}
				else
				{
					var fadeOutCnt = 280;
					var fadeInCnt = 340;
					var animCount = 320;
					var animCount2 = 340;
				}
			}
			else
			{
				if( !currPane.hasClass('article_list') )
				{
					var noinit = true;
					if( $(this.getPanes()[i]).attr('class').indexOf('pag')>= 0 )
					{
						currPane = $(this.getPanes()[i]);
						currPane.show();
						if(oldPane.length > 0){ 
							oldPane.hide().removeClass('act');
							
							currPane.parents('.relpanes').stop(true).css({"height": currPane.innerHeight()+45 });
							var txt = currPane.parents('.pages').next().find('p strong');
							var indT = $(txt[1]).html();
							indT = (((i*perPage))+perPage)<indT ? (((i*perPage))+perPage) : indT;
							$(txt[0]).html( (1+(i*perPage)) + ' to ' + indT );
							
							return false;
						}
						else
						{
							currPane.siblings().hide();
							if( currPane.outerHeight() >= 40 ){
								currPane.parents('.relpanes').stop(true).css({"height": currPane.innerHeight()+45 });
								
								var txt = currPane.parents('.pages').next().find('p strong');
								var indT = $(txt[1]).html();
								indT = (((i*perPage))+perPage)<indT ? (((i*perPage))+perPage) : indT;
								$(txt[0]).html( (1+(i*perPage)) + ' to ' + indT );
								
							}
							return false;
						}
					}
					else
						currPane=currPane.parents('.article_list');
				}
				
				currPane = $(this.getPanes()[i]);
				var fadeOutCnt = 260;
				var fadeInCnt = 320;
				var animCount = 300;
				var animCount2 = 340;
			}
		}
		
		if( oldPane.length ==0 ){
			$(this.getPanes()).hide();
			if(noinit){
				currPane.show();
				 
				if( currPane.outerHeight()>100 && currPane.parents('.relpanes').outerHeight() < currPane.outerHeight() )
					currPane.parents('.relpanes').stop(true).animate({"height": currPane.find('.page1').innerHeight()+16 },animCount2);
				return false;
			}
			currPane.show();
			
			currPane.addClass('act');
			if( currPane.hasClass('article_content') ) var checker = currPane.find('.article_list');
			else var checker = currPane;
			
			if( currPane.parents('.relpanes').outerHeight() < checker.outerHeight() )
				currPane.parents('.relpanes').stop(true).animate({"height": checker.innerHeight()+16 },animCount2);
		}
		
		var oldtotal = oldPane.outerHeight();   
		var that = this;
		
		if( total > oldtotal ){ 
			if( (total-oldtotal) > 300)
			{
				oldPane.removeClass('act').stop(true,true).fadeOut(fadeOutCnt,function(){ 
					oldPane.parents('.relpanes').stop(true).animate({"height": total},animCount2, function(){
							
							var txt = currPane.find('.paging').find('p strong'); 
							var indT = parseInt(  $(txt[1]).text() );
							indT = (((i*perPage))+perPage)<indT ? (((i*perPage))+perPage) : indT;
							$(txt[0]).html( (1+(i*perPage)) + ' to ' + indT );
							
						currPane.addClass('act').stop(true,true).fadeIn(fadeInCnt, function(){
							done.call();
						});
					});
				});
			}
			else
			{
				oldPane.removeClass('act').stop(true,true).fadeOut(fadeOutCnt);
				oldPane.parents('.relpanes').stop(true).animate({"height": total},animCount, function(){
							
							var txt = currPane.find('.paging').find('p strong'); 
							var indT = $(txt[1]).html();
							indT = (((i*perPage))+perPage)<indT ? (((i*perPage))+perPage) : indT;
							$(txt[0]).html( (1+(i*perPage)) + ' to ' + indT );
							
					currPane.addClass('act').stop(true,true).fadeIn(fadeInCnt, function(){
					
							done.call();
					});
				});
			}
		}else{
			if( (oldtotal-total) > 300)
			{	
				oldPane.removeClass('act').stop(true,true).fadeOut(fadeOutCnt,function(){
					oldPane.parents('.relpanes').stop(true).animate({"height": total},animCount2, function(){
							
							var txt = currPane.find('.paging').find('p strong');
							var indT = $(txt[1]).html();
							indT = (((i*perPage))+perPage)<indT ? (((i*perPage))+perPage) : indT;
							$(txt[0]).html( (1+(i*perPage)) + ' to ' + indT );
							
							currPane.addClass('act').stop(true,true).fadeIn(fadeInCnt, function(){
						
							done.call();
						});
					});
				});
			}
			else
			{
				oldPane.removeClass('act').stop(true,true).fadeOut(fadeOutCnt);
				oldPane.parents('.relpanes').stop(true).animate({"height": total},animCount, function(){
						
							var txt = currPane.find('.paging').find('p strong');
							var indT = $(txt[1]).html();
							indT = (((i*perPage))+perPage)<indT ? (((i*perPage))+perPage) : indT;
							$(txt[0]).html( (1+(i*perPage)) + ' to ' + indT );
							
					currPane.addClass('act').stop(true,true).fadeIn(fadeInCnt, function(){
							done.call();
					});
				});
			}
		}
	});
}

/*
CSS Browser Selector v0.4.0 (Nov 02, 2010)
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua=u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1},g='gecko',w='webkit',s='safari',o='opera',m='mobile',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3.6')?g+' ff3 ff3_6':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('blackberry')?m+' blackberry':is('android')?m+' android':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?m+' j2me':is('iphone')?m+' iphone':is('ipod')?m+' ipod':is('ipad')?m+' ipad':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win'+(is('windows nt 6.0')?' vista':''):is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);

