window.addEvent('domready', function(){
	// -----------
	
	/*
		Common logics
	*/

	// release BUTTON as LINKS
	$$('button.ui-link').addEvent('click', function(){
		window.location.href = this.get('name');
		return false;
	});

	// release POPUP links
	$$('a[rel=popup]').each(function(o){
		if ( o.get('href') && ['.png', '.gif', '.jpg', 'jpeg', '.bmp'].contains(o.get('href').substr(o.get('href').length - 4)) ) {
			o.image = new Asset.image(o.get('href'));
			o.image.set('big', o.get('big'));
			o.addEvent('click', function(){
				window.Popup.show(o.image);
				return false;
			});
		}
	});

	// release NEW WINDOWED links
	$$('a[rel=new]').each(function(o){
		o.set('target', '_blank');
	});

	// release inputs
	$$('form input[type=text], form input[type=password]').each(function(o){
		o.store('defaultValue', o.get('value'));
	});
	$$('form input[type=text], form input[type=password]').resetValue();




	/*
		Aimed logics
	*/

	// show/hide fence after click on shack
	if ( $('shack') && $('ration') ) {
		var morphObject = new Fx.Morph($('ration'), {
			duration: 500,
			transition: 'bounce:out'
			});

		$('shack').addEvent('click', function(){
			if ( $('ration').getStyle('height').toInt() == 0 ){
				morphObject.start({'height': 120});
			} else {
				morphObject.start({'height': 0});
			}
			return false;
		});
	}

	// release ration (image map)
	if ( $('ration') ) {
		$('ration').getElements('area').addEvents({
			'mouseover': function(){
				var path = 'url(/img/_/bg.ration' + this.get('name') + '.jpg) no-repeat ' + this.get('tabindex') + 'px 0';
				$$('#ration img').setStyle('background', path);
				return false;
			},
			'mouseout': function(){
				$$('#ration img').setStyle('background','none');
				return false;
			}
		});
	}

	// -----------
});
