Element.Events.extend({
	'wheelup': {
		type: Element.Events.mousewheel.type,
		map: function(event){
			event = new Event(event);
			if (event.wheel >= 0) this.fireEvent('wheelup', event)
		}
	},
 
	'wheeldown': {
		type: Element.Events.mousewheel.type,
		map: function(event){
			event = new Event(event);
			if (event.wheel <= 0) this.fireEvent('wheeldown', event)
		}
	}
});
    
var MM_Blend = {
   el: null
  ,build: function()
  {
  $E('body').setStyle('height', '100%'); 	  //für IE6 & IE7 benötigt
  $E('html').setStyle('overflow', 'hidden');  //für IE7 benötigt oO
  $E('body').setStyle('overflow', 'hidden');
  window.scrollTo(0, 0);
		
    this.el = new Element('div');
    
    var coords = window.getSizes();
    
    this.el.setStyles({
       position: 'absolute'
      ,top: 0
      ,left: 0
      ,width: coords.size.x
      ,height: Math.max(coords.size.y, coords.size.bodyY)
      ,background: 'black'
      ,opacity: 0.8
      ,zIndex: 1100
    });
    
    this.el.setHTML('<img src="/theme/default/css/images/uppedLoaderr.gif" id="upL">'+$('blendS').innerHTML);
    
    $E('body').adopt(this.el);
   // this.el.addEvent('click', MM_Blend.destroy);
    
    if (window.ie) 
    {
      document.addEvent('mousewheel', this.evtWindowMousewheel);
    }
    else
    {
      window.addEvent('mousewheel', this.evtWindowMousewheel);
    }
    window.addEvent('scroll', this.evtWindowScroll);
    window.addEvent('resize', this.evtWindowResize);
  }
  
	,destroy: function()
	{
    if (window.ie) 
    {
      document.removeEvent('mousewheel', this.evtWindowMousewheel);
    }
    else 
    {
      window.removeEvent('mousewheel', this.evtWindowMousewheel);
    }
    window.removeEvent('scroll', this.evtWindowScroll);
    
    MM_Blend.el.remove();
	}
  
  ,evtWindowMousewheel: function(e)
   {
     e = new Event(e);
     e.stop();
   }
  
  ,evtWindowScroll: function()
  {
//    var coords = window.getSize();
//    MM_TP.viewerEl.display.setStyle('top', MM_TP.size.margin + coords.scroll.y);
  }
};

window.getSizes = function()
{
  var coords = window.getSize();
  if (!coords.size)
  {
    coords.size = {
       x: coords.x
      ,y: coords.y
    };
  }
  var coords2 = Client.viewportSize();
  var coords3 = $E('body').getSize();
  coords.size.y = coords2.height;
  coords.size.bodyY = coords3.y;
  return coords;
}

var Client = {
  viewportWidth: function() {
    return self.innerWidth || (document.documentElement.clientWidth || document.body.clientWidth);
  },

  viewportHeight: function() {
    return self.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight);
  },
  
  viewportSize: function() {
    return { width: this.viewportWidth(), height: this.viewportHeight() };
  }
};

function scalerImage(url, opt)
{
  url = url.replace(/\.(\w+)$/, '.' + opt + '.$1');
  url = url.replace(/media/, 'media/_generate');
	return url;
}

    
window.addEvent('domready', function()
{
  if ((el = $E('input[name=upload]')))
  {
    el.onclick = null;
    el.href = 'javascript: void(0);'
    el.addEvents({
      click: function()
      {
        MM_Blend.build();
      }
    });
  }
  /*
  setTimeout( function(){
	  if ((el = $E('a[id=caption]')))
	  {
  		el.onclick = null;
   	 	el.href = 'javascript: void(0);'
    	el.addEvents({
     	 click: function()
      	 {
      	  alert(el.id);
       	  
     	 }
        });
	  }
  }, 5000 );*/
});