$(document).ready(function(){
    // #content fades in on top level pages only
    // (on top level pages, the <body>'s ID and CLASS will be equal)

    if($('body').attr('class') == $('body').attr('id') || $('body').attr('id') == 'pg_home') {
        $('#content').css('opacity', 0).clip({clipHeight: 375});

        setTimeout( function() {
            $('#content').animate({opacity: 1}, 500, function () {
				if ( this.style && this.style.filter ) {
					this.style.removeAttribute('filter'); 
				}
			});
        }, 1000);
    } else if(!$('body').hasClass('popup')) {
        $('#content').clip({clipHeight: 375});
    }

    var secondary_nav = $('#nav ul ul');
    if(secondary_nav) {
        secondary_nav.hideAndReveal();
    }

  $('#signup input').placeholder('#BFBFBF');

	$('#signup').bind('submit.obmg', function () {
		var params = { email: $('#email').val(), xhr: true };
		if($.trim(params.email) === '') {
			$('#newsletter_status').text('Please enter your email address');
			return false;
		}

		$.post($(this).attr('action'), params, function (d, s) {
			$('#newsletter_status').text(d.msg);
			if (d.success) {
				try {
					pageTracker._trackPageview('/subscribe/complete');
					pageTracker._trackEvent('Newsletter', 'Subscribe');
				} catch (e) { }
			}
		}, 'json');
		return false;
	});
});



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;
    if(fullHeight > clipHeight) {
		$(this).wrapInner('<div id="clipped"/>')
        $('#clipped').after('<a href="#" id="unclip"><img src="/inc/img/btn_down.gif" height="12" width="12" alt="Down arrow" /> Continue reading</a>');
        $('#clipped').height(clipHeight).css({overflow:'hidden'});
        $('#unclip').click(function() {
            var clipped = $('#clipped');
            $(this).remove();
			$('#content').css('height', 'auto');
            clipped.animate({height: fullHeight}, 1000);
            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');");
}
