function Promocion() {
   var self=this

   this.is_open=true
   this.id='#pestanya'
   this.wrapper='#pestanya-hide'

   $('.reallyupdown').click(function() { self.toggle() })

   this.timeout=null
   this.timeout_delay=20000
   this.add_timeout()
}

Promocion.prototype.toggle = function() {
   this.is_open ? this.close() : this.open()
}

Promocion.prototype.close = function(now) {
   var self=this
   $(this.id).animate(
      { top: '285px' },
      now==null ? 'normal' : 1,
      'swing',function() { 
         self.is_open=false
         self.arrow_up()
         self.close_wrapper()
      })
}

Promocion.prototype.open = function() {
   var self=this
   this.open_wrapper()
   this.clear_timeout()
   $(this.id).animate(
      { top: '0px' },
      'normal',
      'swing',function() { 
         self.is_open=true
         self.arrow_down()
         self.add_timeout()
      })
}

// wrapper management
Promocion.prototype.open_wrapper = function() {
   $(this.wrapper).css({ height: 326 })
   $(this.id).css({ top: 285 })
}

Promocion.prototype.close_wrapper = function() {
   $(this.wrapper).css({ height: 41 })
   $(this.id).css({ top: 0 })
}

// arrow management
Promocion.prototype.arrow_up = function() {
   $('.updown img').css('top','0px')
}

Promocion.prototype.arrow_down = function() {
   $('.updown img').css('top','-35px')
}

// timeout management
Promocion.prototype.clear_timeout = function() {
   if(this.timeout != null) clearTimeout(this.timeout)
   this.timeout = null
}

Promocion.prototype.add_timeout = function() {
   var self=this
   this.clear_timeout()
   this.timeout=setTimeout(function() { self.close() }, this.timeout_delay)
}

$(function() { new Promocion() });

