$(document).ready(function(){
	
	$('ul.blog li p img').each(function(){
		var p = $(this).parent();
		p.addClass( 'thumbnail' );
		if( $(this).attr('title') != '' )
			p.append( '<span>'+ $(this).attr('title') +'</span>' );
	});
	
	$('ul.blog li p img').hover(function(){
		var p = $(this).parent();
		var w = getOriginalWidthOfImg( $(this).attr('src') );
		if( w < 150 )
			w = 150;
		if( w > 450 )
			w = 450;
		p.stop().animate({ width: w+'px' });
	},function(){
		$(this).parent().stop().animate({ width: '150px' });
	});
	
	
	$('#sidebar a img').parent().lightbox();
	
	
	setup_labelover();
	
});

function getOriginalWidthOfImg( src ) {
    var t = new Image();
    t.src = src;
    return t.width;
}


function setup_labelover() {
	$('input[type="text"], input[type="password"], textarea').each(function(){
		if( $(this).attr('label') )
			labelover( $(this), $(this).attr('label') );
	});
}


function labelover( element, title ) {
	var color_label = '#AAA';
	var color_text = '#000';

	if( element.is('textarea') ) {
		if( element.text() == '' )
			element.text(title).css( 'color', color_label );
		element.focus(function(){
			if( $(this).text() == title )
				$(this).text('').css( 'color', color_text );
		});
		element.blur(function(){
			if( $(this).text() == '' )
				$(this).text(title).css( 'color', color_label );
		});
	}
	else if( element.is('input') ) {
		if( element.val() == '' )
			element.val(title).css( 'color', color_label );
		element.focus(function(){
			if( $(this).val() == title )
				$(this).val('').css( 'color', color_text );
		});
		element.blur(function(){
			if( $(this).val() == '' )
				$(this).val(title).css( 'color', color_label );
		});
	}
}

