
var Agro = new Class({
	options:{
		'wrapper': 			'wrapper',
		'office':				'office',
		'menu': 				'menu',
		'topOffset': 			'40',
		'bottomOffset' : 		'0'
	},
	initialize: function(options){
		this.office = $(this.options.office);
		this.moveOffice = new Fx.Tween(this.office);
		
		this.setOptions(options);
		this.setWrapperHeight();
		this.adjustElements();
		this.redirect();
		
		
		window.addEvent('resize', function(){ 
			this.initialize();
		}.bind(this));
	},
	setWrapperHeight: function() {
		this.windowSize = document.getSize();
		var wrapperHeight = (this.windowSize.y - this.options.topOffset);
		var wrapper = $(this.options.wrapper);
		
		wrapper.set('styles', {
			'height': wrapperHeight,
			'top': this.options.topOffset,
			'left': 0
		});
	},
	adjustElements: function() {
		this.officeSize = this.office.getSize();
		var centerX = (this.officeSize.x)/2;
		var centerY = (this.officeSize.y)/2;
		
		$$('.theTip', '.link').each(function(el) {
			var cords = el.get('rel').split('::');
			var top = cords[0];
			var left = cords[1];
			
			el.set('styles', {
				'left': centerX + left.toFloat(),
				'top': centerY + top.toFloat()
			});
		});
		
		$('center').setStyle('margin-left', (this.windowSize.x)/2 - 115 )
	},
	centerOffice: function() {
		var officeOffset = (this.officeSize.x - this.windowSize.x)/2;
		this.moveOffice.start('left', '-'+officeOffset );
	},
	redirect: function() {
		switch(location.hash)
		{
			case '#left':
				this.moveLeft();
				break;
			case '#right':
				this.moveRight();
				break;
			case '#center':
			default:
				this.centerOffice();
				break;
		}
	},
	moveRight: function() {
		var officeLeft = parseFloat(this.office.getStyle('left'));
		var move = this.officeSize.x - this.windowSize.x;
		this.moveOffice.start('left', '-'+ move);
		//alert('right');
	},
	
	moveLeft: function() {
		var officeLeft =this.office.getStyle('left').toFloat();
		var move = officeLeft + 600;
		this.moveOffice.start('left', 0);
		//alert('left');
	}
	
});
Agro.implement(new Options);