// COMMENT ACTIONS
function showComment() {
  // loop over gallery links
  var commentLinks = $$('#gallery a');
  for (var i=0; i<commentLinks.length; i++) {
    // open comment box
    commentLinks[i].onclick = function() {
      // remove clone if exists
      if ($('clonedImage')) $('clonedImage').remove();
      // clone link image
      var image = this.getPrevious().clone();
      // give clone an id
      image.id = 'clonedImage';
      //inject clone into comment
      image.injectBefore($E('#commentbox p'));
      // set title
      $E('#commentbox strong').setText(this.getText());
      // set text
      $E('#commentbox p').setText(this.getProperty('title'));
      // make comment box visible
      $('commentbox').addClass('open');
      // fade comment box in
      $('commentbox').effect('opacity', {duration:200, transition: Fx.Transitions.linear}).start(0,1);
      return false;
    }
  }
  // close box
  $('close_comment').onclick = function() {
    // fade comment box out, remove box from display
    $('commentbox').effect('opacity', {duration:200, transition: Fx.Transitions.linear, onComplete: function(){
      $('commentbox').removeClass('open');
    }}).start(1,0);
  }
}
window.addEvent('domready', showComment);

// FIX IE PNG TRANCPARENCY ON IMG ELEMETS
function loadAlpha() {
  if (!window.ie || window.ie7) return false; // exit if IE 7 or not IE
  var images = $$('img.transparent');
  for (var i=0; i<images.length; i++) {
    if (images[i].src.indexOf('.png')!=-1) {
      // stop image from collapsing if no width/height set
      images[i].width ? images[i].setStyle('width',images[i].width+'px') : false;
      images[i].height ? images[i].setStyle('height',images[i].height+'px') : false;
      // apply alpha
      images[i].setStyle('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+images[i].src+'", sizingMethod="image")');
      // hide src image
      var tmp = images[i].src.split('/');
      var src = tmp[tmp.length-1];
      images[i].src = images[i].src.replace(src, 'spacer.png');
    }
  }
}
window.addEvent('domready', loadAlpha);