var Dom = YAHOO.util.Dom,
	YEvent = YAHOO.util.Event;

IRIS.namespace('eaauctions');
YEvent.addListener(window, 'load', function() {
	var images = document.getElementsByTagName('IMG'), i;
	for( i = 0; i < images.length; i++ ) {
		images[i].onmousedown = function(e) {
			if( navigator.appName == 'Microsoft Internet Explorer' ) {
				if( event.button == 2 ) {
					alert("No right click please");
					return false;
				}
			}
			else if( e.button == 2 ) {
				return false;
			}
		};
	}
	if( !IRIS.widget.ImageSwitcher ) {
		return;
	}
	IRIS.widget.ImageSwitcher.init('#topNav > ul > li > a');
});
document.onselectstart = function(e) {
	return false;
};

IRIS.eaauctions = {};

IRIS.eaauctions.ItemList = {
	lastRotation: 0,
	easing: null,
	interval: 10,
	duration: 1,
	rotateFeatured: function( cfg ) {
		if( !this.easing && YAHOO.util.Easing ) {
			this.easing = YAHOO.util.Easing.easeBoth;
			// IRIS.eaauctions.ItemList.easing = YAHOO.util.Easing.bounceBoth;
			// IRIS.eaauctions.ItemList.interval = 3;
		}
		var now = new Date().getTime(),
			nextRotation = (this.lastRotation ? this.lastRotation : now)
					+ (this.interval * 1000);
		setTimeout(function() {
				IRIS.eaauctions.ItemList.updateFeatured(cfg);
			}, nextRotation - now
		);
		this.lastRotation = nextRotation;
	},
	updateFeatured: function( cfg ) {
		var uri = cfg.uri
				+ (cfg.auctionId ? '&auctionId=' + cfg.auctionId : '')
				+ (cfg.offset ? '&offset=' + cfg.offset : '');
		YAHOO.util.Connect.asyncRequest('GET', uri, {
			success: function( response ) {
				var oldEl = Dom.get(cfg.el).parentNode,
					newEl = document.createElement('DIV');
				newEl.style.marginLeft = '660px';
				newEl.innerHTML = response.responseText;
				IRIS.util.Loader.notifyAllLoaded(newEl, 'IMG', function() {
					oldEl.parentNode.appendChild(newEl);
					IRIS.util.Loader.handleScripts(newEl);
					var oldOut = new YAHOO.util.Anim(oldEl, {
								marginLeft: {to: -660}
							}, this.duration, this.easing
						),
						newIn = new YAHOO.util.Anim(newEl, {
								marginLeft: {to: 0}
							}, this.duration, this.easing
						);
					newIn.onComplete.subscribe(function() {
						oldEl.parentNode.removeChild(oldEl);
					});
					if( Browser.getInstance().is('ie7') ) {
						oldEl.style.display = 'none';
						newIn.animate();
					}
					else {
						oldOut.animate();
						if( Browser.getInstance().is('ie8') ) {
							setTimeout(function() { newIn.animate(); }, 100);
						}
						else {
							newIn.animate();
						}
					}
				}, this);
			},
			failure: function() {},
			scope: this
		});
	}
};