$(document).ready(function(){
  $("a").bind( 'focus', function() { $(this).blur(); } );

  $('#hmenu ul').superfish();
  $('#hmenu ul li').each(function(i){$(this).css('z-index',100+i);});
  $('#vmenu ul').superfish();
  $('#bmenu ul').superfish();

  $('.table').each(function() {
    $('tr:first', this).addClass('firstTr');
    $('tr:even', this).not(':first').addClass('evenTr');
    $('tr',this).not(':first').each(function() {
      $('td',this).addClass('allTd');
      });
    });

  $('.inputDate').mask("99/99/9999");

  var galleryMaxHeight = 0;
  $('.gallery tr td div').each(function(){
    var height = $(this).height();
    if ( height > galleryMaxHeight ) galleryMaxHeight = height;
  });
  $('.gallery tr td div').css("height", galleryMaxHeight);
});

function popup(url, target, width, height, features)
{
  var wnd, features1;

  features1 = 'width=' + width + ',height=' + height;
  if (screen) {
      features1 += ',left=' + (screen.width - width) / 2 +
              ',top=' + (screen.height - height) /2;
  }
  if (features) {
      features1 += ',' + features;
  }

  wnd = window.open(url, target, features1);
  wnd.focus();

  return false;
}

function galleryCopyValue( obj, form, buttons, hidden )
{
  var thumb = new Array();
  var k = 0;
  $(obj).children().each(function(){ thumb[k++] = $(this).html(); });

  $(form[0]).attr("value", thumb[1]);
  $(form[1]).attr("value", thumb[2]);
  $(form[2]).attr("value", thumb[3]);
  $(hidden[1]).attr("value", thumb[1]);

  gallerySetState('modify/delete', form, buttons, hidden );
}

function gallerySetState( state, form, buttons, hidden )
{
  if ( state == 'add' )
  {
    $(form[0]).parent().parent().hide();
    $(buttons[0]).show();
    $(buttons[1]).hide();
    $(buttons[2]).hide();
    $(buttons[3]).hide();

    $(form).attr("value", '');
  }
  else
  {
    $(form[0]).parent().parent().show();
    $(buttons[0]).hide();
    $(buttons[1]).show();
    $(buttons[2]).show();
    $(buttons[3]).show();
  }
}