
function $save(id){
  if ( $(id) ) $(id).submit();
  return false;
  }	

/*--------------------------------------------------------------------------------------------------------------------------------*/

function menu (obj){
  var li = $(obj).getParent();
  var ul = li.getElement('ul');  
  ul.toggleClass('hide');  
  if ( li.hasClass('active' ) )
    li.removeClass('active')
  else if ( !ul.hasClass('hide') ) 
    li.addClass('active');
  }
  
/*--------------------------------------------------------------------------------------------------------------------------------*/
  
function swich_order_row ( obj ){
  var className = obj.get('name') ;
  if( className ){
    if ( obj.get('value') )
      $$('.'+className).removeClass('hide');
    else
      $$('.'+className).addClass('hide');
    }
  }   

/*--------------------------------------------------------------------------------------------------------------------------------*/
  
function clear_input( input ){
  var input = $(input);
  if ( input ){
    input.addEvent('focus',function(){  if ( input.get('title') == input.get('value') ) input.set('value',''); });
    input.addEvent('blur',function(){ if ( input.get('value') == '' ) input.set('value', input.get('title') ); });
    }
  }

/*--------------------------------------------------------------------------------------------------------------------------------*/  

function add_comment(sub){
  var comment_form = $('comment_form');
  new Element('input',{'name':'sub','value':sub,'type':'hidden'}).inject(comment_form);
  comment_form.submit();  
  }

/*--------------------------------------------------------------------------------------------------------------------------------*/

function show_comment_form(obj){
  $('comment_form').removeClass('hide');
  obj.setStyle('display','none'); 
  }

/*--------------------------------------------------------------------------------------------------------------------------------*/
  
window.addEvent('domready', function() {
  var dodajdokoszyka = $('dodajdokoszyka') ;  
  if ( dodajdokoszyka ){
    dodajdokoszyka.addEvent('click',function(e){
      new Event(e).stop();
      $('order_add_form').submit();
      });
    }
});



/*--------------------------------------------------------------------------------------------------------------------------------*/
  
function hide_arrows ( gallery_slider , gallery_slider_size , marginTop , step ){
  if ( marginTop >= 0 ){
    $('arrow-up').setStyle('visibility','hidden');
    }
  else{
    $('arrow-up').setStyle('visibility','visible');
    }
  if ( gallery_slider_size.y + marginTop - ( 2 * step ) <= 0 ){
    $('arrow-down').setStyle('visibility','hidden');
    }
  else{
    $('arrow-down').setStyle('visibility','visible');
    }
  } 

window.addEvent('domready', function() {
  var gallery_slider = $('gallery_slider');
  var step = 89;

  if ( gallery_slider ){
    gallery_slider_size = gallery_slider.getScrollSize();
    var marginTop = gallery_slider.getStyle('marginTop').toInt();
    hide_arrows ( gallery_slider , gallery_slider_size , marginTop, step );

    $('arrow-down').addEvent('click', function(e){
      new Event(e).stop();
      marginTop = $('gallery_slider').getStyle('marginTop').toInt() - step ;
      if ( marginTop % step == 0 ){
        hide_arrows ( gallery_slider , gallery_slider_size , marginTop , step );
        gallery_slider.morph({'marginTop':marginTop+'px'});
        }
      });
  
    $('arrow-up').addEvent('click', function(e){
      new Event(e).stop();
      marginTop = $('gallery_slider').getStyle('marginTop').toInt() + step ;
      if ( marginTop % step == 0 ){
        hide_arrows ( gallery_slider , gallery_slider_size , marginTop , step );
        gallery_slider.morph({'marginTop':marginTop+'px'});     
        }
      });
    }
  });

