// Adapted from the credits below...
// STYLING FILE INPUTS 1.0 | Shaun Inman <http://www.shauninman.com/> | 2007-09-07
// if (!window.SI) { var SI = {} ; } ;
var BNFileInput = new Class({

	Implements: Options,

	options: {
		htmlClass: 'BNfiles',
		fileClass: 'file_input',
		wrapClass: 'file_input_container',
		
		fini: false,
		able: false
	},

	initialize: function(options){
		this.setOptions(options) ;
		this.options.fini = true ;
		
		var ie = 0 //@cc_on + @_jscript_version
		if (window.opera || (ie && ie < 5.5) || !document.getElementsByTagName) { return ; } // no support for opacity or the DOM
		this.options.able = true ;
		
		var html = $(document).getElements('html')[0] ;
		html.addClass(this.options.htmlClass)  ;
	},
	
	stylize: function(elem){
		if (!this.options.fini) { this.init() ; } ;
		if (!this.options.able) { return ; } ;
		elem.getParent().addEvent('mousemove', function(e){
			if ($type(e) == 'undefined') { e = window.event ; }
			if ($type(e.pageY) == 'undefined' &&  $type(e.clientX) == 'number' && document.documentElement)
			{
				e.pageX = e.clientX + document.documentElement.scrollLeft ;
				e.pageY = e.clientY + document.documentElement.scrollTop ;
			}

			// var ox = oy = 0 ;
			// var elem = this ;
			// if (elem.offsetParent)
			// {
			// 	ox = elem.getPosition().x ;
			// 	oy = elem.getPosition().y ;
			// 	while (elem = elem.offsetParent)
			// 	{
			// 		ox += elem.getPosition().x ;
			// 		oy += elem.getPosition().y ;
			// 	}
			// }

			// var x = e.client.x - ox ;
			// var y = e.client.y - oy ;
			// var w = this.getSize().x ;
			// var h = this.getSize().y ;

			// this.setStyle('top', (y - (h / 2)  + 'px')) ;
			// this.setStyle('left', (x - (w - 30) + 'px')) ;
		}.bind(elem.getParent().getChildren(this.fileClass)[0])) ;
	},
	
	stylizeById: function(id){
		this.stylize($(id)) ;
	},
	
	stylizeAll: function(){
		if (!this.options.fini) { this.init() ; }
		if (!this.options.able) { return ; }
		
		var inputs = $(document).getElements('input') ;
		for (var i = 0 ; i < inputs.length ; i++)
		{
			var input = inputs[i] ;
			if (input.getProperty('type') == 'file' && input.hasClass(this.options.fileClass) && input.getParent().hasClass(this.options.wrapClass))
			{
				this.stylize(input) ;
			}
		}
	}
}) ;
