/**

Site-wide RAD JavaScript

*/


// default value for search text box.
var defaultSearchValue = "Search";


// 
//
//
var intContentPadTop = 0;
var wrapperHeight = 0;
var footerHeight = 0;
var sideWrapperHeight = 0;
var contentHeight = 0;
// var prevConHeight = 0;
// var heightIntMS = 50;
// var heightInterval;


//
// Functions to run when every page loads.
//
$(document).ready(function(){
	$("ul#menu-links li a").each(function(index){
		var menu_id = this.id.split("-link")[0];
		$(this).hover(function(){
			// myOpenMenu(menu_id);
			fPrimaryRollOver('over', (index+1));
		},function(){
			// myCloseMenu(menu_id);
			fPrimaryRollOver('out', (index+1)); 
		});
		$(this).after("<div class='menu-bottom' id='"+menu_id+"-bottom'"+($(this).parent().get(0).className.indexOf("current")>-1 ? " class='current'" : "")+"></div>");
	})
	$("#menu").prepend("<div id='menu-left'></div><div id='menu-right'></div>");
	$(".dropmenu").each(function(index){
		$(this).mouseover(function(){
			fPrimaryRollOver('over', (index+1));
		}).mouseout(function(){
			fPrimaryRollOver('out', (index+1));
		});
	});
	
	//
	// 
	//
	$("#search_module_text").focus(function(){
		$(this).addClass("searchFocus");
		if($(this).val() == defaultSearchValue) {
			$(this).val("");
		}
	}).blur(function(){
		$(this).removeClass("searchFocus");
		if($(this).val() == "") {
			$(this).val(defaultSearchValue);
		}
	}).val(defaultSearchValue);
	
	//
	//
	
	// alert($("#interior-content").get(0));
	// console.log($("#interior-content").get(0));
	if(document.getElementById("interior-content")) {
		intContentPadTop = parseInt($("#interior-content").css("paddingTop").split("px")[0]);
	}
});

function fixImageCaption() {
	$("#interior-content").children("#caption").css({
		marginTop: "1px",
		marginLeft: "65px"
	});
	
	$("#interior-top-pic-wrap").filter(function(){
		return $.trim($(this).html()) == "";
	}).each(function(){
		$(this).css("backgroundImage", "none");
		$("#caption").css("backgroundImage", "none");
	});
	
	$("#caption").filter(function(){
		return $.trim($(this).text()) == "";
	}).height(0).css({
		margin: "0px"
	}).each(function(){
		$(".interior #interior-content").css("paddingTop", "25px");
	});
	
	$("#interior-top-pic-wrap").filter(function(){
		return $.trim($(this).html()) == "";
	}).each(function(){
		$("#caption").text("").height(0).css({
			margin: "0px"
		}).each(function(){
			$(".interior #interior-content").css("paddingTop", "25px");
		});
	});
}

function fixHeights() {
	wrapperHeight = parseInt($("#interior-content-wrapper").height());
	footerHeight = parseInt($("#footer").height()) + parseInt($("#footer").css("paddingTop").split("px")[0]) + parseInt($("#footer").css("paddingBottom").split("px")[0]);
	sideWrapperHeight = parseInt($("#side-wrapper").height());
	contentHeight = wrapperHeight - footerHeight;
	// console.log(contentHeight+" "+parseInt(sideWrapperHeight+50));
	if(contentHeight <= parseInt(sideWrapperHeight+50)) {
		$("#content").height(sideWrapperHeight-(intContentPadTop)+50);
	}
	else {
		$("#content").height("auto");
	}
}

window.onload = fixHeights;

