/**
 * Compact labels plugin
 */
(function($){$.fn.compactize=function(){return this.each(function(){var label=$(this),input=$('#'+label.attr('for'));input.focus(function(){label.hide();}).blur(function(){if(input.val()===''){label.show();}});window.setTimeout(function(){if(input.val()!==''){label.hide();}},50);});};})(jQuery);

/*
 * 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
 *
 */
function ajaxformCss(){
	$j("table.ajax tbody tr:nth-child(even) th, table.ajax tbody tr:nth-child(even) td").css({"background":"#efefef"});
    	$j("table.ajax tbody tr:nth-child(odd) th, table.ajax tbody tr:nth-child(odd) td").css({"background":"#fff"})
}
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);
					}
				});
			}
		},
		forms : {
			labels : function(){
				var $elements = $('.top-box form p.row label');
				$elements.compactize();
			}
		}
	};

	Engine.utils.links();
	Engine.utils.mails();
	
	$j.expr[':'].external = function(obj){
        return !obj.href.match(/^mailto\:/)
       && (obj.hostname != location.hostname)
       && !obj.href.match(/^javascript\:/)
       && !obj.href.match(/^http\:\/\/paxworld.com\//)
       && !obj.href.match(/^http\:\/\/www.esgmanagers.com\//)
       && !obj.href.match(/^http\:\/\/app.streamsend.com\//);

};
 
$j('a:external').addClass('external');
 
$j('.external').click(function() {
    var link = $(this).attr('href');
 
    $j('<div>You are now leaving ESGShares.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 ESGshares.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;
});

$j("ul.sf-menu").supersubs({
                minWidth:16.7,
                maxWidth:16.7,
                extraWidth:1
            }).superfish().find('ul').bgIframe({
                opacity:false
});


var tabs = {
   horizontal : function(){
       $(".tabs").unwrap();
       $(".tabs").nextAll("div").hide();
if ($(".tabs .tabs-links2").size() == 0) {
       $(".tabs").nextAll("div:first").show();
}
       $(".tabs-links > li").click(function(){
	  var tabNumber = $(".tabs-links li").index(this);
	  $(".tabs").nextAll("div").hide();
	  $(".tabs").nextAll("div:eq("+tabNumber+")").fadeIn();
	  $(".tabs-links li").removeClass("active");
	  $(this).addClass("active")
       })
   }
}
$j("input:text, textarea, input:password").focus(function(){
            if(this.value == this.title)
                this.value = '';
        });
        $j("input:text, textarea, input:password").blur(function(){
            if(this.value == '')
                this.value = this.title;
        });
        $j("input:image, input:button, input:submit").click(function(){
            $j(this.form.elements).each(function(){
                if(this.type =='text' || this.type =='textarea' || this.type =='password' ){
                    if(this.value == this.title && this.title != ''){
                        this.value='';
                    }
                }
            });
        });
        
var Accordion = function() {
$(".tabs").nextAll("div.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(); }
    })
}
$j("table.zebra tr:even").addClass("even")
Accordion();
$("#main2 div").show();
tabs.horizontal();
$(".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 );
});	
});
