
// window.onload
jQuery(function($) {
  
  // remove self link
  $(document).removeSelfLink();

});

// photo_home
function photo_home() {

  $('a.advanced').click(function() {
    $('div.widget.advanced')
	  .toggle();
    return false;
  });
  
  var form = document.form;
  if (form.sid.value || form.aid.value || form.cid.value || form.uid.value)
    $('a.advanced')
	  .click();

  $('a.check-all').click(function() {
    $('form :checkbox')
	  .attr('checked', true);
    return false;
  });

} // photo_home

// photo_create_form
function photo_create_form() {

// window.onload
jQuery(function($) {
  
  var field = $('div.widget div.field');

  $('dt > :checkbox', field).click(function() {
    var id = this.value;
	if (!this.checked)
	  $('dd > :checkbox[@value^='+id+']', field)
	    .attr('checked', false);
  });

  $('dd > :checkbox', field).click(function() {
    var id = this.value.substring(0, 8);
	if (this.checked)
	  $('dt > :checkbox[@value='+id+']', field)
	    .attr('checked', true);
  });

  $('a.add', field).click(function() {
    
	var i = $(this.parentNode)
	  .siblings('div.field')
	  .andSelf()
	  .length + 1;

    var field = $('<div />')
	  .addClass('field')
	  .insertAfter(this.parentNode)
	  .append(this);

    $('<input type="text" />')
	  .addClass('text')
	  .attr('name', 'link'+ i + '_url')
	  .attr('value', 'http://')
	  .attr('size', 60)
	  .attr('maxlength', 255)
	  .prependTo(field);

    $('<input type="text" />')
	  .addClass('text')
	  .attr('name', 'link' + i + '_title')
	  .attr('size', 40)
	  .attr('maxlength', 40)
	  .prependTo(field);

    $('<input type="hidden" />')
	  .attr('name', 'link' + i)
	  .attr('value', 1)
	  .prependTo(field);

    return false;
  });
  
  
});

} // photo_create_form

// photo_update_form
var photo_update_form = photo_create_form;

