/*# Metadata ################################### Header v.2
# $URL: http://gt-nas-1/svn/gamebase.frontend/trunk/xsl_gamebase/x__gamebase_2.0/js/GT.IESelects.js $
# $Rev: 6445 $
# $Date: 2012-01-16 17:39:42 +0100 (Mo, 16 Jän 2012) $
# $Author: bszil $
### TOC ###################################################
#
### Description ###########################################
#
#########################################################*/
(function ($) {
	this.GT = this.GT || {};
	this.GT.IESelects = this.GT.IESelects || new Class({
		Implements: [Options],
		options: {
			selectTags: 'select#fk_country, select#securityQuestionTag, select#bank_country',
			maxWidth: 700
		},
		initialize: function (options) {
			this.setOptions(options);		
			if (Browser.name == 'ie' && Browser.version < 9) {
				var selectTags = $$(this.options.selectTags);
				selectTags.each(function (elem) {
					var selectTag = elem,
						largeWidth = normalWidth = selectTag.getSize().x,
						maxWidth = this.options.maxWidth;

					selectTag.setStyles({
						width: 'auto',
						visibility: 'hidden'
					});

					var thisWidth = selectTag.getSize().x;
					largeWidth = (thisWidth > largeWidth) ? thisWidth : largeWidth;
					var parent = selectTag.getParent();
					var parentHeight = parent.getSize().y;
					if (!($('fnSettingsPersonal'))) {
						selectTag.setStyles({
							position: 'absolute'
						});
					}
					selectTag.setStyles({
						width: normalWidth,
						visibility: 'visible'
						/*top: 'auto',
						left: 'auto'*/
					});
					parent.setStyles({
						position: 'relative',
						height: parentHeight
					});

					if (largeWidth > normalWidth) {
						if (largeWidth > maxWidth) {
							largeWidth = maxWidth;
						}

						var mouseLeave = function () {
							selectTag.setStyle('width', normalWidth);
						};

						selectTag.addEvents({
							mouseenter: function () {
								this.setStyle('width', largeWidth);
							},
							focus: function () {
								this.setStyle('width', largeWidth);
							},
							mouseleave: mouseLeave,
							click: function () {
								this.removeEvent('mouseleave', mouseLeave);
							},
							blur: function () {
								this.addEvent('mouseleave', mouseLeave);
								mouseLeave();
							}
						});
					}
				}, this);
			}
		}
	});
})(document.id);

// TODO: raus damit, in tools or so
window.addEvent('domready',function () {
	var options = {
		selectTags: '#fk_country, #securityQuestionTag, #bank_country, #messageActions select, #info_type',
		maxWidth: 700
	};
	new GT.IESelects(options);
});
