$(document).ready(function(){
  $('#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:eq(0)', this).addClass('tr1');
    $('tr:eq(1)', this).addClass('tr2');
    $('tr:eq(3)', this).addClass('tr3');
    $('tr:even', this).not(':first').addClass('trEven');
    $('td', this).nthCol(1).addClass('td1');
    $('td', this).nthCol(2).addClass('td2');
    $('td', this).nthCol(3).addClass('td3');
    });

  $('.inputDate').mask("99/99/9999");
  $('.inputDate').keydown(function(e) {
    if (e.keyCode == 13)
    {
      $(this).parents('form').submit();
      return false;
    }
  });

  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);

  // clasele pt ul
  $('ul').each(function() {
    $('li:first', this).addClass('first');
    $('li:last', this).addClass('last');
  });

  $("a").bind( 'focus', function() { $(this).blur(); } );
// ---------------------------------------------------

  // CUSTOM

	$("#getGalerie").easySlider({
		auto: false,
		continuous: true,
    prevText: '',
    nextText: ''
	});

  
});

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 submitForm( formId )
{
  document.getElementById(formId).submit();
  return false;
}

function reloadCaptcha( imageName )
{
  var randomnumber=Math.floor(Math.random()*1001);
  document.images[imageName].src = "manager/includes/veriword.php?rand="+ randomnumber;
}

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 == 'reset' )
  {
    $(form).attr("value", '');
    state = 'add';
  }

  if ( state == 'add' )
  {
    $(form[0]).parent().parent().hide();
    $(buttons[0]).show();
    $(buttons[1]).hide();
    $(buttons[2]).hide();
    $(buttons[3]).hide();
    $(hidden[2]).attr("value", "add");
  }
  else
  {
    $(form[0]).parent().parent().show();
    $(buttons[0]).hide();
    $(buttons[1]).show();
    $(buttons[2]).show();
    $(buttons[3]).show();
    $(hidden[2]).attr("value", "modify/delete");
  }
}
