// STYLING FILE INPUTS 1.0 | Shaun Inman <http://www.shauninman.com/> | 2007-09-07
if (!window.SI) { var SI = {}; }
SI.Files = {
	htmlClass : 'SI-FILES-STYLIZED',
	fileClass : 'file',
	wrapClass : 'cabinet',
	
	fini : false,
	able : false,
	init : function()
	{
		this.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.able = true;
		
		var html = document.getElementsByTagName('html')[0];
		html.className += (html.className != '' ? ' ' : '') + this.htmlClass;
	},
	
	stylize : function(elem) {
		if (!this.fini) { this.init(); }
		if (!this.able) { return; }
    elem = $(elem);

	  $(elem.parentNode).addClassName('default_button_mini');

    elem.parentNode.file = elem;
		elem.parentNode.onmousemove = function(e) {
			if (typeof e == 'undefined') e = window.event;
			if (typeof e.pageY == 'undefined' &&  typeof 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.offsetLeft;
				oy = elem.offsetTop;
				while (elem = elem.offsetParent) {
					ox += elem.offsetLeft;
					oy += elem.offsetTop;
				}
			}

			var x = e.pageX - ox;
			var y = e.pageY - oy;
			var w = 190; //this.file.offsetWidth;
			var h = 35;//this.file.offsetHeight;

			this.file.style.top		= y - h  + 'px';
			this.file.style.left	= x - w + 'px';
			this.file.style.cursor	= 'pointer';
		};

    // Event.observe(elem.parentNode, 'mouseover', function(){ setTimeout(elem.blur, 10);});
	},
	
	stylizeAll : function() {
		if (!this.fini) { this.init(); }
		if (!this.able) { return; }
		
    $$('.'+this.wrapClass+' input.'+this.fileClass).each(function(fi){
		  SI.Files.stylize(fi);
    });
	}
};

