//declaring the class
var WindowWatcher = Class.create();

//defining the rest of the class implementation
WindowWatcher.prototype = {
  initialize: function() {
	this.registeredObjects = new Array;
        this.Window = window;
	this.Window.onload = this.update.bindAsEventListener(this);
	this.Window.onunload = this.onunloadEvent.bindAsEventListener(this);
        this.Window.onresize = this.onresizeEvent.bindAsEventListener(this);
  },
  update: function(event) {
        this.resizeBackground($('backgroundimage'));
	WindowUtilities.enableScreen();
	this.reloadObjects();
	// activate tooltips for thumbnaillinks on load 
	$$('.thumbnaillinks ul li.item img').each( function(link) {
			new Tooltip(link, {mouseFollow: false,
				backgroundColor:'',
				borderColor:'',
				textColor: '',
				textShadowColor: '',
				maxWidth: 360,
				delay: 0,
				opacity: 0.9,
				appearDuration:0.25,
				hideDuration:0.25
				});
	})
  },
  onunloadEvent: function(event) {
	// disable the screen overlay
	WindowUtilities.enableScreen();
  },
  onresizeEvent: function(event) {
        // resize backgroundimage
        this.resizeBackground($('backgroundimage')); 
  },
  registerObject: function (container, bgcolor, location, flashvars, version, cl, width, heigth) {
		i = this.registeredObjects.length + 1;
		this.registeredObjects[i] = new Array;
		this.registeredObjects[i][0] = container;
		this.registeredObjects[i][1] = bgcolor;
		this.registeredObjects[i][2] = location;
		this.registeredObjects[i][4] = flashvars;
	    this.registeredObjects[i][5] = version;
	    this.registeredObjects[i][6] = cl;
		this.registeredObjects[i][7] = width;
	    this.registeredObjects[i][8] = heigth;
	    
  },
  reloadObjects: function() {
	for(var i=1; i<this.registeredObjects.length; i++) {
		HTMLstr  = '<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+this.registeredObjects[i][3]+'\" class=\"'+ this.registeredObjects[i][5]+'\" width=\"'+ this.registeredObjects[i][7] + '\" height=\"'+ this.registeredObjects[i][8] + '\">';
	 	HTMLstr += '<param name=\"allowScriptAccess\" value="sameDomain\" />';
	    HTMLstr += '<param name=\"movie\" value=\"'+ this.registeredObjects[i][2] + '\" /><param name=\"quality\" value=\"high\" />';
	    HTMLstr += '<param name=\"bgcolor\" value=\"'+this.registeredObjects[i][1]+'\"/>';
	    HTMLstr += '<param name=\"FlashVars\" value=\"'+this.registeredObjects[i][4]+'\"/>';	
	    HTMLstr += '<embed FlashVars=\"'+this.registeredObjects[i][4]+'\" src=\"'+this.registeredObjects[i][2]+'\" quality=\"high\" class=\"'+ this.registeredObjects[i][6] + '\" allowScriptAccess=\"sameDomain\" width=\"'+ this.registeredObjects[i][7] + '\" height=\"'+ this.registeredObjects[i][8] + '\"  type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />'
	    HTMLstr += '</object>';	
		$(this.registeredObjects[i][0]).innerHTML = HTMLstr;
	}	
  },
  resizeBackground: function(img) {
   if (img != null) {
     var imageratio = img.height / img.width;
     var dim = document.viewport.getDimensions();
     var winheight = dim.height;
     var winwidth = dim.width;
     var winratio = winheight / winwidth;

if(imageratio > winratio) {
     img.width = winwidth;
    } else {
     img.height = winheight;
     img.width = winheight/imageratio;
     }

   }
  }

};

var watcher = new WindowWatcher();
