function clearText(field){
	if (field.defaultValue == field.value) field.value = '';
	else if (field.value == '') field.value = field.defaultValue;
}

$(document).ready(function(){
	
	$('.entry img').each(function() {
		
		var maxWidth = 540; // Max width for the image
    var ratio = 0;  // Used for aspect ratio
    var width = $(this).width();    // Current image width
    var height = $(this).height();  // Current image height

    // Check if the current width is larger than the max
    if(width > maxWidth){
        ratio = maxWidth / width;   // get ratio for scaling image
        $(this).css("width", maxWidth); // Set new width
        $(this).css("height", height * ratio);  // Scale height based on ratio
        height = height * ratio;    // Reset height to match scaled image
    }
		
	});
	
	if ( $('body.single .post .postShare').length > 0 && !($.browser.msie && parseInt($.browser.version) < 7)) {
	
		var descripY = parseInt($('.post .entry').offset().top) - 20;

		var $postShare = $('.post .postShare');
		var pullX = $postShare.css('margin-left');
	
		$(window).data('scrollBound',false);

		function positionShareScroll() {
			var scrollY=$(window).scrollTop();
			var fixedShare = $postShare.css('position') == 'fixed';

			if(scrollY > descripY && !fixedShare) {
				$postShare.stop().css({ position:'fixed', left:'50%', top:20, marginLeft:-571 });
			} else if(scrollY < descripY && fixedShare) {
				$postShare.css({ position:'relative',left:0,top:0,marginLeft:pullX });
			}
		}

		$(window).resize( function(){ 
			var windowW = $(window).width();
			var pulledOutside = $postShare.css('margin-left') == pullX;
		
			if(windowW >= 1143) {
				if($('.post .fb-like').length>0) $('.post .fb-like').css('clear','none');
			
				if(!$(window).data('scrollBound')) {
					if(!pulledOutside) {
						$postShare.animate({ marginLeft:pullX });	
						$('.smallButtons').hide();
						$('.largeButtons').show();
						$postShare.css('border-width','1px 0 1px 1px');
						$postShare.width('auto');
						$postShare.css({marginRight:7,marginTop:20});
						$postShare.css('float','left');
					}

					$(window).data('scrollBound',true).bind('scroll.positionShare',function(){positionShareScroll()});
	
					positionShareScroll();
			
				}
			} else {
			
				if($('.post .fb-like').length>0) $('.post .fb-like').css('clear','both');

				if( pulledOutside || $(window).data('scrollBound')) {
					$postShare.css({ position:'relative',left:0,top:0 }).animate({ marginLeft:0 });
					$('.largeButtons').hide();
					$('.smallButtons').show();
					$postShare.css({marginTop: 10, marginBottom: 15});
					$postShare.css('border-left',0);
					$postShare.css('float','none');
				
					var content_width=$('#primary').width();
				
					if(content_width=='undefined') content_width = 640;
				
					if($postShare.attr('_width')){
						$postShare.width($postShare.attr('_width'));
						var block_width=$postShare.attr('_width');
					} else { 
						$postShare.attr('_width',$postShare.width());
						var block_width=$postShare.width();
					}
				
					$postShare.width(content_width);
		
					$(window).data('scrollBound',false).unbind('scroll.positionShare');
				}
			}
		});
		$(window).resize();
	}
	
});

