window.addEvent('domready', function() {
	new pngSupport({
		transparentImage: ($('home')?'':'.') + './images/transparent.gif'
	}).replace();

	if (Browser.Engine.trident) {
		$$('input').each(function(inp) {
			if (inp.get('type') == 'text' || inp.get('type') == 'password') {
				inp.addEvent('focus', function() {this.addClass('focus');});
				inp.addEvent('blur',  function() {this.removeClass('focus');});
			}
			if (inp.get('type') == 'submit') {
				inp.addEvent('mouseenter', function() {this.addClass('submit_hover');});
				inp.addEvent('mouseleave', function() {this.removeClass('submit_hover');});
			}
		});
		$$('textarea').each(function(inp) {
			inp.addEvent('focus', function() {this.addClass('focus');});
		});
	}

	$$('textarea').each(function(ta){
		ta.store('minheight', ta.getSize().y);
		ta.setStyle('overflow', 'hidden');
		function resize() {
			this.setStyle('height', this.retrieve('minheight'));
			if (this.getSize().y < this.getScrollSize().y && this.getSize().y > this.getStyle('height').toInt()) {
				this.setStyle('height', this.getScrollSize().y);
			}
		}
		ta.addEvent('click', resize).addEvent('keyup', resize);
		ta.fireEvent('click');
	});

	$$('div.step label').each(function(steplbl) {
		if (steplbl.get('for')) {
			var elid = steplbl.get('for');
			if (!$(elid)) {
				steplbl.getParent('div.step').setStyle('display', 'none');
			}
		}
	});
/*
	$$('div.step input, div.step select').each(function(stepinp) {
		var steplbl = stepinp.getParent('div.step').getElement('label.steplabel');
		if (steplbl) {
			stepinp.addEvent('focus', function(e) {
				$clear(steplbl.retrieve('timeout'));
				steplbl.addClass('steplabel_current');
			});
			..stepinp.addEvent('blur', function(e) {
				steplbl.store('timeout', steplbl.removeClass.delay(100, steplbl, 'steplabel_current'));
			});..
		}
	});
*/
	$$('ul#metamenu li').each(function(el, i) {
		if (i > 0) {
			new Element('li').set('html', '|').inject(el, 'before');
		}
	});
	
	$$('ul#subsubnav li').each(function(el, i) {
		if (i > 0) {
			new Element('li').set('html', '|').inject(el, 'before');
		}
	});
	
	if (Browser.Engine.trident4 && $('subnav') && $('ptwrapper')) {
		$('subnav').setStyles({
			'position': 'absolute',
			'bottom': 'auto',
			'left': 0,
			'top': $('ptwrapper').getSize().y - $('subnav').getSize().y - 10
		});
	}
});

var pngSupport = new Class({

	Implements: [Options],

	options: {
		transparentImage: '../images/transparent.gif'
	},

	initialize: function(options) {
		this.setOptions(options);
		this.needed = Browser.Engine.trident4 && Browser.Platform.win;
	},

	replace: function(parentel) {
		if (!this.needed) return;
		if (!parentel) parentel = document;

		parentel.getElements('img').each(function(img) {
			if (img.src.indexOf(this.options.transparentImage) == -1 && img.src.indexOf("png") >= 0) {
				var oldsrc = img.get('src');
				img.set('src', this.options.transparentImage);
				img.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + oldsrc + "',sizingMethod='scale')";
			}
		}, this);
	}
});

/*
function loadMap(lat,lng,markers) {
	if ($('pnlGoogle') && GBrowserIsCompatible()) {
		var map = new GMap2($('googlemap'));

		map.addControl(new GLargeMapControl());
		map.setCenter(new GLatLng(lat,lng), 13);

		var tmp = new Array();
		tmp = markers.split("|");

		var blueIcon = new GIcon(G_DEFAULT_ICON);
		blueIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
		markerOptions = { icon:blueIcon };

		var i;
		for (i=0;i<tmp.length;++i)
		{
				if (i == 0)
				{
						var marker = new GMarker(new GLatLng(tmp[i],tmp[i+1]));
				}
				else
				{
						var marker = new GMarker(new GLatLng(tmp[i],tmp[i+1]), markerOptions);
				}

				map.addOverlay(marker);
				++i;
		}
	}
}
*/
