/*
 * hrefID jQuery extention - returns a valid #hash string from link href attribute in Internet Explorer
 */
(function($){$.fn.extend({hrefId:function(){return $(this).attr('href').substr($(this).attr('href').indexOf('#'));}});})(jQuery);

/*
 * Scripts
 *
 */
jQuery(function($) {
 
	var Engine = {
		utils : {
			links : function(){
				$('a[rel*=external]').click(function(e){
					e.preventDefault();
					window.open($(this).attr('href'));						  
				});
			},
			
			
			mails : function(){
				$('a[href^=mailto:]').each(function(){
					var mail = $(this).attr('href').replace('mailto:','');
					var replaced = mail.replace('/at/','@');
					$(this).attr('href','mailto:'+replaced);
					if($(this).text() == mail) {
						$(this).text(replaced);
					}
				});
			}
		}
	};

	Engine.utils.links();
	Engine.utils.mails();
	
});

$.fn.unwrap = function() {
  this.parent(':not(body)')
    .each(function(){
      $(this).replaceWith( this.childNodes );
    });

  return this;
};
var tabs = {
   horizontal : function(){
       $(".tabs").unwrap();
       $(".tabs").nextAll(".html_paragraph").hide();
if ($(".tabs .tabs-links2").size() == 0) {
       $(".tabs").nextAll(".html_paragraph:first").show();
}
       $(".tabs-links > li").click(function(){
	  var tabNumber = $(".tabs-links li").index(this);
	  $(".tabs").nextAll(".html_paragraph").hide();
	  $(".tabs").nextAll(".html_paragraph:eq("+tabNumber+")").fadeIn();
	  $(".tabs-links li").removeClass("active");
	  $(this).addClass("active")
       })
   }
}

$(function(){
// Start Tab Selection Code
// get value of query string
function getQuerystring(key, default_) {
	if (default_==null) default_="";
	key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
	var qs = regex.exec(window.location.href);
	if(qs == null)
	return default_;
		else
	return qs[1];
}
var tab_value = getQuerystring('tab');

// open selected tab
if (tab_value){
	var currentTab = tab_value 
} else {	
	var currentTab = 0; // Set to a different number to start on a different tab.
}
	
function openTabMain(clickedTab) {
	var thisTab = $(".tabs-links li a").index(clickedTab);
	$(".tabs-links li a").removeClass("active");
	$(".tabs-links li a:eq("+thisTab+")").addClass("active");
	$(".dynamic").hide();
	$(".dynamic:eq("+thisTab+")").show();
	currentTab = thisTab;
} // End tab selection code
	

$(".dynamic tr:odd").addClass("odd");

	$("#content").each(function() {
		$(this).html($(this).html().replace(/Â®/g,"<sup>Â®</sup>"));
		return true;
	});
$('a.disclaimer').click(function(event) {		
		var answer = confirm('Please acknowledge receiving and reading the applicable prospectus, as well as the Application and Adoption Agreement Instructions, the Disclosure Statement, the Custodial Account Agreement, and the Privacy Notice (the "Account Documents").')
		if (answer){
			
		}
		else{
			event.preventDefault();				
		}		
	});
	
	// Switch the active table body in the performance table
	$('#quarter-toggle').click(function() {
		$('#quarter-table').show();
		$('#monthly-table').hide();
		$(this).addClass('active');
		$('#month-toggle').removeClass('active');
	});
	
	$('#month-toggle').click(function() {
		$('#monthly-table').show();
		$('#quarter-table').hide();
		$(this).addClass('active');
		$('#quarter-toggle').removeClass('active');
	});	 // End table toggle


var Accordion = function() {
$(".tabs").nextAll(".html_paragraph").hide();
    $(".tabs-links2 li").not(".tabs-links2 li ul li").click(function () {
        if (! ($(this).find("div").hasClass("activeBlock"))) {
            var tabNumber = $(".tabs-links2 li").not(".tabs-links2 li ul li").index(this);
            $(".activeBlock").remove();
            var activeTabHTML = $(".tabs").nextAll(".html_paragraph:eq(" + tabNumber + ")").html();
            $(this).append("<div class='activeBlock'>" + activeTabHTML + "</div>");
            $(".activeBlock").fadeIn();
            $(".tabs-links2 li").removeClass("active");
            $(this).addClass("active").find("li").unbind();
        }
        else { $(".activeBlock").remove(); }
    })
}

Accordion();
$("#main2 div").show();

   $(".list-items-3-col .item").unwrap();
   $(".item-b").unwrap();
   tabs.horizontal();
   $('.slider-items').cycle({
        fx:      'scrollHorz',
        timeout:  4000,
        prev:    '.prev',
        next:    '.next',
        cleartypeNoBg: true
    });
$('.main-side > div').addClass("box").addClass("box-a");

$(".font-s a").click(function(){
    $(".content").animate({fontSize: "100%"}, 300 );
});
$(".font-m a").click(function(){
    $(".content").animate({fontSize: "130%"}, 300 );
});
$(".font-l a").click(function(){
    $(".content").animate({fontSize: "150%"}, 300 );
});
//$(".d li a").truncate(60);

$.expr[':'].external = function(obj){
      return !obj.href.match(/^mailto\:/)
              && (obj.hostname != location.hostname)
              && !obj.href.match(/^javascript\:/);
  };
 
  $('a:external').addClass('external');
 
  $('.external').click(function() {
    var link = $(this).attr('href');
 
    $('<div>You are now leaving ESGManagers.com. Thank you for visiting. Pax World and ALPS Distributors, Inc. are not responsible for the content on the page you are linking to. Please click OK to continue and open '+(link)+' in a new window. Close the new window at any time to return to ESGManagers.com.</div>').dialog({
      title: "External Link",
      modal : true,
      overlay: {
        backgroundColor: '#000',
        opacity: 0.5
      },
      buttons: {
        'Ok': function() {
          $(this).dialog('close').remove();
          window.open(link);
        },
        'Cancel': function() {
          $(this).dialog('close').remove();
          return false;
        }
      }
    }); 
    return false;
});
});
