// Used only for MSIE6

var tgmMsie6Class = Class.create({
	
	className:'tgmMsie6Class',
	windowElements:null,
	
	initialize:function(mainObject)
	{
		mainObject.observeEvent('onBeforePaneOpen', this.hideWindowElements.bindAsEventListener(this));
		mainObject.observeEvent('onPaneClose', this.showWindowElements.bindAsEventListener(this));

		// The suggest still features its own functioning iframe code so we won't touch that now
		// mainObject.observeEvent('onSuggestOpen', this.showIFrame.bindAsEventListener(this));
		// mainObject.observeEvent('onBeforeSuggestClose', this.hideIFrame.bindAsEventListener(this));
		
		mainObject.observeEvent('onDropdownOpen', this.showIFrame.bindAsEventListener(this));
		mainObject.observeEvent('onBeforeDropdownClose', this.hideIFrame.bindAsEventListener(this));
		this.windowElements = new Array();
	},
	
	hideWindowElements:function(e)
	{
		var selectBoxes = $$('select');
		if (selectBoxes.length > 0) {
			selectBoxes.each(function(sel) {
				if (sel.style.visibility != 'hidden') {
					sel.style.visibility = 'hidden';
					this.windowElements.push(sel);
				}
			}.bind(this));
		}
	},
	
	showWindowElements:function(e)
	{
		if (this.windowElements != null && this.windowElements.length > 0) {
			this.windowElements.each(function(el) {
				el.style.visibility='visible';
			}.bind(this));
			this.windowElements = new Array();
		}
	},

	showIFrame:function(e)
	{
		var classObject = e.memo;
		if (typeof classObject.getElement != 'undefined') {
			var copyElement = classObject.getElement();
			//console.log(copyElement);

			// Check if iframe already exists
			var myIFrame = copyElement.up('div').down('iframe');
			if (myIFrame == null) {
				var iframeId = 'msie6_iframe_'+Math.round(Math.random()*100000);
				var myIFrame = new Element('iframe', { id:iframeId });
				copyElement.parentNode.appendChild(myIFrame);
				var divDims = copyElement.getDimensions();

				var copyElementZIndex = copyElement.parentNode.getStyle('zIndex');

				myIFrame.setStyle({
					display:'none',
					position:'absolute',
					width:divDims.width+'px',
					height:divDims.height+'px',
					border:0,
					frameBorder:0,
					zIndex:(copyElementZIndex - 10)
				});
			}
			
			myIFrame.clonePosition(copyElement);
			//copyElement.clonePosition(myIFrame);
			myIFrame.show();
		}
	},


	hideIFrame:function(e)
	{
		var classObject = e.memo;
		if (typeof classObject.getElement != 'undefined') {
			var copyElement = classObject.getElement();
			var myIFrame = copyElement.up('div').down('iframe');
			if (myIFrame != null) {
				myIFrame.hide();
			}
		}
	}
	
});

var tgmMsie6;
