// ---------------------------------------------------------------------------- //
// -- View time --------------------------------------------------------------- //
// ---------------------------------------------------------------------------- //
function sivamtime() {

	var data = new Date();
	var gg, mm, aaaa;

	gg = data.getDate() + ".";
	mm = data.getMonth() + 1 + ".";
	aaaa = data.getFullYear();	

	document.timeForm.field.value = (gg + mm + aaaa);
	
}
// ---------------------------------------------------------------------------- //
// -- View description -------------------------------------------------------- //
// ---------------------------------------------------------------------------- //	
var DivUpdater = Class.create({
	updateDivId: 'content_pictures',
	divDescriptionCss: '.verticalContentBox',
	loadedOrInError: 0,
	
	initialize: function() {	
	},
	
	_checkImageLoading: function() {
		this.loadedOrInError ++;
		
		if ($$('#' + this.updateDivId + ' img').size() == this.loadedOrInError) {
			new Effect.Opacity(this.updateDivId, {
				duration: 0.4,
				from: 0,
				to: 1,
				queue: {position: 'start', scope: 'projectimages'}
			});
			
			$$('#' + this.updateDivId + ' img').each(function(el) {
				new Effect.Opacity(el, {
					duration: 0.4,
					from: 0,
					to: 1,
					queue: {position: 'end', scope: 'projectimages'}
				});
			});
		}
	},
	
	goToPage: function(href) {
		this.loadedOrInError = 0;
		new Ajax.Updater(this.updateDivId, href, {
			method: 'get',
			onComplete: function() {
				this._initDivWidth();

				$$('#' + this.updateDivId + ' img').each(function(el) {
					el.setOpacity(0);

					Event.observe(el, 'load', function() {
						this._updateDivWidth($(this.updateDivId).getWidth() + el.width);
						this._checkImageLoading();
					}.bind(this))
					
					Event.observe(el, 'error', function() {
						this._updateDivWidth($(this.updateDivId).getWidth() + el.width);
						this._checkImageLoading();
					}.bind(this));

				}.bind(this));


			}.bind(this)
		});
	},
	
	_initDivWidth: function() {
			var totWidth = 0;
			$$('#' + this.updateDivId + ' ' + this.divDescriptionCss).each(function(elemento) {
				totWidth += elemento.getWidth();
			});

			$$('#' + this.updateDivId + ' span').each(function(elemento) {
				var marginRight = parseInt(elemento.getStyle('margin-right'));
				var marginLeft = parseInt(elemento.getStyle('margin-left'));

				if (marginRight) { totWidth += marginRight}
				if (marginLeft) { totWidth += marginLeft}
			});
			
			$$('.swf').each(function(el) {
				totWidth += parseInt(el.width);
			});

			this._updateDivWidth(totWidth);
	},
	
	_updateDivWidth: function(width) {
		$(this.updateDivId).setStyle({
			width: width + 'px'
		});
	}
})