var ClothinglinesMenu = Class.create({
	initialize: function(element) {
		this.element = $(element);
		this.box = $('clothinglinesBox');
		
		this.options = Object.extend({
			delay: 0.3,
			zIndex: 300
		}, arguments[1] || {});
		
		this.box.hide = this.box.hide.wrap(function(proceed, event) {
			this.setStyle({
				visibility: 'hidden',
				top: '-9999px',
				left: '-9999px'
			});
			return this;
		});
		this.box.show = this.box.show.wrap(function(proceed, event) {
			this.setStyle({
				visibility: 'visible',
				top: '28px',
				left: '-5px'
			});
			this.select('object, embed').invoke('setStyle', { position: 'relative', zIndex: 3000 });
			return this;
		});
		this.box.visible = function() {
			var left = parseInt(this.getStyle('left'));
			var visible = (left >= -5);
			
			return (visible);
		};
		
		this.prepare();
	},
	
	prepare: function() {
		// IE needs help
		this.box.setStyle({
			zoom: 1,
			zIndex: this.options.zIndex
		});
		
		//if (Prototype.Browser.IE) {
			this.iframeShim = new Element('iframe', {
		        className : 'iframeShim',
		        src: 'javascript:false;',
		        frameBorder: 0
		      }).setStyle({
		        display: 'none',
		        zIndex: this.options.zIndex - 1,
				opacity: .5,
				top: '28px',
				left: '-5px'
		    });
			this.box.insert({ before: this.iframeShim });
		//}
		
		$w('toggle show').each(function(fn) {
			this[fn] = this[fn].wrap(function(proceed, event) {
				if (event && event.blurFlashElement) event.blurFlashElement();
				if (!this.element) this.initialize();
				proceed(event);
			});
		}.bind(this));
		
		this.padder = this.box.down('.padder');
		this.padder.observe('mousemove', this.show.bindAsEventListener(this))
		//this.padder.observe(Katoenenzo.useEvent['mouseenter'], Katoenenzo.capture(this.show).bindAsEventListener(this))
		.observe(Katoenenzo.useEvent['mouseleave'], Katoenenzo.capture(this.hide).bindAsEventListener(this));
	},
	
	toggle: function(event) {
		this.box[this.box.visible() ? 'hide' : 'show']();
		return false;
	},
	
	clearHideTimer: function() {
		if (this._hideTimer) {
			window.clearTimeout(this._hideTimer);
			this._hideTimer = null;
		}
	},
	
	hide: function(event) {
		this.clearHideTimer();
		this._hideTimer = window.setTimeout(function() {
			this.box.hide();
			this.iframeShim.hide();
		}.bind(this), this.options.delay * 1000);
		
	},
	
	show: function(event) {
		this.clearHideTimer();
		this.box.show();
		
		/*this.iframeShim.setStyle({
			width: (dimensions.width) + 'px',
			height: (dimensions.height) + 'px'
			//top: 0,//position.top + 'px',
			//left: 0//position.left + 'px'
		}).show();*/
		
		this.box.setStyle('zoom:auto').setStyle('zoom:1');
	}
});

document.observe('dom:loaded', function() {
	window.ClothinglinesMenu = new ClothinglinesMenu('menuClothinglines');
});