jQuery(document).ready(function(){

	// Opens external links in a new window (unless it's going to the cornforthimages domain)
	jQuery("a[href*='http://']:not([href*='"+location.hostname+"'])").attr("target","_blank");
	jQuery("a[href*='cornforthimages']").removeAttr("target");

	
	/**
	 * Place post images at the top of posts
	 */
	jQuery('.block').each(function(){
		
		jQuery(this).find('.content > #tweetpress').remove().prependTo(jQuery(this)).css({
			'float': 'none',
			'margin-bottom': 10
		});
		
		jQuery(this).find('.content > p:first').find('img:first').remove().prependTo(jQuery(this)).css({
			'float': 'none',
			'margin-bottom': 10
		});
		
	});

	/**
	 * Remove "(Jon Cornforth)" from twitter handle on tweetpress mobile uploads pages
	 */
	var twitterHandle = jQuery('#tp-main-twitter-info #tp-author a').text().split(' ').slice(0,1);
  jQuery('#tp-main-twitter-info #tp-author a').text(twitterHandle[0]);
	
	// Clear default values in form input fields
	var active_color = '#000'; // Colour of user provided text
	var inactive_color = '#999'; // Colour of default text
	
  jQuery("input.textfield").css("color", inactive_color);
  var default_values = new Array();
  jQuery("input.textfield").focus(function() {
    if (!default_values[this.id]) {
      default_values[this.id] = this.value;
    }
    if (this.value == default_values[this.id]) {
      this.value = '';
      this.style.color = active_color;
    }
    jQuery(this).blur(function() {
      if (this.value == '') {
        this.style.color = inactive_color;
        this.value = default_values[this.id];
      }
    });
  });
  
  //tweetpressResizeVerticals();
});

/**
 * Tweetpress: resize vertical images to max height of 780px
 */


function tweetpressResizeVerticals()
{
	var image = jQuery('#tweetpress img.tp-main-image');
	
	image.height(780);
	
	jQuery(window).load(function(){
		
		console.log(image.height());
		
	});
	
	
	/*
	var image = jQuery('#tweetpress img.tp-main-image');
	
	jQuery(window).load(function(){
	
		var originalWidth = image.width();
		var originalHeight = image.height();
		
		console.log(originalWidth);
		
		if(originalHeight > originalWidth)
		{
			image.height(originalWidth);
			
			image.width(image.width() * (image.height() / originalHeight));
		}
	
	});
	*/
}



















