function doOnLoad() {
	
}

window.addEvent('domready', loadRolloverImages);

var test = (typeof(console) != 'undefined') ? console.log : function() {};

function trover(that) {
	that.oldClassName = that.className;
	that.className = 'hover';
}

function trout(that) {
	that.className = that.oldClassName;
}



function buttonover(that) {
	if(!that.oldClassName) that.oldClassName = that.className;
	that.className = that.oldClassName + 'over';
}
function buttonout(that) {
	that.className = that.oldClassName;
}
function buttonpress(that) {
	that.className = that.oldClassName + 'down';
}
function buttonrelease(that) {
	buttonover(that);
}



function loadRolloverImages() {
	var allimgs = $$('img');

	for(var i=0; i<allimgs.length; ++i) {
		if(allimgs[i].getAttribute('hoversrc')) {
			_loadRolloverImage(allimgs[i]);
		}
	}

	var allinputs = document.getElementsByTagName('input');
	for(var i=0; i<allinputs.length; ++i) {
		if(allinputs[i].getAttribute('hoversrc')) {
			_loadRolloverImage(allinputs[i]);
		}
	}

}

function _loadRolloverImage(img) {
	preloadImage(img.getAttribute('hoversrc'));

	img.onmouseover = function() {
		var src = this.getAttribute('src');
		if(src) {
			this.setAttribute('__src_orig', src);
			this.setAttribute('__filter_orig', this.style.filter);

			if(this.style.filter && navigator.userAgent.toUpperCase().indexOf('MSIE') >= 0) {
				this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.getAttribute('hoversrc')+"', sizingMethod='scale')";
			} else {
				this.setAttribute('src', this.getAttribute('hoversrc'));
			}
		}
	};
	img.onmouseout = function() {
		var src = this.getAttribute('__src_orig');
		if(src) {
			if(this.style.filter && navigator.userAgent.toUpperCase().indexOf('MSIE') >= 0) {
				this.style.filter = this.getAttribute('__filter_orig');
			} else {
				this.setAttribute('src', src);
			}
		}
	};

}

function preloadImage(href) {
	if(!window.preloadImageList) window.preloadImageList = new Array();
	var i = window.preloadImageList.length;

	window.preloadImageList[i] = new Image();
	window.preloadImageList[i].src = href;
}


function popupWin(that, w, h, options) {
	if(!w) w = 500;
	if(!h) h = 500;

	var x = (screen.availWidth - w) / 2;
	var y = (screen.availHeight - h) / 2;

	if(!options) options = '';

	var optslist = new Array();
	optslist[optslist.length] = 'width='+w;
	optslist[optslist.length] = 'height='+h;
	optslist[optslist.length] = 'scrollbars=auto';
	optslist[optslist.length] = 'resizable=yes';
	optslist[optslist.length] = 'left='+x;
	optslist[optslist.length] = 'top='+y;

	var bits = options.split(/,/);
	for(var i=0; i<bits.length; ++i) {
		var b = bits[i].split(/=/);
		optslist[optslist.length] = b[0] + '=' + b[1];
	}
	var optionstring = optslist.join(',');



	var href;
	if(that.href) href = that.href;
	else href = that;

	var win = window.open(that.href, 'popwin', optionstring);

	win.resizeTo(w, h);
	win.focus();

	return false;
}

function getLeft(obj) {
	return (obj.offsetParent==null ? obj.offsetLeft : obj.offsetLeft + getLeft(obj.offsetParent));
}
function getTop(obj) {
	return (obj.offsetParent==null ? obj.offsetTop : obj.offsetTop + getTop(obj.offsetParent));
}


function hover(that, classname) {
	var oclassname = that.className;
	if(!classname) classname = oclassname + '_hover';

	that.setAttribute('originalClassName', oclassname);
	that.className = classname;

	that.onmouseout = function() {
		unhover(this);
	}
}

function unhover(that) {
	that.className = that.getAttribute('originalClassName');

}



ScrollFeedback = new Class({
	Implements: [Options],
	options: {
		timeout: 6000,
		duration: 1000,
		items: []
	},

	initialize: function(el, options) {
		this.setOptions(options);
		this.el = $(el);
		if(!this.el) return;

		this.timer = null;
		this.cur = 0;

		this.feedback = [];
		for(var i=0; i<this.options.items.length; ++i) {
			var buf = '<table width="100%" height="100%" cellpadding="0" cellspacing="0"><tr>';
			buf += '<td align="center" height="100%" style="color:white;">' + this.options.items[i] + '</td>';
			buf += '</tr></table>';

			
			var item = new Element('div', {
				id: 'divScrollFeedback'+i,
				styles: {
					height: 90
				
				}
			})
			.set('html', buf)
			.inject(this.el);

			this.feedback.push(item);			
		}

		this.el.addEvents({
			mouseenter: function() {
				this.pause();
			}.bind(this),
			mouseleave: function() {
				this.resume();
			}.bind(this)
		});


		this.el.scrollTo(0,0);
		this.resume();
	},

	pause: function() {
		clearTimeout(this.timer);
	}, 

	resume: function() {
		clearTimeout(this.timer);
		this.timer = setTimeout(function() {
			this.scroll();
		}.bind(this), this.options.timeout);
	},

	scroll: function() {
		clearTimeout(this.timer);
		++this.cur;
		if(this.cur >= this.feedback.length) {
			this.cur = 0;
			this.el.scrollTo(0,0);
		}
		else {			
			new Fx.Scroll(this.el, {
				duration: this.options.duration
			}).toElement(this.feedback[this.cur]);
		}
		this.resume();
	}
});











