$(function(){
	var t;
	
	$('nav li').has('.sub-menu').addClass('sub-menu-parent');

	// Navigation
	//Dropdown animation - CSS only backup in place
	$('nav ul li.sub-menu-parent').hover(function(){
		$(this).find('ul.sub-menu').css('display', 'none').slideDown(200, function () { $(this).addClass('active-hover')});
	}, function(){
		$(this).find('ul.sub-menu').removeClass('active-hover');
		
		//t = setTimeout(function(){
			$('ul.sub-menu').each(function(){
				if(!$(this).hasClass('active-hover')){
					$(this).hide();
				}
			});
		//},1);
		
	});
	
	
	// Blog Post 'More' Button Fix
	
	$('article.post').each(function(){
		
		var orig = $(this).find('a.more-link').text();
		$(this).find('a.more-link').html('<strong>More</strong>');
		var el = $(this).find('a.more-link');
		
		if(orig != ''){
			el.parent('p').remove();
			$(this).find('p:not(:has(>img))').last().append('&hellip;&nbsp;').append(el);
		}
		
	});
	
	
	// Placeholders for form fields
	$('.author').val('Name').css('color','#818182').focus(function(){
	if($(this).val() == 'Name'){$(this).val('').css('color','#000')}}).focusout(function(){
		if($(this).val() == 'Name' || $(this).val() == '' || $(this).val() == ' '){$(this).val('Name').css('color','#818182')}});

	$('.email').val('Email (we will not publish your email address)').css('color','#818182').focus(function(){
	if($(this).val() == 'Email (we will not publish your email address)'){$(this).val('').css('color','#000')}}).focusout(function(){
		if($(this).val() == 'Email (we will not publish your email address)' || $(this).val() == '' || $(this).val() == ' '){$(this).val('Email (we will not publish your email address)').css('color','#818182')}});
	
	$('.url').val('Website address').css('color','#818182').focus(function(){
	if($(this).val() == 'Website address'){$(this).val('').css('color','#000')}}).focusout(function(){
		if($(this).val() == 'Website address' || $(this).val() == '' || $(this).val() == ' '){$(this).val('Website address').css('color','#818182')}});
		
	$('.comment').val('Your reply').css('color','#818182').focus(function(){
	if($(this).val() == 'Your reply'){$(this).val('').css('color','#000')}}).focusout(function(){
		if($(this).val() == 'Your reply' || $(this).val() == '' || $(this).val() == ' '){$(this).val('Your reply').css('color','#818182')}});
		
	$('.phone').val('Phone number (optional)').css('color','#818182').focus(function(){
	if($(this).val() == 'Phone number (optional)'){$(this).val('').css('color','#000')}}).focusout(function(){
		if($(this).val() == 'Phone number (optional)' || $(this).val() == '' || $(this).val() == ' '){$(this).val('Phone number (optional)').css('color','#818182')}});
		
	$('.name').val('Name').css('color','#818182').focus(function(){
	if($(this).val() == 'Name'){$(this).val('').css('color','#000')}}).focusout(function(){
		if($(this).val() == 'Name' || $(this).val() == '' || $(this).val() == ' '){$(this).val('Name').css('color','#818182')}});
		
	$('.message').val('Your message').css('color','#818182').focus(function(){
	if($(this).val() == 'Your message'){$(this).val('').css('color','#000')}}).focusout(function(){
		if($(this).val() == 'Your message' || $(this).val() == '' || $(this).val() == ' '){$(this).val('Your message').css('color','#818182')}});
		
	$('#commentform input[type=submit]').attr('value', '');
	$('#contact_form input[type=submit]').attr('value', '');
	
	$('.comment-meta').hide();
	
	$('.comment').hover(function(){
		//$(this).children('div').children('.comment-meta').show();
	},
	function(){
		$(this).children('div').children('.comment-meta').hide();
	});
	
	function resize_blog(){
	
		
		$('#post img').each(function(){
		
			if($(this).width() > $('article').width()){
				if(!$(this).attr('data-original')){
					$(this).attr('data-original', $(this).attr('width'));
				}
				
				$(this).attr('width', ($('article').width()));
				$(this).removeAttr('height');
			}else if($(this).attr('data-original')){
				
				if($(this).attr('data-original') > $(this).width()){
					
					if($(this).attr('data-original') > $('article').width()){
						$(this).attr('width', ($('article').width()));
					}else{
						$(this).attr('width', ($(this).attr('data-original')));
					}
					
				}
				
			}
			
			
		});
	}

	
	$(window).resize( resize_blog );
	resize_blog();
	$('img').load( resize_blog );
	
	
	
	
});
