$(document).ready(function(){
	
	$.easing.custom = function (x, t, b, c, d) { 
	    var s = 1.70158;  
	    if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; 
	    return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; 
	}
	
	$('#secondaryNav ul li:not(#backTo)').click( function() {
		var selMenu = $(this).find("a").attr('childid');
		$(this).find("a").removeAttr('childid');
		var thisHref = $(this).find("a").attr("href");
		var thisTarget = $(this).find("a").attr("target");
		var thisTitle = $(this).find("a").attr("title");
		if (selMenu.length) {
			$("#childOf_" + selMenu).toggle(200, function(){
				$('#secondaryNavSlideContainer').animate({
					marginLeft: "-214px"
				}, 700, 'custom', function(){
					$('#secondaryNav h2').html(thisTitle);
					$("#secondaryNavSlideContainer").animate({height: $("#childOf_" + selMenu).height()+20},700, 'custom', function(){
						if(thisTarget == '_blank'){
							var newWindow = window.open(thisHref, '_blank');
							newWindow.focus();
							return false;
						} else {
							window.location = thisHref;
						}
					});
				});
			});
		} else {
			if(thisTarget == '_blank'){
				var newWindow = window.open(thisHref, '_blank');
				newWindow.focus();
				return false;
			} else {
				window.location = thisHref;
			}
		}
		return false;
	});
	
	
	// fixing IE7 laying issue
	//##map_ListingsExplorer
	
	
	
	$('.menu > li:not(.ddImageNav li, .dd2Col1Link, .ddNavArea3 ul li a)').hover( function() {
		
		$(".cont",this).addClass('ddSel');
		//$("~ .ddHolder, ~ .liSpacer", this).show();
		$(".cont .liSpacer", this).show();
		$(".ddHolder", this).show();
		//alert($.browser)
		if($.browser.msie && $.browser.version == "7.0") {
			$("#searchHolder, img.ui-datepicker-trigger:eq(0)").css('position','static');
			$("#searchHolder .txtInput, #searchHolder .submitBtn, img.ui-datepicker-trigger, .addthis_toolbox").hide();
			$('.frame2').css('padding-top','220px');
		}
	}, function () {
		
		$(".cont",this).removeClass('ddSel');
		//$("~ .ddHolder, ~ .liSpacer", this).hide();
		$(".cont .liSpacer", this).hide();
		$(".ddHolder", this).hide();
		if($.browser.msie && $.browser.version == "7.0") {
			$("#searchHolder, img.ui-datepicker-trigger:eq(0)").css('position','relative');
			$("#searchHolder .txtInput, #searchHolder .submitBtn, img.ui-datepicker-trigger, .addthis_toolbox").show();
			$('.frame2').css('padding-top','0px');
		}
	});
	
	// getting around jackrabbit placement	
	$('#end-date, #start-date, .ui-datepicker-trigger').click( function(){ $('#ui-datepicker-div').css('display','block'); });
	
	// ie cutting of select drop downs
	/*if($.browser.msie){
		var oldWidth;
		$("select").bind('mouseenter', function() {
			oldWidth = $(this).css('width');								   
			$(this).css('width','auto');							
		});
		$("select").bind('mouseleave', function() {
			$(this).css('width',oldWidth);							
		});
		$("select").hover(
		  function () {
			$(this).css('width','400px');
		  }, 
		  function () {
			$(this).css('width','auto');
		  }
		);
	}*/
	
});


$(window).load(function(){
	// getting around jackrabbit placement	
	$('#ui-datepicker-div').css('display','none');
	
});


// Back ground image functionality
function loadbgimage(idx){
	var bgImg = new Image;
	$(bgImg).load(function() {
		 $('body').css("background-image","url(" + bgImg.src + ")");
	});
	$(bgImg).error(function() {
		if(idx < window.menuFamArr.length){
			loadbgimage(++idx);
		}
		else{
			$('body').css("background-image","url(" + siteRoot + "includes/images/shell/bg-body.jpg)");			
		}
	});

	bgImg.src = siteRoot + "includes/images/backgrounds/backthumb_" + menuFamArr[idx] + ".jpg";			
}

function isdefined( variable)
{
    return (typeof(window[variable]) == "undefined")?  false: true;
}

// Fires later after all frames, object, and images have been loaded.
$(window).load(function(){
	// change out background image but only after the rest of the page is in.	
	var idx = 0;
	if(isdefined('menuFam') && menuFam != '||') {
		window['menuFamArr'] = menuFam.split('|');
		if(menuFam.length > 0) {
			loadbgimage(idx);
		} else {
			$('body').css("background-image","url(" + siteRoot + "includes/images/shell/bg-body.jpg)");			
		}
	} else {
		$('body').css("background-image","url(" + siteRoot + "includes/images/shell/bg-body.jpg)");		
	}

});