function hide(id)
{
  var currentmenu = document.getElementById(id);
  if(currentmenu)
    currentmenu.style.visibility = 'hidden';
}

function show(id)
{
  var currentmenu = document.getElementById(id);
  if(currentmenu)
    currentmenu.style.visibility = 'visible';
}

function popup_img(url, title)
{
  var elenent_popup = document.getElementById('wrapper_popap');
  if (elenent_popup){
      jQuery('#wrapper_popap').remove();}

  html = '<div id="wrapper_popap" style="z-index:-100"><div class="popap"><div id="header_popap"><img alt="Marsel" src="images/img/logo_popap.jpg" width="147px" height="68px" /></div><div class="content_popap"><img src="'+url+'" alt="'+title+'" style="cursor:pointer;" onclick="jQuery(\'#wrapper_popap\').remove();" name="popupImg" onLoad="resizePopup();"/></div></div></div>'
  jQuery('body').append(html);
}

function resizePopup()
{
  img = document.images["popupImg"];
  jQuery('#wrapper_popap').css({'margin-top':-(img.height/2), 'margin-left':-(img.width/2)-37, 'z-index':1000});
}


function toggleDetail( id ){
  var item = document.getElementById(id),
      currentClass = item.className;

  if( currentClass.search(/(^|\s*)(vacancies_form_list_item_closed)(\s*|$)/) != -1 ){
    currentClass = currentClass.replace(/(^|\s*)(vacancies_form_list_item_closed)(\s*|$)/, '');
  }else{
    currentClass += ' vacancies_form_list_item_closed';
  }
  item.className = currentClass;
}



function CustomSelect( element ){
  this.element = jQuery(element);
  this.__construct();
}

  CustomSelect.prototype.__construct = function(){
    this.box = this.element.parents('.custom_select');
    if( !this.box.length ){
      this.element.wrap('<span class="custom_select"></span>');
      this.box = this.element.parents('.custom_select');
    }

    this.customValue = this.box.find('.custom_select_value');
    if( !this.customValue.length ){
      this.box.append('<span class="custom_select_value"></span>')
      this.customValue = this.box.find('.custom_select_value');
    }

    this.customButton = this.box.find('.custom_select_button');
    if( !this.customButton.length ){
      this.box.append('<span class="custom_select_button"></span>')
      this.customButton = this.box.find('.custom_select_button');
    }

    this.change();

    var bindContext = this;
    this.element.bind('change keydown keypress keyup', function(){
      bindContext.change.call(bindContext);
    }).bind('focus', function(){
      bindContext.focus.call(bindContext);
    }).bind('blur', function(){
      bindContext.blur.call(bindContext);
    });
  };

  CustomSelect.prototype.change = function(){
    var selectedIndex = this.element[0].selectedIndex || 0,
        value = this.element.children('option').eq(selectedIndex).text();

    this.customValue.html(value);
  };

  CustomSelect.prototype.focus = function(){
    this._setFocus(true);
  };

  CustomSelect.prototype.blur = function(){
    this._setFocus(false);
  };

  CustomSelect.prototype._setFocus = function( isFocus ){
    if( isFocus ){
      this.box.addClass('custom_select_focus');
    }else{
      this.box.removeClass('custom_select_focus');
    };
  };
/*--/CustomSelect--*/

function CustomFile( element ){
  this.element = jQuery(element);
  this.__construct();
}
  CustomFile.prototype.__construct = function(){
    this.box = this.element.parents('.custom_file')
    if( !this.box.length ){
      this.element.wrap('<span class="custom_file"></span>');
      this.box = this.element.parents('.custom_file')
    }

    this.customButton = this.element.parents('.custom_file_button')
    if( !this.customButton.length ){
      this.element.wrap('<span class="custom_file_button"></span>');
      this.customButton = this.element.parents('.custom_file_button')
    }

    this.customValue = this.box.children('.custom_file_value')
    if( !this.customValue.length ){
      this.box.append('<span class="custom_file_value"></span>');
      this.customValue = this.element.parents('.custom_file_value')
    }
    this.customValue.html('');

    this.change();

    var bindContext = this;

    this.customButton.bind('mousemove', function( e ){
      bindContext.updatePosition.call(bindContext, e);
      return false;
    }).bind('mouseout', function(){
      bindContext.resetPosition.call(bindContext);
      return false;
    })
    
    this.element.bind('change', function(){
      bindContext.change.call(bindContext);
    }).bind('focus', function(){
      bindContext.focus.call(bindContext);
    }).bind('blur', function(){
      bindContext.blur.call(bindContext);
    });
  };

  CustomFile.prototype.change = function(){
    var value = this.element[0].value || '';
    value = value.substr(value.lastIndexOf('/') + 1);

    this.customValue.html(value);
  };

  CustomFile.prototype.updatePosition = function( e ){
    var inputWidth = this.element[0].offsetWidth,
        wrapCoords = { x : this.box.offset().left, y : this.box.offset().top },
        inputCoords = { x : e.pageX - wrapCoords.x - inputWidth + 10, y : e.pageY - wrapCoords.y - 10};

    this.element.css({ 'left' : inputCoords.x + 'px', 'top' : inputCoords.y + 'px' });
  };

  CustomFile.prototype.resetPosition = function(){
    this.element.css({ 'left' : '0px', 'top' : '0px' });
  };

  CustomFile.prototype.focus = function(){
    this.resetPosition();
    this._setFocus(true);
  };

  CustomFile.prototype.blur = function(){
    this.resetPosition();
    this._setFocus(false);
  };

  CustomFile.prototype._setFocus = function( isFocus ){
    if( isFocus ){
      this.box.addClass('custom_file_focus');
    }else{
      this.box.removeClass('custom_file_focus');
    };
  };
/*--/CustomFile--*/
  


jQuery(document).ready(function(){
  jQuery('select.js_custom').each(function(){
    new CustomSelect(jQuery(this));
  });

  jQuery('input[type="file"].js_custom').each(function(){
    new CustomFile(jQuery(this));
  });

  jQuery('.show_popup_button').fancybox({
    hideOnContentClick : false,
    overlayOpacity : 0.5,
    centerOnScroll : false,
    zoomSpeedIn : 500,
    zoomSpeedOut : 500
  });
});

