// JavaScript Document

$(document).ready(function(){
	initSitemap();
});

var to;

function initSitemap(){
	/* $('#nav_placer').children('li').each(function(i,elem){
		if(i == 4){
			$(elem).prependTo('#kwick3 .col_nav>ul');
		}else{
			$(elem).prependTo('#kwick'+i+' .col_nav>ul');
		}
	});
	$('#nav_placer').remove(); */
	
	$('#sitemap_wrapper').hover(
		function(){
			clearTimeout(to);
		},
		function(){
			to = setTimeout('hideSitemap();', 2000);
		}
	);
	
	$('#nav').kwicks({
		max : 330,
		spacing : 20,
		duration : 300
	});
	
	var maxHeight = 0;
	$('#sitemap_wrapper').show();
	$('#nav').children('li').each(function(i,elem){
		var id = i + 1;
		$('#kwick'+id+' a').hover(
			function(){
				if($(this).attr('rel') != null && $(this).attr('rel') != ''){
					$('#kwick'+id+' .col_info').html($(this).attr('rel'));
					$('#kwick'+id+' .col_info').show();
				}
			},
			function(){
				$('#kwick'+id+' .col_info').hide();
				$('#kwick'+id+' .col_info').html('');
			}
		);
		var height = $(elem).outerHeight();
		if(height > maxHeight) maxHeight = height;
	});
	$('#sitemap').css('height', maxHeight+'px');
	$('.col').css('height', (maxHeight - 20)+'px'); // subtract 20 for top and bottom padding
	$('#sitemap_wrapper').hide();
}

function showSitemap(){
	clearTimeout(to);
	$('#sitemap_wrapper').slideDown();
}

function hideSitemap(){
	$('#sitemap_wrapper').slideUp();
}