/**
 * @version     $Id: mmstage.min.js 624 2011-01-13 02:10:25Z martin $
 * @package     Joomla
 * @subpackage  System - mmBackground Free
 * @author      Martin Gray <author [at] mmPlugins.com>
 * @copyright   Copyright (C) 2009-2011 mmPlugins | All rights reserved
 * @license     GNU/GPL v.2
 * @see         /plugins/system/mmbackground/mmbackground/LICENSE.php
 */

var mmStage=new Class({Implements:[Options,Events],workspaces:new Hash({}),widgets:new Hash({}),position:{},dimensions:{},currentWorkspace:null,options:{element:'mmStage',height:0,width:0,x:0,y:0,opacity:1,zIndex:333,viewportMargin:0,onInit:Class.empty},initialize:function(options){this.setOptions(options);$(document.body).setStyles({padding:'0px',margin:'0px',overflow:'hidden'});if(this.options.width==0)this.options.width=this.getWinWidth();if(this.options.height==0)this.options.height=this.getWinHeight();this.position.x=this.options.x;this.position.y=this.options.y;this.dimensions.x=this.options.width;this.dimensions.y=this.options.height;this.stage=$(this.options.element);this.resize(this.dimensions.x,this.dimensions.y,this.position.x,this.position.y);window.addEvent('resize',function(){this.adjust();}.bind(this));this.fireEvent('onInit');},getWinHeight:function()
{if(window.opera)return window.innerHeight;else return window.getSize().y;},getWinWidth:function(){if(window.opera)return window.innerWidth;else return window.getSize().x;},resize:function(width,height,x,y){this.stage.setStyles({top:0,left:0,width:width+'px',height:height+'px',position:'absolute',overflow:'hidden',scroll:'none'});},adjust:function(){this.dimensions.x=this.getWinWidth();this.dimensions.y=this.getWinHeight();this.stage.setStyles({width:this.dimensions.x+'px',height:this.dimensions.y+'px'});if(this.currentWorkspace!=null){var marginLeft=this.workspaces.get(this.currentWorkspace)[0]*this.dimensions.x;var marginTop=this.workspaces.get(this.currentWorkspace)[1]*this.dimensions.y;this.stage.setStyles({marginTop:-marginTop+'px',marginLeft:-marginLeft+'px'});}
this.workspaces.each(function(workspace,elId){var x=workspace[0]*this.dimensions.x;var y=workspace[1]*this.dimensions.y;$(elId).setStyles({left:x+'px',top:y+'px',width:this.dimensions.x+'px',height:this.dimensions.y+'px'});},this);this.widgets.each(function(widget){widget.adjust();},this);},registerWorkspace:function(elId,x,y){var location=new Array();location.push(x);location.push(y);this.workspaces.set(elId,location);x=this.workspaces.get(elId)[0]*this.dimensions.x;y=this.workspaces.get(elId)[1]*this.dimensions.y;$(elId).setStyles({left:x+'px',top:y+'px',width:this.dimensions.x+'px',height:this.dimensions.y+'px',position:'absolute',zIndex:this.options.zIndex+1});},registerWidget:function(identifier,widget){this.widgets.set(identifier,widget);},moveToWorkspace:function(identifier){this.currentWorkspace=identifier;var marginLeft=this.workspaces.get(identifier)[0]*this.dimensions.x;var marginTop=this.workspaces.get(identifier)[1]*this.dimensions.y;var switchWorkspace=new Fx.Styles(this.stage,{duration:600,transition:Fx.Transitions.Sine.easeOut});switchWorkspace.start({marginTop:-marginTop+'px',marginLeft:-marginLeft+'px'});},getDimensions:function(){return this.dimensions;},getPosition:function(){return this.position;}});

