
 
/*
MooSizer - a Mootools rewrite of: Supersized - Full Screen Background/Slideshow jQuery Plugin
 
License:
	MIT-style license.
 
Credits:
	Original jQuery supersized script By Sam Dunn ( <http://buildinternet.com> / <http://onemightyroar.com>	 )
	found here: <http://buildinternet.com/2009/02/supersized-full-screen-backgroundslideshow-jquery-plugin/>
	rewritten for Mootools 1.2 by Markus Timtner ( <http://mtness.net> ) 2009-03-27 1100-1500 GMT+1
*/
 
var DEBUG;(typeof(window.console) != "undefined")?DEBUG=1:DEBUG=0;//alert(DEBUG);
 
var mooSizer = new Class({
 
	Implements: [Options, Events],
	options: {
		startwidth: 640,  
		startheight: 480,
		minsize: .5,
		slideshow: 1,
		slideinterval: 5000,
		bgElement: ''
	},
 
	initialize: function(options){
        this.setOptions(options);
 
		//Define image ratio & minimum dimensions
		var minwidth	= this.options.minsize*(this.options.startwidth);
		var minheight	= this.options.minsize*(this.options.startheight);
		var ratio		= this.options.startheight/this.options.startwidth;
 
		this.resizenow(minwidth,minheight,ratio);
 
 		window.addEvent('resize', function(){
			this.resizenow(minwidth,minheight,ratio);
		}.bind(this));
 
	},
 
	resizenow: function(minwidth,minheight,ratio) {
 
		//Gather browser and current image size
		var imagesize		= $(this.options.bgElement).getSize();
		var imagewidth		= imagesize.x;
		var imageheight		= imagesize.y;
		var clientsize		= window.getSize();
		var browserwidth	= clientsize.x;
		var browserheight	= clientsize.y;
 
 		//Check for minimum dimensions
		if ((browserheight < minheight) && (browserwidth < minwidth)){
				$(this.options.bgElement).setStyle('height',minheight);
				$(this.options.bgElement).setStyle('width',minwidth);
		}
		else{	
			//When browser is taller	
			if (browserheight > browserwidth){
				imageheight = browserheight;
					$(this.options.bgElement).setStyle('height',browserheight);
				imagewidth = browserheight/ratio;
					$(this.options.bgElement).setStyle('width',imagewidth);
 
				if (browserwidth > imagewidth){
					imagewidth = browserwidth;
						$(this.options.bgElement).setStyle('width',browserwidth);
					imageheight = browserwidth * ratio;
						$(this.options.bgElement).setStyle('height',imageheight);
				}
			}			
			//When browser is wider
			if (browserwidth >= browserheight){
				imagewidth = browserwidth;
					$(this.options.bgElement).setStyle('width',browserwidth);
				imageheight = browserwidth * ratio;
					$(this.options.bgElement).setStyle('height',imageheight);
 
				if (browserheight > imageheight){
					imageheight = browserheight;
						$(this.options.bgElement).setStyle('height',browserheight);
					imagewidth = browserheight/ratio;
						$(this.options.bgElement).setStyle('width',imagewidth);
				}
			}
		}
	}
 
});
 
/*************************************************************/
 
document.addEvent('domready', function(){
 
 	moosizer = new mooSizer({ bgElement:'supersize' });
 
});
 

