var google = 'UA-8059772-1';
if (google) {
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
}

window.addEvent('load', function(e) {
	if (google && _gat) {
		var pageTracker = _gat._getTracker(google);
		pageTracker._initData();
		pageTracker._trackPageview();
	}
});

window.addEvent('domready', function(e) {
	
	$$('body').addClass('js');

	new mouseOvers();

	if ($('alert_container') && $('alert')) {
		$('alert').fade('hide');
		new Element('div', {'id': 'alertlayer'}).inject($('alert_container'), 'before');
		new Element('div', {'id': 'closealert'})
			.inject($('alert_container'), 'bottom')
			.addEvent('click', function(e) {
				$('alertlayer').fireEvent('click');
			});

		new Element('img', {
			'class': 'background',
			'src': '../images/circle_alert.gif',
			'styles': {
				height: 0,
				width: 0
			}
		})
			.inject($('alert_container'), 'top')
			.set('morph', {
				duration: 4000,
				transition: 'bounce:out',
				onStart: function() {
					$('alert').fade.delay(
						this.options.duration/2,
						$('alert'),
						'in'
					);
				},
				onComplete: function() {
					$('closealert').setStyle('display', 'block');
				}
			})
			.morph({
				height: 435,
				width: 435,
				'margin-top': '-217px',
				'margin-left': '-217px'
			});

		$('alertlayer').addEvent('click', function(e) {
			$('alert_container').fade('out');
			$('alert').fade('hide');
			$('alertlayer').tween('opacity', $('alertlayer').getStyle('opacity'), 0);
			$('alert_container').dispose.delay(1000, $('alert_container'));
			$('alertlayer').dispose.delay(1000, $('alertlayer'));
		});
	}

	if ($('fileupload'), $('progressbar')) {
		$('fileupload').addEvent('submit', function(e) {
			$('progressbar').setStyle('display', 'block');
		});
	}
});

var mouseOvers = new Class({
	initialize: function(elements) {
		elements = elements || $$('.mouseover');
		elements.each(function(image) {
			if (image.hasClass('specialmo')) {
				image.set('src_mouseover', image.get('class').replace(/.*mouseover=/, ''));
				image.set('src_mouseout',  image.get('src'));
				image.addEvent('mouseenter', this.mouseover);
				image.addEvent('mouseleave', this.mouseout);
				new Asset.image(image.get('src_mouseover'));
			} else {
				var xsrc = image.src;
				if (xsrc.substring(xsrc.length-7, xsrc.length-3) == '_up.')	{
					image.set('src_mouseover', image.get('src').replace(/_up\.([a-z]{3})/, '_ov.$1'));
					image.set('src_mouseout',  image.get('src'));
				
					image.addEvent('mouseenter', this.mouseover);
					image.addEvent('mouseleave', this.mouseout);

					// Preload
					new Asset.image(image.get('src_mouseover'));
				}
			}
		}, this);
	},
	mouseover: function() {
		this.set('src', this.get('src_mouseover'));
	},
	mouseout: function()	{
		this.set('src', this.get('src_mouseout'));
	}
});