/* IE6 background image flicker bug solution */
Hasbro.IE6Flicker = new Class({
	initialize : function () {
		try {document.execCommand("BackgroundImageCache", false, true);} 
		catch(err) {}
	}
});

/* kill default behavior of anchor tags with href="#" */
Hasbro.NullAnchor = new Class({
	initialize : function (id) {
		this.container = id;
		this.nullAnchors = this.container.getElementsBySelector('a.hsb_null_link').merge(this.container.getElements('a[href=#]'));
		
		this.nullAnchors.each(function(anchor) {
			anchor.onclick = function (event) {
				var evt = new Event(event);
				evt.preventDefault();
			}
		});
	}
});

Hasbro.Rollover = new Class ({
	initialize : function (el) {
		if(!$defined(el)) this.container = $E('body');
		else this.container = $(el);
		this.preload = new Hasbro.ImgPreload(this.container);
		this.images = $$('.hsb_rollover');
		
		this.preload.addEvent('onImgsLoaded', function () {
			this.images.each (function (image) {
				image.addEvent('mouseenter' , this.on.pass(image));
				image.addEvent('mouseleave' , this.off.pass(image));
			}.bind(this));
		}.bind(this));
	},
	on : function (image) {
		if (image.getTag() == 'img' || image.getTag() == 'input')
			image.src = image.src.replace('_off.', '_on.');
		else {
			image.addClass('hsb_rollover_on');
		}
	},
	off : function (image) {
		if ((image.getTag() == 'img'|| image.getTag() == 'input') && !image.hasClass('hsb_iv_trg_on'))
			image.src = image.src.replace('_on.', '_off.');
		else {
			image.removeClass('hsb_rollover_on');
		}
	}
});

/* image preloader fires 'onImgsLoaded' on completion */
Hasbro.ImgPreload = new Class({
	initialize : function (el) {
		this.container = el;
		this.imgs = this.container.getElements('img').getProperty('src');
		if (this.imgs.length > 0) {
			new Asset.images(this.imgs, {onComplete: this._doImgsLoaded.bind(this)});	
		}
	},
	_doImgsLoaded : function () {
		this.fireEvent('onImgsLoaded');
	}
});
Hasbro.ImgPreload.implement(new Events);

Hasbro.Timer = new Class({
	msecs: 1000,
	onExpire : Class.empty,
	isRunning: false,
	initialize : function(msecs) {
		($defined(msecs))? this.msecs = msecs: null;
	},
	start : function () {
		var ref = this;
		this.isRunning = true;
		this.interval = setTimeout(function() {ref.fireExpire();}, this.msecs );
		return true;
	},
	stop : function () {
		this.isRunning = false;
		clearTimeout(this.interval);
		return true;	
	}, 
	restart : function () {
		this.stop();
		this.start();
		return true;
	}, 
	fireExpire : function () {
		this.stop();
		this.fireEvent('onExpire');
		return true;
	}
});
Hasbro.Timer.implement(new Events);