
if (!document.trace) {
	this.trace = function(output) {
		//if (console.log && output) console.log(output);
	}
}

/**
 * Scroll Page Button
 * @uses mootools-release-1.11.js
 */
var ScrollPageButton = new Class({
	
	initialize : function(container, styles) {
		trace('ScrollPageButton.initialize()');
		
		this.container = container;
		this.view = {};
		this.styles = styles;
		
		this.rendered = false;
		this.showing = true;
		this.enabled = true;
		
		this.render();
	},
	
	
	render : function() {
		trace('ScrollPageButton.render()');
		
		this.rendered = true;
		
		var view = new Element('div');
		view.setStyle('overflow', 'hidden');
		view.setStyle('position', 'absolute');
		view.setStyle('z-index', '10');
		view.setStyle('width', this.styles.width + 'px');
		view.setStyle('height', this.styles.height + 'px');
		view.setStyle('top', this.styles.y + 'px');
		view.setStyle('left', this.styles.x + 'px');
		view.setStyle('cursor', 'pointer');
		if (window.ie && !window.ie7) {
			var glyph = new Element('div');
			glyph.setStyle('width', this.styles.width + 'px');
			glyph.setStyle('height', this.styles.height + 'px');
			glyph.setStyle('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + this.styles.background + '")');
			glyph.injectInside(view);
		} else {
		view.setStyle('background', 'url(' + this.styles.background + ') no-repeat');
		}
		view.injectInside(this.container);
		this.view = view;
				
		this.view.addEvent('mouseover', this.onMouseOver.bindWithEvent(this));
		this.view.addEvent('mouseout', this.onMouseOut.bindWithEvent(this));
		this.view.addEvent('mousedown', this.onMouseDown.bindWithEvent(this));
	},
	
	
	onMouseOver : function(e) {
		
		e.preventDefault();
		
		if (!this.rendered || !this.enabled) return;
		
		if (!window.ie || window.ie7) {
		this.view.setStyle('background-position', '0px -19px');
		} else {
			var glyph = this.view.getFirst();
			glyph.setStyle('top', -this.styles.height + 'px');
		}
		
	},
	
	
	onMouseOut : function(e) {
		
		e.preventDefault();
		if (!this.rendered || !this.enabled) return;
		
		if (!window.ie || window.ie7) { 
		this.view.setStyle('background-position', '0px 0px');
		} else {
			var glyph = this.view.getFirst();
			glyph.setStyle('top', '0px');
		}
	},
	
	
	onMouseDown : function(e) {
		
		e.preventDefault();
		
		if (!this.rendered || !this.enabled) return;
		this.view.fireEvent('onScrollPage');
	},
	
	
	disable : function() {
		trace('ScrollPageButton.disable()');
		
		if (!this.rendered) return;
		this.enabled = false;
		this.view.setStyle('opacity', 0.25);
	},
	
	
	enable : function() {
		trace('ScrollPageButton.enable()');
		
		if (!this.rendered) return;
		this.enabled = true;
		this.view.setStyle('opacity', 1.00);
	},
	
	
	hide : function() {
		trace('ScrollPageButton.hide()');
		
		if (!this.rendered) return;
		this.showing = false;
		this.view.setStyle('display', 'none');
	},
	
	
	show : function() {
		trace('ScrollPageButton.show()');
		
		if (!this.rendered) return;
		this.showing = true;
		this.view.setStyle('display', 'block');
	},
	
	
	toString : function() {
		return "[ScrollPageButton]";
	}
});