function initOverLabels()
{
  var labels, id, field;

  labels = document.getElementsByTagName('label');
  for (var i = 0; i < labels.length; i++) {
    if (labels[i].className == 'overlabel') {

      id = labels[i].htmlFor || labels[i].getAttribute('for');
      if (!id || !(field = document.getElementById(id))) {
        continue;
      }

      labels[i].className = 'overlabel-apply';

      if (field.value !== '') {
        hideLabel(field.getAttribute('id'), true);
      }

      field.onfocus = function () {
        hideLabel(this.getAttribute('id'), true);
      };
      field.onblur = function () {
        if (this.value === '') {
          hideLabel(this.getAttribute('id'), false);
        }
      };

      labels[i].onclick = function () {
        var id, field;
        id = this.getAttribute('for');
        if (id && (field = document.getElementById(id))) {
          field.focus();
        }
      };
    }
  }
}
function hideLabel(field_id, hide)
{
  var field_for;
  var labels = document.getElementsByTagName('label');
  for (var i = 0; i < labels.length; i++) {
    field_for = labels[i].htmlFor || labels[i].getAttribute('for');
    if (field_for == field_id) {
      labels[i].style.textIndent = (hide) ? '-1000px' : '0px';
      return true;
    }
  }
}

function initMenuTabs(default_active_tab)
{
  if(default_active_tab)
    active_tab = default_active_tab;
  else
    active_tab = null;

  jQuery('.tab_toggler').click(function(){
    var parent_id = jQuery(this).parents('.tab_cont').attr('id');

    if(!active_tab || (parent_id != active_tab))
    {
      if(parent_id == 'auth_cont')
      {
        jQuery('#auth_active, #menu_passive').addClass('active');
        jQuery('#auth_passive, #menu_active').removeClass('active');
      }
      else if(parent_id == 'menu_cont')
      {
        jQuery('#menu_active, #auth_passive').addClass('active');
        jQuery('#menu_passive, #auth_active').removeClass('active');
      }

      active_tab = parent_id;
    }
    else
    {
      jQuery('#auth_active, #menu_active').removeClass('active');
      jQuery('#auth_passive, #menu_passive').addClass('active');

      active_tab = null;
    }

    return false;
  });
}

function onPopupOpen(elts, settings)
{
  jQuery('#nyroModalFull').append('<!--[if lte IE 6.5]><iframe class="select-free"></iframe><![endif]-->');

  jQuery('#large_image').bind('load', function(e){ jQuery.nyroModalSettings({ width: 690 , height: e.target.height + 100 }); });

  jQuery("#image_list a").click(function(){ jQuery('#large_image').attr('src', this.href); return false; });

  jQuery("#image_list a").click(function(e){
    e.preventDefault();

    jQuery('#large_image').attr('src', this.href);
     return false;
  });
}
function initNMPopups()
{
  jQuery('.nmPopup a').nyroModal({
                                  modal: true,
                                  width: 690,
                                  minHeight: 500,
                                  endShowContent: function(elts, settings) { onPopupOpen(elts, settings); },
                                  hideContent: function(elts, settings, callback){ callback(); }
  });
}

/* */
function initApp()
{
  initMenuTabs();

  initOverLabels();

  initNMPopups();
}
