function resizeFooter( adjust ) {
    $("#bottom-pane").css( "width", $(document).width() - adjust );
}

function resizePsuedoBody() {
    var adjust = $.browser.msie ? 165 : 165;

    $("#psuedo-body").height( $(window).height() - adjust );
}

function resizeCenterContent() {
   var adjust = $.browser.msie ? 14 : 10;

    if ( window.location.pathname == '/' ) {
	adjust = $.browser.msie ? 4 + 117 : 0 + 116;
    }
    
    var centerHeight = $(document).height() - $("#header").outerHeight(true) - 30 - adjust;
    if ( centerHeight < 531 ) { centerHeight = 531 };

    $("#center-content").css( "height", centerHeight );

    if ( window.location.pathname == '/' ) {
	swfobject.embedSWF("actionscript/Main.swf","center-content-swf","100%","100%","10.0","",{},{"wmode":"transparent"});
    }
}

function setFeaturedPaneOpacity(opacity) {
    $("#featured-pane-container").fadeTo(2000,opacity);
}

// Globals

navClicked = "";

$(document).ready(function() {
    // resizeCenterContent() is only for the home page. sticky footer behavior needs
    // to be reconciled across all pages and both sites - it is currently special-cased
    // for the home page. use microsite implementation as the reference
    
    if ( window.location.pathname == '/' ) {
	resizeCenterContent();
    } else {
	resizePsuedoBody();
	resizeFooter( $.browser.msie ? 0 : 0 );
    }

    $(".featured-pane").children(".featured-pane-image,.featured-pane-header,.featured-pane-text").fadeTo(500,.5);

    $("#footer_right a").mouseenter( function() {
	$(this).css("text-decoration","underline");
    });

    $("#footer_right a").mouseleave( function() {
	$(this).css("text-decoration","");
    });

    $(".featured-pane").mouseenter( function() {
	$(this).children(".featured-pane-image,.featured-pane-header,.featured-pane-text").fadeTo(500,1);

    });

    $(".featured-pane").mouseleave( function() {
	$(this).children(".featured-pane-image,.featured-pane-header,.featured-pane-text").fadeTo(500,.5);
    });

    $("#horz-slide-content-container").height( $("#center-content").height() - $("#interior-header-text").outerHeight(true) );
    $("#interior-header-title").height( $("#interior-header-text").outerHeight(true) );

    // text contained in absolute positioned divs are not hidden on
    // overflow. put the content in a separate container and use
    // margin-left + display to achieve the animation

    // $("#interior-left-nav div").click( function() {
    // 	// we need this variable to reference this in the callback functions
    // 	var el = this;
	
    // 	navClicked = this.id.split('-nav')[0];
    // 	setTimeout( "window.location.hash = navClicked", 1000);

    // 	$(".opened").animate({marginLeft:900},500, function() {
    // 	    // hidden elements (i.e. display:none) are not in the DOM, causing
    // 	    // visible elements below to shift up

    // 	    $(".opened").hide();
    // 	    $(".opened").css("margin-left","-915px");

    // 	    $("#" + navClicked + "-text").show();
    // 	    $("#" + navClicked + "-text").animate({marginLeft:0},500, function() {
    // 		$(".opened").removeClass("opened");
    // 		$("#" + navClicked + "-text").addClass("opened");
    // 	    });
    // 	});
    // });

    // JS for insights page

    $(".content-list table tr td").mouseout( function() {
    	$(this).css("background-color","");
    	$(this).next().css("background-color","");
    	$(this).children("a").css("color","");

    	$("#snippet").html( "" );
    	$("#snippet").css("background-color","");
    });	

    $(".content-list table tr td").mouseover( function() {
    	$(this).css("background-color","#bbbbbb");
    	$(this).next().css("background-color","#bbbbbb");
    	$(this).children("a").css("color","#1a5ca6");

    	$("#snippet").css("background-color","#bbbbbb");
    	$("#snippet").css("margin-top",$(this).position().top);

    	$("#snippet").html( $("#" + this.id + "-content").html() );

	// don't draw the snippet over the footer

	var overhang = ($(window).height() - $("#bottom-pane").height()) - ($("#snippet").offset().top + $("#snippet").outerHeight()); 

	if ( overhang < 0 ) {
    	    $("#snippet").css("margin-top",$(this).position().top - -overhang - 40);
	}
    });

    // the layout on the insights page is slightly different, so
    // we need to unbind the existing handler

    // $(".insights-page #col1-3 .left-nav-button").unbind( "click" );

    // $(".insights-page #col1-3 .left-nav-button").click( function() {
    // 	var el = this;

    // 	navClicked = this.id.split('-nav')[0];
    // 	setTimeout( "window.location.hash = navClicked", 1000);

    // 	$("#snippet").css("width","415px");
    // 	$("#snippet").animate({marginLeft:500},500, function() {
    // 	    $("#snippet").html( "" );
    // 	    $("#snippet").css("width","");
    // 	    $("#snippet").css("marginLeft","0");
    // 	    $("#snippet").css("background-color","");
    // 	});

    // 	$(".opened").animate({marginLeft:900}, 500, function() {
    // 	    $(".opened").hide();
    // 	    $(".opened").css("margin-left","-600px");
    // 	    $(".opened").removeClass("opened");

    // 	    $("#" + navClicked  + "-list").show();

    // 	    $("#" + navClicked + "-list").animate({marginLeft:0},500, function() {
    // 		$("#" + navClicked + "-list").addClass("opened");
    // 	    });
    // 	});
    // });
    
    // hash = window.location.hash;
    // if ( hash.length > 0 ) {
    // 	$( hash + "-nav" ).click();
    // }

});

$(window).resize( function() {
    if ( window.location.pathname == '/' ) {

	setFeaturedPaneOpacity(1);
	resizeCenterContent();
    
	if ( window.location.pathname == '/' ) {
	    setTimeout(function() {
		$("#center-content-swf").remove();
		$("#center-content").append( "<div id=center-content-swf></div>" );
		swfobject.embedSWF("actionscript/Main.swf","center-content-swf","100%","100%","10.0","",{},{"wmode":"transparent"});
	    }, 200);
	}
    } else {
	resizePsuedoBody();
	resizeFooter( 0 );
    }
});

$("#overview-pane").click( function() {
    $("#center-content").click();
});

