/*======================================================================================
 Blog JS handler
 Created: DM - 03/10/2009
======================================================================================*/



//======================================================================================
// Handles Puma Blog Search Parsing Functionality
//======================================================================================
pblog = { 
	split_url: function(url){
		return location.href.split(url)[1];
	},
	// Parses & cleans up search term to be used many times
	search_handler: function(){
		var filterterm = pblog.split_url('search/label/');
		var searchterm = pblog.split_url('?q=');
		var regex = '/%20|[ \t\r\n]/';
		
		// Lets clean up the search term so we can use it
		if(filterterm){
			filterterm = filterterm.toLowerCase().replace(regex, '_')
			$('#' + filterterm).children('a').addClass('on');
		}else{
			$('.default').children('a').addClass('on');
		}
		if (searchterm) {
			searchterm = unescape(searchterm.split('+').join(' '));
			$('.blog_form input["text"]').val(searchterm);
		}
	},
	init: function(){
		pblog.search_handler();
	}
}
commentForm = { 
	setup: function(){
		$('#commentform input[title], #commentform textarea[title]').each(function() {
			if($(this).val() === '') {
				$(this).val($(this).attr('title'));
			}
	
			$(this).focus(function() {
				if($(this).val() === $(this).attr('title')) {
					$(this).val('').addClass('focused');
				}
			});
	
			$(this).blur(function() {
				if($(this).val() === '') {
					$(this).val($(this).attr('title')).removeClass('focused');
				}
			});
		});
		$('#commentform').submit(function() {
			$('#commentform input[title], #commentform textarea[title]').each(function() {
				if($(this).attr('title') === $(this).val()) {
					$(this).val('');
				} 
			});
		});
		$('.commentlist li').click(function() {
			$(window).scrollTo('#' + $(this).attr('id'), 500);
		});
	}
	
}

$(document).ready(function() {
	pblog.init();
	commentForm.setup();

});