function closeFlash(){
    $$('#flashTeaser object')[0].remove();
    $('flashTeaser').remove();
    $('flashTeaserOverlay').remove();
    cleanScreen.init('block');
}

var getPageSize = function() {
   var docElem = document.documentElement
   var width = self.innerWidth || (docElem&&docElem.clientWidth) || document.body.clientWidth;
   var height = self.innerHeight || (docElem&&docElem.clientHeight) || document.body.clientHeight;
   var ret = new Array(parseInt(width),parseInt(height));
   return ret;
}

var cleanScreen = {
    items: [],
    init: function(display){
        $$('select, input, #construction').each(function(item, index){
            if(display == 'none'){
                this.items[index] = item.getStyle('display');
                item.setStyle({'display':display});
            }else{
                item.setStyle({'display':this.items[index]});
            }
        }.bind(this));
    }
}

var Teaser = Class.create();
Teaser.prototype = {
	initialize:  function(param){
       	cleanScreen.init('none');
       	var sizes = getPageSize();
       	var content = '<div id="flashTeaserOverlay" style="position: absolute; z-index: 99; width: 100%; height: '+sizes[1]+'px; background-color: #000; filter: alpha(opacity=80); -moz-opacity : 0.8;opacity: 0.8;"></div><div id="flashTeaser" style="position: absolute; z-index: 100; left: 211px; top: 72px;"><p style="text-align:right"><a href="javascript:closeFlash();"><img src="/images/close-video.gif" alt="close" /></a></p><object type="application/x-shockwave-flash" data="'+param.src+'" width="'+param.width+'" height="'+param.height+'" /><param name="movie" value="'+param.src+'" /><param name="wmode" value="transparent"></object></div>';
       	new Insertion.Before('page', content);
  		Position.Center($('flashTeaser'));
		Event.observe($('flashTeaserOverlay'), 'click', function(){
        closeFlash();
      });
   }
}

Position.getWindowSize = function(w) {
  var width, height;
  w = w ? w : window;
  width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
  height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);

  return { width: width, height: height };
}

Position.Center = function(element, parent) {
        var w, h, pw, ph;
        var d = Element.getDimensions(element);
        w = d.width;
        h = d.height;
        Position.prepare();
        if (!parent) {
                var ws = Position.getWindowSize();
                pw = ws.width;
                ph = ws.height;
        } else {
                pw = parent.offsetWidth;
                ph = parent.offsetHeight;
        }
        //element.style.top = (ph/2) - (h/2) -  Position.deltaY + "px";
        element.style.left = (pw/2) - (w/2) -  Position.deltaX + "px";
}

function openvideobox() {
	new Teaser({'width':600, 'height':337, 'src':'/flash/stade_lille.swf'});
}

Event.observe(window, 'load', function(){
	$$('#menu_bas li').each(function(elem){
		Event.observe(elem, 'mouseover', function(){
			if($(elem).getElementsBySelector('ul')) {
				var ulList = $(elem).getElementsBySelector('ul');
				if(ulList.length > 0) {
					ulList[0].show();
				}
			}
		});
		Event.observe(elem, 'mouseout', function(){
			if($(elem).getElementsBySelector('ul')) {
				var ulList = $(elem).getElementsBySelector('ul');
				if(ulList.length > 0) {
					ulList[0].hide();
				}
			}
		});
 	});
	if($$('#bandeau_bas a#video').length > 0) {  
		Event.observe($$('#bandeau_bas a#video')[0], 'click', function(event){
			Event.stop(event);
			openvideobox();
		});
	}
});
