$(function() {
  Shadowbox.init();
  
  $('#slider div:first').bxSlider({
    mode: 'fade',
    auto: true,
    controls: false,
    speed: 2000,
    pause: 4000,
    wrapper_class: 'slider_container'
  });
  
  $('*[title]').tooltip({ 
    track: true, 
    delay: 0, 
    showURL: false,
    fade: 250 
  });
  
  $('#newpiece').click(function() {
    var n = $('#pieces').children().length + 1;
    $('#pieces').append(
      $('#piece_1').clone()
      .attr('id', 'piece_' + n)
      .find('#lblWidth_1').attr('id', 'lblWidth_' + n).attr('for', 'width_' + n).text('Piece ' + n + ' Width: ').end()
      .find('#width_1').attr('id', 'width_' + n).attr('name', 'width_' + n).end()
      .find('#lblHeight_1').attr('id', 'lblHeight_' + n).attr('for', 'height_' + n).text('Piece ' + n + ' Height: ').end()
      .find('#height_1').attr('id', 'height_' + n).attr('name', 'height_' + n).end()
    );
  });

  $('#newlpiece').click(function() {
    var n = $('#lpieces').children().length + 1;
    $('#lpieces').append(
      $('#lpiece_1').clone()
      .attr('id', 'lpiece_' + n)
      .find('#lbllWidth_1').attr('id', 'lbllWidth_' + n).attr('for', 'lwidth_' + n).text('Piece ' + n + ' Overall Width: ').end()
      .find('#lwidth_1').attr('id', 'width_' + n).attr('name', 'width_' + n).end()
      .find('#lbllHeight_1').attr('id', 'lbllHeight_' + n).attr('for', 'lheight_' + n).text('Piece ' + n + ' Overall Height: ').end()
      .find('#lheight_1').attr('id', 'lheight_' + n).attr('name', 'lheight_' + n).end()
    );
  });

  if($('ul.gallery_left')) { $('ul.gallery_left').galleria({
      history   : false, // deactivates the history object for bookmarking, back-button etc.
      clickNext : false, // helper for making the image clickable. Let's not have that in this example.
      insert    : '#gallery_right',
      onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
        $('.first_image').hide();
        // fade in the image & caption
        if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
          image.css('display','none').fadeIn(1000);
        }
        caption.css('display','none').fadeIn(1000);
      }
    });

    }

});