/*
  Auto-Fill function accepts id of input and fills it with the given value.
  Written by Joe Sak http://www.joesak.com/2008/11/19/a-jquery-function-to-auto-fill-input-fields-and-clear-them-on-click/
  JP 17/03/2009 changed $ references to jQuery
*/
function autoFill(id, v){
	jQuery(id).css({ color: "#999" }).attr({ value: v }).focus(function(){
		if(jQuery(this).val()==v){
			jQuery(this).val("").css({ color: "black" });
		}
	}).blur(function(){
		if(jQuery(this).val()==""){
			jQuery(this).css({ color: "#999" }).val(v);
		}
	});
}


/*
  Resize oversized images to fit into content column
  Inspired by jquery.imagefit by Oliver Boermans
  Source: http://www.ollicle.com/eg/jquery/imagefit/
*/
MAX_IMAGE_WIDTH = 540;
(function($) {
	$.fn.fitimage = function(options) {
    this.each(function(){
        width = $(this).width();
        height = $(this).height();
        if (width > MAX_IMAGE_WIDTH) {
          $(this).height(Math.round( height * (MAX_IMAGE_WIDTH / width)));
          $(this).width(MAX_IMAGE_WIDTH);
        }
			});
		return this;
	};
})(jQuery);


/*
  Set up behaviours
*/
jQuery(document).ready(function(){
  // rounded corners
  jQuery("#nav > li > a").cornerz({radius:15, borderColor:"white"});

  // fix navi for ie6, who would have thought..
  if (jQuery.browser.msie && jQuery.browser.version.substr(0,1)<7) {
    jQuery("#nav > li").width(85);
    jQuery("#nav > li").css({margin: '0 20px 0 0'});
  }

  // resize oversized images
  jQuery(".entry-content img").fitimage();

  // workaround for Contact Form 7, which does not use provide ids for input fields..
  jQuery('input[name="your-name"]').attr('id','your-name');
  jQuery('input[name="your-email"]').attr('id','your-email');
  jQuery('textarea[name="your-message"]').attr('id','your-message');

  // input prompts
	autoFill("#s", "Search");
  autoFill("#comment", "Any comments? Type your reply here");
  autoFill("#your-name", "Your name");
  autoFill("#your-email", "Your email address");
  autoFill("#your-message", "Type your message here");
});
