var bgImages = [
	'url(/images/bg_pro.jpg)',
	'url(/images/bg_caregiver.jpg)',
	'url(/images/bg_provider.jpg)'
];

function resizeBox() {
	if($('#divBgImage').is(':hidden')) {
		$('#divBgImage').height($(document).height()-5+"px");
		$('#divBgImage').width($(document).width()-670+"px");
		$('#divBgImage').css("background-image",bgImages[0]).show();
	} else {
		$('#divBgImage').height($(document).height()-5+"px");
		$('#divBgImage').width($(window).width()-670+"px");
	}
}

$(document).ready(function()
{
	resizeBox();
	// External links
	$("a[href^=http]").add("a[href$=.pdf]").bind("click", function()
	{
		window.open($(this).attr("href"));
		return false;
	});
	
	//tabbed navigation
	$("#divMain").append('<div id="divBgImage"></div>');
	$('#divContainer').height($(document).height('100%'));
	
	// Make sure that whenever the window is resized or scrolled the div gets redrawn
	$(window).resize(resizeBox);
	$(window).scroll(resizeBox);
	
	$("#ulNav2 a").click(function()
	{
		// change the tab navigation and content area below it
		var curChildIndex = $(this).parent().prevAll().length;
		$(this).parent().parent().children('.current').removeClass('current');
		$(this).parent().addClass('current');
		$("#divStyles").add("#ulNav3").children('.current').removeClass('current');
		$("#liFirst").addClass('current');
		$("#ulNav3 li#liFirst a").attr("title", curChildIndex);
		$("div.divTabs").each(function(n) {
			if (curChildIndex == n) {
			$(this).addClass('current');
			}
		})
		$(this).blur();
		
		// swap out the hero image
		$('#divContainer').css("background-image","none");
			if($('#divBgImage').is(':hidden')) {
				$('#divBgImage').height($(document).height()-5+"px");
				$('#divBgImage').width($(document).width()-670+"px");
				$('#divBgImage').css("background-image",bgImages[curChildIndex]);
				$("#divBgImage").fadeIn('slow');
			} else {
				$("#divBgImage").fadeOut(100, function() {
					$('#divBgImage').height($(document).height()-5+"px");
					$('#divBgImage').width($(document).width()-670+"px");
					$('#divBgImage').css("background-image",bgImages[curChildIndex]);
					$("#divBgImage").fadeIn('slow');
				});
			}
		return false;
	});
	
	// third level nav
	$("#ulNav3 a").not("#ulNav3 li#liFirst a").click(function()
	{
		var curLowIndex = $(this).parent().prevAll().length+2;
		$(this).parent().parent().children('.current').removeClass('current');
		$(this).parent().addClass('current');
		$("#divStyles").children('.current').removeClass('current');
		
		$("div.divTabs").each(function(n) {
			if (curLowIndex == n+1) {
			$(this).addClass('current');
			}
		})
		return false;
	});
	// overview link
	$("#ulNav3 li#liFirst a").click(function()
	{
		$("#divStyles").add("#ulNav3").children('.current').removeClass('current');
		$(this).parent().addClass('current');
		var aT = $(this).attr("title");
		$("div.divTabs").each(function(n) {
			if (aT == n) {
			$(this).addClass('current');
			}
		})
		return false;
	});
	
	// overview link
	$("#aDemo").click(function()
	{
		//console.log("sdfsdfs");
		Shadowbox.open(
		{
			content:    'http://www.youtube.com/v/cENd04aKlW8?fs=1&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;autoplay=1',
			player:     "swf",
			title:      "Timberland PRO<sup>&reg;</sup> YouTube Channel",
			height:     480,
			width:      640
		});
		return false;
	});
});

 
