var Exm = new Class({

	//Implements: [Hash, Element, Event, Option],

	/*
		hack release advanced links logics, based on 'rel' attribute

		provided markups:
			rel="submit" - link submits parent form
			rel="reset" - link resets parent form
			rel="new" - link will be opened in new window
	*/
	a: function(){

		// working collection
		var elements = $$('a[rel]');

		elements.addEvent('click', function(){
			var rel = this.get('rel');
			switch (rel){
				case 'submit':
					this.getParent('form').submit();
					break;

				case 'reset':
					this.getParent('form').reset();
					break;

				case 'new':
					var newWindow = window.open(this.get('href'));
					newWindow.focus();
					break;

				default:
					return true;
			}
			return false;
		});

		return this;
	},




	/*
		flash embed via <img alt="/path/to/movie.swf" /> tag

		provided markups:
			img
				src: src of alternate image
				alt: SWF file URI
				longdesc="swiff", class="swiff": indicator
				width, height: dimensions of flash movie
	*/
	img: function(){

		// working collection
		var elements = $$('img');

		elements.each(function(e){
			if ( Browser.Plugins.Flash.version && e.get('alt') && (e.get('longdesc') === 'swiff' || e.hasClass('swiff') )) {
				if (e.get('width') && e.get('width') > 0)
					var width = e.get('width');
				else
					var width = '100%';

				if (e.get('height') && e.get('height') > 0)
					var height = e.get('height');
				else
					var height = '100%';

				// let's embed it 
				new Swiff(e.get('alt'), {
					'width': width,
					'height': height,
					'container': e.getParent(),
					'params': {
						'wMode': 'transparent',
						'allowfullscreen': 'true'
					}
				});
			} else {
				//
			};
			return this;
		});

		return this;
	},



	/*
		'for' attribute logics emulation without using ids

		provided markups:
			none
	*/
	label: function(){

		//working collection
		var elements = $$('label');

		elements.addEvents({
			'click': function(){
				var subling = this.getPrevious('input');
				if (subling.get('type') === 'radio' || subling.get('type') === 'checkbox') {
					subling.click();
					return false;
				} else {
					return true;
				}
			},
			'mousedown': $lambda(false),
			'selectstart': $lambda(false)
		});
	},


	/*
		pressed state for buttons

		provided murkups:
			.pressed - class of pressed button
	*/
	button: function(){

		//working collection
		var elements = $$('button, input[type=button]');

		elements.addEvents({
			'mousedown': function(){this.addClass('pressed');},
			'mouseup': function(){this.removeClass('pressed');},
			'mouseout': function(){this.removeClass('pressed');}
		});
		return this;
	},


	/*
		autovalue inputs

		provided markups:
			none
	*/
	input: function(){

		// working collection
		var elements = $$('input[type=text], input[type=password]');

		elements.each(function(e){
			if (e.get('value').length > 0) {
				e
					.store('defaultValue', e.get('value'))
					.addEvents({
						'focus': function(){
							if( this.get('value') === this.retrieve('defaultValue'))
								this.set('value', '');
							return false;
						},
						'blur': function(){
							if( this.get('value') === '')
								this.set('value', this.retrieve('defaultValue'));
							return false;
						}
					});
			}
			return this;
		});

		return this;
	},




	/*
		@constructor
		@return: instanse of Class
		@arguments: 
	*/
	initialize: function(){
		_this_ = this;

		if (arguments.length == 0) {
			for (i in this) {
				if (!['_current', 'caller', 'initialize'].contains(i)) {
					try {
						_this_[i]();
					} catch(e){};
				}
			}
		} else {
			$A(arguments).each(function(i){
				try {
					_this_[i]();
				} catch(e){};
			});
			return this;
		}

	}
});
