var Overlay = new Class({
	initialize: function(element, options) {
		if(Browser.loaded){
			this.setup(element, options);
		} else{
			window.addEvent('domready', this.setup.pass([element, options]));
		}
	},
	setup: function(element, options) {   
	       
    var showtimer;
    var hidetimer;
    var delay = 0;
    var isopen = false;

    var showbox = new Fx.Morph('userStoverlayPi1OL');
    
    $$('div.userStoverlayPi1OLItem').setStyle('display', 'none');
  
  	$$('a.TGElem').addEvents({
      mouseenter: function(){
       $clear(hidetimer);
			 showtimer = showfunction.delay(delay, this);
      },
      mouseleave: function(){
        $clear(showtimer);
        hidetimer = hidefunction.delay(delay, this);
      }
    });
    $('userStoverlayPi1OL').addEvents({
      mouseenter: function(){
       $clear(hidetimer);
      },
      mouseleave: function(){
        $clear(showtimer);
        hidetimer = hidefunction.delay(delay, this);
      }
    });
    var showfunction = function(){ 
      var flashpos = flashStartEnd(1);
      $(options['flashID']).SetVariable('cache', '1');
      
      $$('div.userStoverlayPi1OLItem').setStyle('display', 'none');
      var divid = this.id;
      divid = 'OL'+divid;
      $(divid).setStyle('display', 'block');
      
      delay = options['delay'];
      
      if (!isopen) {
        $('userStoverlayPi1OL').setStyle('top', flashpos['startY']); 
        $('userStoverlayPi1OL').setStyle('left', flashpos['startX']); 

        showbox.start({
    			height: '300px',
    			top: flashpos['endY']
    		});
  		
  		  isopen = true;
  		}
  		
    }; 
    var hidefunction = function(){ 
      var flashpos = flashStartEnd(0);
      $(options['flashID']).SetVariable('cache', '0');
      
      delay = 0;
      
      if (isopen) {
        $('userStoverlayPi1OL').setStyle('top', flashpos['startY']);
        $('userStoverlayPi1OL').setStyle('left', flashpos['startX']); 

       
        showbox.start({
    			height: '0px',
    			top: flashpos['endY']
    		});
    		
    		isopen = false;
    	}
    }; 
  
    var flashStartEnd = function(direction){
      var flashelem = $(options['flashDiv']);
      var flashpos = flashelem.getCoordinates();
      var pos = new Array();
      if (direction == 1) {
        pos['startY'] = flashpos['top']+flashpos['height'];
        pos['endY'] = flashpos['top']+flashpos['height']-300;
        pos['startX'] = flashpos['left']+((flashpos['width']-630)/2);
        pos['endX'] = pos['startX'];
      } else {
        pos['startY'] = flashpos['top']+flashpos['height']-300;
        pos['endY'] = flashpos['top']+flashpos['height'];
        pos['startX'] = flashpos['left']+((flashpos['width']-630)/2);
        pos['endX'] = pos['startX'];
      }
      
      return pos;
    };
  

	}
});

