// swapClass
$.fn.swapClass = function(c1, c2) { return this.each(function(){ $(this).toggleClass(c1).toggleClass(c2); }); }; 
// pxToEm
Number.prototype.pxToEm=String.prototype.pxToEm=function(b){b=jQuery.extend({scope:"body",reverse:false},b);var e=(this=="")?0:parseFloat(this);var d;var c=function(){var g=document.documentElement;return self.innerWidth||(g&&g.clientWidth)||document.body.clientWidth};if(b.scope=="body"&&$.browser.msie&&(parseFloat($("body").css("font-size"))/c()).toFixed(1)>0){var f=function(){return(parseFloat($("body").css("font-size"))/c()).toFixed(3)*16};d=f()}else{d=parseFloat(jQuery(b.scope).css("font-size"))}var a=(b.reverse==true)?(e*d).toFixed(2)+"px":(e/d).toFixed(2)+"em";return a};
// equalHeights
$.fn.equalHeights=function(a){$(this).each(function(){var b=0;$(this).children().each(function(c){if($(this).height()>b){b=$(this).height()}});if(!a||!Number.prototype.pxToEm){b=b.pxToEm()}if($.browser.msie&&$.browser.version==6){$(this).children().css({height:b})}$(this).children().css({"min-height":b})});return this};



/* SITE-WIDE JCF INITS
	Do the things that affect display and/or layout first
--------------------------------------------------------------- */
$().ready(function() {	
		
	// Cleanup the Subnav [HIGH]
	$('#left li.selected').prev('li').addClass('prev');
	if ( $('#left li.selected').length === 1  && $('#left li.prev').length === 0 ) {
		$('#left li:first').addClass('selected-first');
	}
	
	// TOOLS [HIGH]
	$('#body').not('body#home #body').prepend('<p id="tools">Text: <a class="larger" href="#larger">Larger</a> <a class="smaller" href="#smaller">Smaller</a><a class="print" href="#print">Print</a><a class="email" href="#email">Email Page</a></p>');
	
	// EQUALIZE COLUMN HEIGHTS [HIGH?]
	$('.equalize').equalHeights();
		
	// ACCORDIONS	[LOW]
	//$(".accordion").accordion({ header: ".accordion-header", navigation: true, autoheight: false, active: false });
	
	// SEARCH LABEL [LOW]
	$('#head form.search input[type=text]').attr('value', 'Search for:').focus(function() { if($(this).attr('value') === 'Search for:') { $(this).attr('value', ''); } }).blur(function() { if(!$(this).attr('value')) { $(this).attr('value', 'Search for:'); } });		

	// LOGIN FORM [LOW]
	$('#login_trigger').click(function() {
		$('#head form.login').toggle();
		$(this).toggleClass('active');
		return false;
	});


	/* FONT SIZING
	--------------------------------------------------------------- */
	var MIN, MAX, STEP;
	
	MIN = 8;
	MAX = 18;
	STEP = 2;
	
	function get_base_fontsize() {
		return parseInt($('body').css('fontSize').replace(/px/,''),10);
	}
	
	function set_base_fontsize(new_size) {
		$('body').css('fontSize', new_size );
		$.cookie('JCF_FONTSIZE', new_size, { expires:7, path:'/' });
		/* if the next step would be invalid, disable now */
		if (new_size + STEP >= MAX ) {
			$('#tools a.larger').addClass('disabled');
		} else if (new_size - STEP <= MIN ) {
			$('#tools a.smaller').addClass('disabled');
		} else {
			$('#tools a.disabled').removeClass('disabled');	
		}
	}
	
	/* preset a cookie at the base size if it doesn't exist yet */
	if( !$.cookie('JCF_FONTSIZE') ) { $.cookie('JCF_FONTSIZE', 10, { expires:7, path:'/' }); }
	
	/* on pageload, set the base size to the saved cookie value */
	set_base_fontsize(parseInt($.cookie('JCF_FONTSIZE'),10));
	
	$('#tools a.larger').click(function() {
		if( $(this).hasClass('disabled') ) { return false; }
		var newsize = get_base_fontsize() + STEP;
		if(newsize < MAX) {
			set_base_fontsize(newsize);
		} 
		return false;
	});
	
	$('#tools a.smaller').click(function() {												
		if( $(this).hasClass('disabled') ) { return false; }
		var newsize = get_base_fontsize() - STEP;
		if (newsize > MIN) {
			set_base_fontsize(newsize);
		} 
		return false;
	});

	
	/* PRINT THIS PAGE
	--------------------------------------------------------------- */
	$('#tools a.print').click(function() {
		window.print();
		return false;
	});
	
	/* EMAIL THIS PAGE
	--------------------------------------------------------------- */
	$('#tools a.email').click(function() {
		var url = window.location.href;
		var subject = "The Jewish Community Foundation of Los Angeles";
		window.location.href = 'mailto:?subject='+subject+'&body='+url;
		return false;
	});
		
	/* TOGGLER
		A link with class of "toggle" immediately followed by a block 
		element (P or DIV) gets activated here. The block ele is 
		hidden, and when the matching A.toggle is clicked, the P/DIV 
		visibility is toggled.
	--------------------------------------------------------------- 
	$('a.toggle').click(function(){
		var tgt = $(this).attr('href');
		$(tgt).addClass('toggle-target').toggle();
		$(this).toggleClass('toggle-closed');
		return false;
	});
	$('a.toggle').not('.toggle-opened').click();
	
	$('a.toggle-show-all').click(function(){
		$('a.toggle-closed').click();
		return false;
	});
	*/
	
	
	
	

});

function openWindow(x,y,url,name) {
	var width = x;
	var height = y;
	newwindow=window.open(url,name,'resizable=yes,scrollbars=yes,height='+height+',width='+width);
	if (window.focus) {newwindow.focus()}
	return false;
}