Create colorbox link programmatically Hello fellow druaplistas!

I have a situation where I need to output an image field using different image styles depending on some checkbox settings.

I'm doing this inside a node template. Basically this goes like this:

if ($layout == 1) {
  print $small_image;
} 
if ($layout == 2 {
  print $medium_image;
}


To get the url to the correct sized image I can use image_style_url, but this way I have to build the links to the bigger version to open inside colorbox manually. 
Is there some function available that I can pass two image styles and it uses them to generate an image tag wrapped with a link to the bigger sized image?

Update:
I took Clive's code (thanks again) and added a second parameter to be able to choose the preset that will be shown inside the colobox. Also Title and Alt is now included:
As your code was better than mine I took it and extended the stuff I needed, maybe it's of use for someone:

function _colorbox_link($image, $style_name, $style_name_link = 'colorbox_full') {
  $image_style = theme('image_style', array(
    'style_name' =&gt; $style_name,
    'path'       =&gt; $image['uri'],
    'alt'        =&gt; $image['alt'],
    'title'      =&gt; $image['title']
  ));

  $url = image_style_url($style_name_link, $image['uri']);

  $link = l($image_style, $url, array(
    'html' =&gt; TRUE,
    'attributes' =&gt; array(
      'rel' =&gt; array('colorbox-gallery'),
      'class' =&gt; array('colorbox')
    )
   ));
  return $link;
}
I don't think there is, weirdly enough I've just been looking for pretty much the same thing...I couldn't find one so I just wrote a helper function:

function _lightbox_link($image, $style_name) {
  $image_style = theme('image_style', array(
    'style_name' =&gt; $style_name,
    'path' =&gt; $image['uri'],
    'alt' =&gt; $image['alt']
  ));

  $url = image_style_url($style_name, $image['uri']);

  $link = l($image_style, $url, array(
    'html' =&gt; TRUE,
    'attributes' =&gt; array(
      'rel' =&gt; array('lightbox-gallery')
    )
  ));

  return $link;
}