

/*
*******************************************************************************
*	Set up the drop down top navigation
*******************************************************************************
*/

var t; //Hover delay timeout
var currentNavItem;

$(function(){
	$('#nav-main ul.sub-menu').parent().addClass('drop-down');
	
	$('#nav-main>li.drop-down').hover(

		//mouse enter
		function(){
			currentNavItem = $(this);
			t = setTimeout(showTopNavItem, 150);
			
		},
		
		//mouse leave
		function(){
			//clear any timers
			clearTimeout(t);
			
			//Stop animation and reverse it.
			
			//$(this).children(':animated').stop();
			
			//$(this).children('ul').slideUp();
		
			$(this).children('ul').queue(function(){
				$(this).hide().clearQueue();
			})

		}
	);
	
	$('#nav-main>.drop-down>ul>li').hover(function(){
		
			
			//hide any other elements
			$(this).siblings('.drop-down').find('ul').stop().hide();
			
			//show this one	
			if($(this).is('.drop-down')){	
				$(this).find('ul').css('display','block').css('opacity',0).animate({opacity:1});
			}

	});
	
});

function showTopNavItem()
{
	currentNavItem.children('ul').css('height','auto').slideDown(500);
}


/*
*******************************************************************************
*	Inline Label Forms
*******************************************************************************
*/
$(function() {
	
	$('#sidebar form p').has('input:text').each(function(){
	
		//save contents in separate variables
		var input = $(this).find('input');
		var name = $(this).text();
		
		name = $.trim(name);
		
		//remove contents
		$(this).empty();
		

		//set title attribute
		input.attr('title', name);
		
		//set default value of input
		if(input.val() === '') {
			input.val(input.attr('title')).addClass('default-value');
		}

		//add default value class for page reloads
		if(input.val() === input.attr('title')) {
			input.addClass('default-value');
		}
		
		//bind focus event for the inputs
		input.focus(function() {
			
			//remove default value
			if($(this).val() === $(this).attr('title')) {
				$(this).val('')
			}
			
			//add focused class
			$(this).addClass('focused');
		});
		
		
		input.blur(function() {
			if(input.val() === '') {
				//restore the default value if no value has been given
				$(this).val($(this).attr('title'));
				$(this).addClass('default-value');
			}else{
				//remove the default value class
				$(this).removeClass('default-value');
			}
			
			//remove focused class
			$(this).removeClass('focused');
		});
		
		//return input to paragraph
		$(this).append(input);
		
	});
});


/*
*******************************************************************************
*	Relocation of Blog Archives and Categories 
*******************************************************************************
*/

$(function() {
	var content = $('#sidebar #archives, #sidebar #categories').removeClass('widget-container');
	
	content.find('ul').addClass('sub-menu');
	
	var wrapper = $('<ul></ul>');
	
	wrapper.append(content).addClass('sub-menu blog');
	
	$('#sidebar #menu-item-49').append(wrapper);
});


/*
*******************************************************************************
*	Smart borders in Sidebar Nav
*******************************************************************************
*/

$(function() {
	 $('#nav-sidebar>li>ul:visible').siblings('a').addClass('current-root-link');
});


/*
*******************************************************************************
*	Force the bottom of the main container to stick to the bottom of the window.
*******************************************************************************
*/
$(function(){

	resizeContent();
	
	$(window).resize(function(){
		var t = setTimeout("resizeContent()", 100)
	})
});


function resizeContent(){
	//get the height difference
	var dif = $(window).height() - $('#container').height();
	
	if(dif > 0)
	{
		//we need some ups
		//add the difference to the #main element height
		$('#main').height(
			$('#main').height() + dif
		);
		
	}
	
	if(dif < 0)
	{
		//clear any height property
		$('#main').css('height','auto')
	}
	
}


