// JavaScript Document

//resize the content area to be long enough to leave space for the backnextnav at the bottom
//TODO also need to take into account the side nav and extend if it is also longer than content
function resize() 
{
    var content_height = $("#content").height();
	var backnextnav_height = $("#backnextnav").height();
	var breadcrumbsContainer_height = $("#breadcrumbsContainer").height();
//	console.debug(content_height);
//	console.debug(backnextnav_height);
//	console.debug(breadcrumbsContainer_height);
	var contentbg_height = content_height + backnextnav_height + breadcrumbsContainer_height + 20;//+20 because wanted a bit more space at the bottom
//	console.debug(contentbg_height);
	
	//the following should not be neccessary since the min heights are set in the CSS
	if (contentbg_height < 415)
		contentbg_height = 415;

	$("#contentbg").height(contentbg_height);


	//make sure the woodstrip stay's with the main carpet.
	var w = $(window).width();
	if (w < 900)
	{
		$("#woodstrip").removeClass("woodstripNormal");
		$("#woodstrip").addClass("woodstripSmallWidth");
		
		$("#body").removeClass("bodyNoHorzScroll");
		$("#body").addClass("bodyNormal");
	}
	else
	{
		$("#woodstrip").removeClass("woodstripSmallWidth");
		$("#woodstrip").addClass("woodstripNormal");
		
		$("#body").removeClass("bodyNormal");
		$("#body").addClass("bodyNoHorzScroll");
	}
	
}

$(document).ready(function() {
$('#breadcrumbs-3').xBreadcrumbs();

$("img.dropshadow")
	.wrap("<div class='outerpair1 floatimage'><div class='outerpair2'><div class='shadowbox'>" +
    "<div class='innerbox'></div></div></div></div>");

$("img.darkableImage").hover(function() {
	$(this).css({ opacity: 1 });
		}, function() {
	$(this).css({ opacity: 0.6 });
});
/*
	$(".lightbox").lightbox({
		fitToScreen: true,
		imageClickClose: false
	});
	*/
//Preload the back next nav hover images... otherwise there is a delay
if (document.images)
{
  pic1= new Image(173,56); 
  pic1.src="/images/backnextnav/next_On172x56.png"; 

  pic2= new Image(172,56); 
  pic2.src="/images/backnextnav/back_On173x56.png"; 
}

//subnav hover functions
$("ul#topnav li").hover(function() { //Hover over event on list item
	$(this).find("span").show(); //Show the subnav
} , function() { //on hover out...
	var currentlink = $(this).find("a");
	$(this).find("span").hide(); //Hide the subnav
});

//back next nav hover functions
$(".nextnav").hover(function() {
	$(this).attr("src","/images/backnextnav/next_On172x56.png");
		}, function() {
	$(this).attr("src","/images/backnextnav/next_Off172x56.png");
});

$(".backnav").hover(function() {
	$(this).attr("src","/images/backnextnav/back_On173x56.png");
		}, function() {
	$(this).attr("src","/images/backnextnav/back_Off173x56.png");
});
	
});


$(window).resize(function() {
  resize();
});

$(window).load(function() {
resize();

//set the startup image to be random
var total = $('#slider img').length;
var rand = Math.floor(Math.random()*total);
	$('#slider').nivoSlider({
		startSlide:rand,
        effect:'fade'
    });
});
