$(document).ready(function(){
	// #content fades in on top level pages only
	// (on top level pages, the <body>'s ID and CLASS will be equal)

	var unclipOpacity = (jQuery.browser.msie ? 0.8 : 0.9999);

	if($('body').attr('class') == $('body').attr('id') || $('body').attr('id') == 'pg_home') {
		$('#content').css({'opacity':0, 'visibility':'visible'});
		$('#content').clip({clipHeight: 375, initOpacity: 0});
		setTimeout( function() {
			$('#content').fadeTo(1500, 0.8);
			$('#content .unclip').fadeTo(1500, unclipOpacity);
		}, 1800); 
	} else if(!$('body').hasClass('popup')) {
		$('#content').clip({clipHeight: 375, initOpacity: unclipOpacity});
	}

	var secondary_nav = $('#nav ul ul');
	if(secondary_nav) {
		secondary_nav.hideAndReveal();
	}

})

jQuery.fn.hideAndReveal = function() {
	this.hide().slideDown(1000);
};

/* clip the height of the content area if it exceeds options.clipHeight */
jQuery.fn.clip = function(options) {
	var fullHeight = this.height();
	var clipHeight = options.clipHeight ? options.clipHeight : 375;
	var initOpacity = options.initOpacity;
	//var initOpacity = options.initOpacity ? options.initOpacity : .8;
	if(fullHeight > clipHeight) {
		$(this).prepend('<a href="#" class="unclip" style="position: absolute; margin-top: 375px; display: block; background: transparent url(\'/inc/img/overlay.png\') repeat; background: #fff none;"><img src="/inc/img/btn_down.gif" height="12" width="12" alt="Down arrow" /> Continue reading</a>');
		$(this).height(clipHeight).css({overflow:'hidden'});
		$(this).find('.unclip').css({opacity:initOpacity});
		$(this).find('.unclip').click(function() {
            var clipped = $(this).parent();
            $(this).remove();
            clipped.animate({height: fullHeight}, 1000);
            //clipped.css('margin-bottom', '200px');
            return false;
        });
	} else {
		var container = $(this).parent();
		$(this).css('padding-bottom', 20);
		var margin_t = (((container.height() - $(this).height()) / 2) - 30);

		$(this).css('margin-top', margin_t);
		$(this).css('overflow', 'visible');
		//$(this).height(defaultHeight);
	}
	return this;
};



function popUp(url, hwnd) {
	eval("popup_" + hwnd + " = window.open('" + url + "', '" + hwnd + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=1,width=375,height=550');");
}