function tr(file){
	if(file!="undefined"){
		var properties = {};
		properties.content='Videos/WMV/' + file;
		window.emosPropertiesEvent(properties);
	}
}

var Video = {};
Video.Box = Class.create();
Object.extend(Prototype.Browser, {
    IE6: (Prototype.Browser.IE && (/MSIE 6./).test(navigator.userAgent)),
	WebKit419: (Prototype.Browser.WebKit && !document.evaluate)
});
Object.extend(Video.Box.prototype, {
  initialize: function() {
  	
	document.body.insertBefore(this.video_box = new Element("div", {
		id: "video"
	}).setStyle({
		backgroundImage: "url(images/content/video_layer_background.gif)",
		width: "440px",
		height: "340px"
	}).hide().insert(this.close_box = new Element("div", {
		id: "flv_close"
	}).setStyle({
		cssFloat: "right",
		paddingRight: "6px",
		height: "20px"
	})).insert(new Element("div", {
		id: "flv_player"
	}).setStyle({
		padding: "20px"
	})), document.body.childNodes[0]);

	Object.extend(this.video_box, {
      	display: 'none'
    });

	this.close_box.innerHTML="<a href=\"#\" onclick=\"$('video').hide();return false\" title=\"Video schließen\"><img style=\"margin-top:3px\" src=\"images/videobox/close.jpg\" border=\"0\"></a>";
	this.tracking=false;
	this.econdaTitle;
    this.createOverlay();
    this.video_box.show = this.show.bind(this);
    this.video_box.setTitle = this.setTitle.bind(this);
    this.video_box.hide = this.hide.bind(this);
    this.parent_element = this.video_box.parentNode;
    this.video_box.style.position = "fixed";
	
	if (Prototype.Browser.IE6) {
	 	this.video_box.style.position = "absolute";
	};
	
	var e_dims = Element.getDimensions(this.video_box);
	var b_dims = Element.getDimensions(this.overlay);
	this.video_box.style.left = ((b_dims.width/2) - (e_dims.width/2)) + 'px';
	this.video_box.style.top = ((b_dims.height/2) - (e_dims.height/2)) + 'px';
	this.video_box.style.zIndex = this.overlay.style.zIndex + 1;
  },
  createOverlay: function() {
	if($('video_overlay')) {
	  this.overlay = $('video_overlay');
	} else {
	  this.overlay = document.createElement('div');
	  this.overlay.id = 'video_overlay';
	  Object.extend(this.overlay.style, {
	  	position: 'fixed',
	  	top: 0,
	  	left: 0,
	  	zIndex: 2999,
	  	width: '100%',
		height: '100%',	
	  	backgroundColor: '#000',
	  	display: 'none'
	  });
	  document.body.insertBefore(this.overlay, document.body.childNodes[0]);
	}
	if (Prototype.Browser.Gecko || Prototype.Browser.IE6) {
		this.overlay.style.position='absolute';	
	}
	this.addObservers();
  },

  moveVideoBox: function(where) {
    Element.remove(this.video_box);
    if(where == 'back')
      this.video_box = this.parent_element.appendChild(this.video_box);
    else
      this.video_box = this.overlay.parentNode.insertBefore(this.video_box, this.overlay);
  },
  setTitle: function(title) {
	  this.econdaTitle = title;
  },
  show: function(flv,img) {

	if(arguments[2]!=undefined && arguments[2]!='') {
		if(arguments[2]=='patracking') this.tracking=true;
		this.javascriptid=arguments[3];
	} else {
		this.tracking=false;
		this.javascriptid='videobox';
	}
    this.overlay.onclick = this.hide.bindAsEventListener(this);
	if (Prototype.Browser.IE6) {
		this.selectBoxes('hide');
	}
	if (Prototype.Browser.IE6) {
		var e_dims = Element.getDimensions(this.video_box);
		this.video_box.style.top = (document.documentElement.scrollTop +(document.documentElement.clientHeight/2) -(e_dims.height/2)) + 'px';
	}
    x=new Effect.Appear(this.overlay, {
		duration: 0.3, 
		from: 0.0, 
		to: 0.7,
		queue: {scope: 'fadein', position: 'end' },
		afterFinish: function(obj){
			$('video').style.display = '';
		}
	});	
    
	var tm = new SWFObject('jw_flv_player/mediaplayer.swf', 'videobox', '400', '300', '8', '#FFFFFF');
	tm.addParam('allowfullscreen', 'true');
	tm.addParam('allowscriptaccess', 'always');
	tm.addParam('wmode', 'opaque');
	tm.addVariable('file', flv);
	tm.addVariable('title', this.econdaTitle);
	tm.addVariable('image', img);
	tm.addVariable('usefullscreen', 'true');
	tm.addVariable('autostart', 'true');
	tm.addVariable('height', '300');
	tm.addVariable('width', '400');
	tm.addVariable('searchbar', 'false');
	tm.addVariable("javascriptid", this.javascriptid);
	tm.addVariable('enablejs', 'true');
	tm.addVariable('screencolor','0xFFFFFF');
	tm.write('flv_player');
  },
  hide: function() {
	try
  	{
		this.sendEvent('videobox','stop');
	}
	catch(err) {};
	if (Prototype.Browser.IE6) {
		this.selectBoxes('show');
		this.overlay.style.display = 'none';
	} else {
		new Effect.Fade(this.overlay, {duration: 0.3});
	}
    this.video_box.style.display = 'none';
  },
  
  maxOverlay: function(){	
	this.overlay.setStyle(this.pixelClone(document.viewport.getDimensions()));
    this.overlay.setStyle(this.pixelClone(this.getScrollDimensions()));
  },
  
  position: function(){
	if (!Prototype.Browser.IE6) {
		var e_dims = Element.getDimensions(this.video_box);
		this.video_box.style.left = ((document.viewport.getDimensions().width/2) - (e_dims.width/2)) + 'px';
		this.video_box.style.top = ((document.viewport.getDimensions().height/2) - (e_dims.height/2)) + 'px';
		
	}
  },
  
  pixelClone: function(A){
	var B = {};
	Object.keys(A).each(function(C){
	    B[C] = A[C] + "px";
	});
	return B;
  },
  
  addObservers: function(){ 
  
  	if (Prototype.Browser.Gecko || Prototype.Browser.IE6) {
	 	Event.observe(window, "scroll", this.maxOverlay.bindAsEventListener(this));
		Event.observe(window, "resize", this.maxOverlay.bindAsEventListener(this));
	 }     
		Event.observe(window, "scroll", this.position.bindAsEventListener(this));
		Event.observe(window, "resize", this.position.bindAsEventListener(this));
  },
  
  getScrollDimensions: function(){
        var A = {};
        $w("width height").each(function(E){
            var C = E.capitalize();
            var B = document.documentElement;
            A[E] = Prototype.Browser.IE ? [B["offset" + C], B["scroll" + C]].max() : Prototype.Browser.WebKit ? document.body["scroll" + C] : B["scroll" + C];
        });
        return A
  },
	
  selectBoxes: function(what) {
    $A(document.getElementsByTagName('select')).each(function(select) {
      Element[what](select);
    });
    if(what == 'hide')
      $A(this.video_box.getElementsByTagName('select')).each(function(select){Element.show(select)})
  },
  
  sendEvent: function (swf,typ,prm) {
		this.thisMovie(swf).sendEvent(typ,prm); 
  },
  
  thisMovie: function (swf) {
		if(navigator.appName.indexOf("Microsoft") != -1) {
			return window[swf];
		} else {
			return document[swf];
		}
  }

});
 
document.observe("dom:loaded", function(){
	new Video.Box();
});



