/* ----------------------------------------------------------------------- */
/* ---------------------------- Input ------------------------------------ */
/* ----------------------------------------------------------------------- */

Input = function( target ) {
	Input.superClass.apply( this, arguments );

	this.Id = 'Input';
	this.element = this.createNode( 'div', { 'class': 'input' }, target );
	this.triggers = this.createNode( 'div', { 'class': 'triggers' }, this.element );
	this.trigger = new HTMLGlif( 'span', { 'class': 'trigger' }, this.triggers );
	this.tip = new HTMLGlif( 'span', { 'class': 'tip' }, this.triggers );

	this.createNode( 'span', { 'class': 'cn t r' }, this.element, '<i class="png"></i>' );
	this.createNode( 'span', { 'class': 'cn t l' }, this.element, '<i class="png"></i>' );
	this.createNode( 'span', { 'class': 'cn b r' }, this.element, '<i class="png"></i>' );
	this.createNode( 'span', { 'class': 'cn b l' }, this.element, '<i class="png"></i>' );
	
	this.type = false;
	this.active = false;
	this.status = false;
	this.error = false;
	this.data = false;
	this.disabled = false;
}
Input.inheritsFrom( HTMLGlif );

/* ----------------------------------------------------------------------- */

Input.prototype.set = function( data, value ) {
	if( !data && !value ) return false;
	this.setData( data );
	this.setValue( value );
	this.setClassName( 'gray', false );

	if( !( this.active && this.getValue() == '' ) ) this.check();
	this.notify( 'inputSetted' );
}

/* ----------------------------------------------------------------------- */

Input.prototype.setError = function( flag ) {
	this.error = flag;
	this.setClassName( 'error', this.error );
}

/* ----------------------------------------------------------------------- */

Input.prototype.getInput = function() {
	return this.input;
}

/* ----------------------------------------------------------------------- */

Input.prototype.getValue = function() {
	return this.input.value;
}

/* ----------------------------------------------------------------------- */

Input.prototype.setValue = function( sValue ) {
	sValue = sValue || '';
	if( typeof( sValue ) != 'string' ) return false;
	this.input.value = sValue;
}

/* ----------------------------------------------------------------------- */

Input.prototype.setDisabled = function( flag ) {
	this.disabled = flag;
	//this.input.disabled = flag;
	this.input.readOnly = flag;
	this.setClassName( this.type + '-disabled', flag );
}

/* ----------------------------------------------------------------------- */

Input.prototype.check = function() {
	var oS = this.status;

	this.status = false;
	if( this.data ) this.status = true;

	if( this.active ) this.setError( !this.status );
	if( !( oS === this.status ) ) this.notify( 'inputStatusChange' );
	return this.status;
}

/* ----------------------------------------------------------------------- */

Input.prototype.getData = function( prop ) {
	if( prop ) {
		return this.data[ prop ];
	} else {
		return this.data;
	}
}

/* ----------------------------------------------------------------------- */

Input.prototype.setData = function( data ) {
	this.data = ( data == undefined ? false : data );
}

/* ----------------------------------------------------------------------- */

Input.prototype.setTrigger = function( sValue ) {
	sValue = sValue || '';
	this.setContent( sValue, this.trigger.element );
}

/* ----------------------------------------------------------------------- */

Input.prototype.setTip = function( sValue ) {
	sValue = sValue || '';
	this.tip.setContent( sValue );
}

/* ----------------------------------------------------------------------- */

Input.prototype.setActive = function( flag ) {
	this.setClassName( 'active-' + this.type, flag );
	this.active = flag;
	if( !flag ) {
		this.notify( 'SetUnActive' );
	}
}

Input.prototype.showTip = function( flag ) {
	this.tip.setClassName( 'hidden', !flag );
}

/* ----------------------------------------------------------------------- */
/* ------------------------ Text Input ----------------------------------- */
/* ----------------------------------------------------------------------- */

TextInput = function( target, type ) {
	TextInput.superClass.apply( this, arguments );
	
	this.Id = 'TextInput';
	this.input = this.createNode( 'input', { type: type || 'text' }, this.element );
	this.type = 'text';
	this.data = '';
	this.pattern = /^.*$/;
	this.template = false;

	this.showTemplate();

	this.addHandler( this.element, 'click', this.focusInput );
	this.addHandler( this.input, 'click', function( params, ev ) { this.stopPropagation( ev ) } );
	this.addHandler( this.input, 'focus', function() { this.setActive( true ); this.setDefault(); } );
	this.addHandler( this.input, 'blur', function() { this.setActive( false ); this.setDefault(); } );
	this.addHandler( this.input, 'keydown', this.setDefault );
	this.addHandler( this.input, 'keyup', this.typing );
	this.addHandler( this.input, 'change', this.typing );
	if ( '\v' == 'v' ){
		this.addHandler( this.input, 'paste', function(){
			this.setData( window.clipboardData.getData('Text') ); this.check();
		});
	}

	this.addHandler( this.input, 'focus', this.notify, 'inputFocused' );
	this.addHandler( this.input, 'blur', this.notify, 'inputBlured' );

	this.setClassName( 'text', true );
}
TextInput.inheritsFrom( Input );

/* ----------------------------------------------------------------------- */

TextInput.prototype.check = function() {
	var oS = this.status;

	this.status = false;

	if( ( ( this.pattern && this.pattern.test ) ? this.pattern.test( this.getData() ) : true ) ) this.status = true;
	if( !( oS === this.status ) ) this.notify( 'inputStatusChange' );

	if( this.active ) this.setError( !this.status );
	return this.status;
}

/* ----------------------------------------------------------------------- */

TextInput.prototype.focusInput = function( params, ev ) {
	if( this.disabled ) return false;
	this.input.focus();
	if( '\v' == 'v' ) {
		if ( this.input.createTextRange ) {
			var r = this.input.createTextRange();
			r.collapse( false );
			r.select();
		}
	}
}

/* ----------------------------------------------------------------------- */

TextInput.prototype.blur = function() {
	this.input.blur();
}

/* ----------------------------------------------------------------------- */

TextInput.prototype.setData = function( data ) {
	data = ( data ? data : '' );
	this.data = data;
}

/* ----------------------------------------------------------------------- */

TextInput.prototype.getTemplate = function() {
	return this.template;
}

/* ----------------------------------------------------------------------- */

TextInput.prototype.setTemplate = function( sValue ) {
	this.template = sValue;
}

/* ----------------------------------------------------------------------- */

TextInput.prototype.setPattern = function( rexp ) {
	if( !rexp ) return false;
	this.pattern = new RegExp( rexp );
}

/* ----------------------------------------------------------------------- */

TextInput.prototype.showTemplate = function( flag ) {
	if( !this.template ) return false;
	this.setClassName( 'gray', flag );
	this.setValue( flag ? this.template : false );
}

/* ----------------------------------------------------------------------- */

TextInput.prototype.setDefault = function() {
	var value = this.getValue();
	var flag = ( value === this.template );
	if( flag && this.active ) {
		this.set( false, false );
		this.showTemplate( false );
	} else if( ( flag || value == '' ) && !this.active ) {
		this.set( false, false );
		this.showTemplate( true );
	}
}

/* ----------------------------------------------------------------------- */

TextInput.prototype.typing = function( params, ev ) {
	var cVal = this.getValue();

	var e = ev || window.event;
	var code = e.charCode || e.keyCode;
	if ( /* e.ctrlKey ||*/ e.altKey ) return true;

	if ( code == 27 ) return false;

	if ( code < 32 && code != 8 && code != 13 ) return true;
	if ( code == 35 || code == 36 || code == 37 || code == 39 ) return true;			// end, home, left, right

	if ( code != 38 && code != 40 && code != 13 && code != 27 && code != 9 ) {
		this.notify( 'Typing' );
	} else {
		this.notify( 'SpecialKeyPressed', code );
	}

	this.setData( cVal );
	this.notify( 'inputSetted' );
	this.check();
}

/* ----------------------------------------------------------------------- */
/* -------------------------- Predicate ---------------------------------- */
/* ----------------------------------------------------------------------- */

PredicateInput = function( target ) {
	PredicateInput.superClass.apply( this, arguments );
	
	this.Id = 'PredicateInput';
	this.pad = new Pad();
	this.pad.setTarget( this );
	this.pad.attachObserver( 'DataChosen', this.dataChoose, this );
	if( '\v' != 'v' ) this.addHandler( this.input, 'blur', this.hidePad );
	this.addHandler( this.pad.element, 'mouseover', this.cancelPadHide );
	this.removeHandler( this.input, 'change', this.typing );
	this.timer = false;
}
PredicateInput.inheritsFrom( TextInput );

PredicateInput.prototype.check = function() {
	var oS = this.status;

	this.status = false;
	if( this.data && this.data instanceof Object ) this.status = true;

	if( !( oS === this.status ) ) this.notify( 'inputStatusChange' );
	//this.setError( !this.status );
	return this.status;
}

PredicateInput.prototype.typing = function( params, ev ) {
	var e = ev || window.event;
	var code = e.charCode || e.keyCode;
	if ( /*e.ctrlKey ||*/ e.altKey ) return true;

	if ( code == 27 ) return false;

	if ( code < 32 && code != 8 && code != 13 ) return true;
	if ( code == 35 || code == 36 || code == 37 || code == 39 ) return true;			// end, home, left, right

	if ( code != 38 && code != 40 && code != 13 && code != 27 && code != 9 ) {
		if( this.active ) this.notify( 'Typing' );
	} else {
		this.pad.specialKeyPressed( code );
	}

	this.check();
}

PredicateInput.prototype.setDataList = function( data ) {
	if( !data && data.length == 0 ) return false;
	this.pad.show( true );
	this.pad.construct( data );
	this.pad.setPosition();

	var so = this.pad.offset();
	var po = this.offset();
	if( !po ) return false;
	this.pad.setSize( po.width );
}

PredicateInput.prototype.dataChoose = function( data ) {
	this.blur();
	this.set( data, data[ 'Name' ] );
	this.pad.construct( false );
}

PredicateInput.prototype.hidePad = function() {
	var obj = this;
	this.timer = window.setTimeout( function() { obj.notify( 'hidePad' ); obj.pad.construct( false ); }, 500 );
}

PredicateInput.prototype.cancelPadHide = function() {
	window.clearTimeout( this.timer );
	this.timer = false;
}

/* ----------------------------------------------------------------------- */
/* ---------------------------- Select ----------------------------------- */
/* ----------------------------------------------------------------------- */

Select = function( target, data ) {
	Select.superClass.apply( this, arguments );
	
	this.Id = 'Select';
	this.input = this.createNode( 'div', { 'class': 'value' }, this.element );
	this.dataList = false;
	
	this.setClassName( 'select', true );

	this.type = 'select';
	this.expanded = false;
	
	this.elementDocumentBody = document.body;
	this.addHandler( this.elementDocumentBody, 'click', this.close );

	this.addHandler( this.element, 'mouseover', this.setActive, true );
	this.addHandler( this.element, 'mouseout', this.setActive, false );
	this.addHandler( this.element, 'click', this.toggleExpanded );

	this.trigger.setContent( '<img src="/images/select-trigger.png" width="32" height="16" class="png" />' );

	this.pad = new Pad();
	this.pad.setTarget( this );
	this.pad.attachObserver( 'DataChosen', function( data ) { this.set( data, data.name ) }, this );
	this.setDataList( data || false );
}
Select.inheritsFrom( Input );

/* ----------------------------------------------------------------------- */

Select.prototype.getValue = function() {
	return this.getData().value;
}

/* ----------------------------------------------------------------------- */

Select.prototype.setValue = function( sValue ) {
	sValue = sValue || '';
	if( typeof( sValue ) != 'string' ) return false;
	this.setContent( sValue, this.input );
}

/* ----------------------------------------------------------------------- */

Select.prototype.getDataList = function( data ) {
	return this.dataList;
}

/* ----------------------------------------------------------------------- */

Select.prototype.setDataList = function( data, num ) {
	this.dataList = ( ( data && data instanceof Array ) ? data : false );
	this.pad.construct( this.dataList );
	if( num && 0 < num && num < this.dataList.length ) {
		this.set( this.dataList[ num ], this.dataList[ num ].name );
	} else {
		this.setDefault();
	}
}

/* ----------------------------------------------------------------------- */

Select.prototype.getDataFromList = function( keys ) {
	if( typeof keys == 'number' ) {
		return this.dataList[ keys ] || false;
	} else if( typeof keys == 'object' ) {
		var result = [];
		for( var i = this.dataList.length; i; i-- ) {
			var record = this.dataList[ i - 1 ];
			for( var key in keys ) {
				var value = keys[ key ];
				if( record[ key ] && record[ key ] === value ) {
					result[ result.length ] = record;
				}
			}
		}
		return ( result.length ? result : false );
	} else {
		return false;
	}
}

/* ----------------------------------------------------------------------- */

Select.prototype.setDefault = function() {
	var first = this.getDataFromList( 0 );
	this.set( first, first.name );
}

/* ----------------------------------------------------------------------- */

Select.prototype.toggleExpanded = function( params, ev ) {
	if( this.disabled ) return false;
	this.expanded ? this.close( null, ev ) : this.expand( null, ev );
}

/* ----------------------------------------------------------------------- */

Select.prototype.close = function( params, ev ) {
	this.pad.show( false );
	this.setClassName( 'expanded', false );
	this.expanded = false;
	this.stopPropagation( ev );
}

/* ----------------------------------------------------------------------- */

Select.prototype.expand = function( params, ev ) {
	this.pad.setPosition( this.element );
	this.pad.show( true );
	this.setClassName( 'expanded', true );
	this.expanded = true;
	this.stopPropagation( ev );
}

/* ----------------------------------------------------------------------- */
/* --------------------------- DateInput --------------------------------- */
/* ----------------------------------------------------------------------- */

DateInput = function( target ) {
	DateInput.superClass.apply( this, arguments );
	
	this.Id = 'DateInput';
	this.type = 'date';
	this.bs = false;
	this.min = false;
	this.max = false;
	this.mask = '__.__.____';
	this.pattern = false;
	this.addHandler( this.input, 'keypress', this.onKeyPress );
	this.addHandler( this.input, 'keydown', this.onKeyDown );
}
DateInput.inheritsFrom( TextInput );

/* ----------------------------------------------------------------------- */

DateInput.prototype.setData = function( data ) {
	data = data || false;
	this.data = this.formate( data );
}

/* ----------------------------------------------------------------------- */

DateInput.prototype.setMin = function( data ) {
	if( !( data instanceof Date ) ) return false;
	this.min = data;
}

/* ----------------------------------------------------------------------- */

DateInput.prototype.setMax = function( data ) {
	if( !( data instanceof Date ) ) return false;
	this.max = data;
}

/* ----------------------------------------------------------------------- */

DateInput.prototype.check = function() {
	var oS = this.status;

	this.status = false;

	//var date = new Date( this.data )
	if( this.data instanceof Date ) this.status = true;
	if( !( oS === this.status ) ) this.notify( 'inputStatusChange' );

	if( this.active ) this.setError( !this.status );
	return this.status;
}

/* ----------------------------------------------------------------------- */

DateInput.prototype.formate = function( data ) {
	if( data instanceof Date ) return data;
	if( typeof data != 'string' ) return false;

	var array = data.split( '.' );

	if( !array || !array[0] || !array[1] || !array[2] ) return false;
	if( array[2].length != 4 || array[1].length != 2 || array[0].length != 2 ) return false;
	
	var year = new Number( array[2] );
	var month = new Number( array[1] ) - 1;
	var day = new Number( array[0] );

	if( 0 >= day || day > 31 || 0 > month || month > 11 || 1900 > year || year > 2100 ) return false;

	var result = new Date( year, month, day ) || false;
	if( result.getDate ) {
		if( result.getDate() != day ) return false;
	} else {
		return false;
	}
	
	if( this.min && this.min.valueOf && this.min.valueOf() > result.valueOf() ) return false;
	if( this.max && this.max.valueOf && this.max.valueOf() < result.valueOf() ) return false;

	return result;
}

/* ----------------------------------------------------------------------- */

DateInput.prototype.setDefault = function() {
	var value = this.getValue();
	var flag = ( value == this.template );
	if( flag && this.active ) {
		this.showTemplate( false );
		this.set( false, this.mask );
		this.moveCaretTo( 0 );
	} else if( ( flag || value == '' || value == this.mask ) && !this.active ) {
		this.set( false, false );
		this.showTemplate( true );
	}
}

/* ----------------------------------------------------------------------- */

DateInput.prototype.onKeyDown = function( params, ev ) {
	var ev = ev || window.event;
	var code = ev.charCode || ev.keyCode;
	if( ev.ctrlKey || ev.altKey ) return true;
	var sel = this.getSelectionStart();

	if ( code == 35 || code == 36 || code == 37 || code == 39 || code == 9 || code == 13 ) return true;
	if( 
		!( ( code >= 48 && code <= 57 ) || ( code >= 96 && code <= 105 ) ) ||
		sel == 10 || 
		code == 8
	) {
		this.preventDefault( ev );
	}

	if( code == 8 && !this.bs && 'v' == '\v' ) {		// 8 - удалить предыдущий символ
		this.bs = true;
		this.onKeyPress( false, { charCode: 8 } );
	};
}

/* ----------------------------------------------------------------------- */

DateInput.prototype.onKeyPress = function( params, ev ) {
	var ev = ev || window.event;
	var code = ev.charCode || ev.keyCode;
	if ( ev.ctrlKey || ev.altKey ) return true;
	if ( code == 27 ) {
		this.input.blur();
		return false;
	}

	if ( code < 32 && code != 13 && code != 8 ) return true;
	if ( code == 35 || code == 36 || code == 37 || code == 39 || code == 9 || code == 13 ) return true;

	if( ( code >= 48 && code <= 57 ) || ( code >= 96 && code <= 105 ) ) {
		var sel = this.getSelectionStart();
		var cVal = this.getValue();
		if( sel == 10 ) {
			this.preventDefault( ev );
			return false;
		}

		if( cVal.substr( sel, 1 ) == '.' ) {
			sel++;
			this.moveCaretTo( sel );
		}

		var key = String.fromCharCode( ( ( code < 96 ) ? code : ( code - 48 ) ) );
		nVal = ( ( sel > 0 ) ? cVal.substring( 0, sel ) : '' ) + key.toString() + cVal.substring( sel + 1, cVal.length );
		this.setValue( nVal );
		sel++;
		this.moveCaretTo( sel );

		if( cVal.substr( sel, 1 ) == '.' ) {
			sel++;
			this.moveCaretTo( sel );
		}
	}

	if( code == 8 ) {
		var cVal = this.getValue();
		var start = this.getSelectionStart();
		var end = this.getSelectionEnd();
		if( start == end ) start--;
		var key = this.mask.substring( start, end );
		nVal = ( ( start > 0 ) ? cVal.substring( 0, start ) : '' ) + key.toString() + cVal.substring( end, cVal.length );
		this.setValue( nVal );
		this.moveCaretTo( start );
		var self = this;
		window.setTimeout( function() { self.bs = false }, 50 );
	}
	this.preventDefault( ev );
}

/* ----------------------------------------------------------------------- */

DateInput.prototype.getSelectionStart = function() {
	if( this.input.selectionStart ) return this.input.selectionStart;
	else if ( document.selection && 'v' == '\v' ) {
		var sel = document.selection.createRange();
		var clone = this.input.createTextRange();
		clone.setEndPoint( 'EndToStart', sel );
		return clone.text.length;
	}
	return 0;
}

/* ----------------------------------------------------------------------- */

DateInput.prototype.getSelectionEnd = function() {
	if( this.input.selectionEnd ) return this.input.selectionEnd;
	else if ( document.selection && 'v' == '\v' ) {
		var sel = document.selection.createRange();
		var clone = this.input.createTextRange();
		clone.setEndPoint( 'EndToEnd', sel );
		return clone.text.length;
	}
	return 0;
}

/* ----------------------------------------------------------------------- */

DateInput.prototype.moveCaretTo = function( position ) {
	if( this.input.setSelectionRange ) {
		this.input.setSelectionRange( position, position );
	} else {
		var rng = this.input.createTextRange();
		rng.collapse( true );
		rng.move( 'character', position );
		rng.select();
	}
}

/* ----------------------------------------------------------------------- */
/* ---------------------------- Checkbox --------------------------------- */
/* ----------------------------------------------------------------------- */

CheckBox = function( target ) {
	CheckBox.superClass.apply( this, arguments );
	
	this.Id = 'CheckBox';
	this.element = this.createNode( 'div', { 'class': 'checkbox' }, target );
	this.swtch = this.createNode( 'span', false, this.element );
	this.label = this.createNode( 'p', { 'class': 'label' }, this.element );
	this.value = false;
	this.status = true;
	this.required = false;
	
	this.addHandler( this.swtch, 'click', this.toggle );
	this.addHandler( this.label, 'click', this.toggle );
}
CheckBox.inheritsFrom( HTMLGlif );

/* ----------------------------------------------------------------------- */

CheckBox.prototype.setRequired = function( flag ) {
	this.required = flag;
}

/* ----------------------------------------------------------------------- */

CheckBox.prototype.toggle = function() {
	this.setData( !this.value );
}

/* ----------------------------------------------------------------------- */

CheckBox.prototype.setLabel = function( value ) {
	this.setContent( value, this.label );
}

/* ----------------------------------------------------------------------- */

CheckBox.prototype.setData = function( flag ) {
	this.value = flag;
	this.notify( 'inputSetted' );
	this.setClassName( 'selected', flag );
	this.check();
}

/* ----------------------------------------------------------------------- */

CheckBox.prototype.getData = function() {
	return this.value;
}

/* ----------------------------------------------------------------------- */

CheckBox.prototype.check = function() {
	var oS = this.status;
	if( this.required ) {
		this.status = this.value;
	}
	
	if( !( oS === this.status ) ) this.notify( 'inputStatusChange' );
	return this.status;
}

/* ----------------------------------------------------------------------- */
/* ------------------------------ Sex ------------------------------------ */
/* ----------------------------------------------------------------------- */

Sex = function( target ) {
	Sex.superClass.apply( this, arguments );
	
	this.Id = 'Sex';
	this.inputs = new Array();
	this.current = false;
	this.status = false;
	this.data = false;
	this.type = 'sex';

	this.dataList = [
		{ name: 'мужской', value: 'MALE' },
		{ name: 'женский', value: 'FEMALE' }
	];
	
	this.element = this.createNode( 'div', { 'class': 'sex' }, target );
	this.inner = this.createNode( 'div', { 'class': 'persons' }, this.element ); 

	this.addInput( 'male' );
	this.addInput( 'female' );

	this.title = this.createNode( 'span', false, this.element, 'пол' );
}
Sex.inheritsFrom( HTMLGlif );

/* ----------------------------------------------------------------------- */

Sex.prototype.check = function() {
	var oS = this.status;

	this.status = false;
	if( this.data ) this.status = true;

	if( !( oS === this.status ) ) this.notify( 'inputStatusChange' );
	return this.status;
}

/* ----------------------------------------------------------------------- */

Sex.prototype.set = function( data, value ) {
	this.setData( data );
	this.setValue( value );

	this.check();
	this.notify( 'inputSetted' );
}

/* ----------------------------------------------------------------------- */

Sex.prototype.setValue = function( sValue ) {
	sValue = sValue || '';
	if( typeof( sValue ) != 'string' ) return false;
	this.setContent( sValue, this.title );
}

/* ----------------------------------------------------------------------- */

Sex.prototype.getData = function() {
	return this.data;
}

/* ----------------------------------------------------------------------- */

Sex.prototype.setData = function( data ) {
	data = data || false;
	this.data = data;
}

/* ----------------------------- Add Input ---------------------------------- */

Sex.prototype.addInput = function( type ) {
	var newPerson = new Person( type, this.element );
	this.setClassName( type, true, newPerson.inner );	
	newPerson.attachObserver( 'ToggleHover', this.toggleHover, this );
	newPerson.attachObserver( 'PersonClicked', this.choose, this );
	newPerson.idx = this.inputs.length;
	this.inputs[ this.inputs.length ] = newPerson;
	newPerson.append( this.inner );
	
	return newPerson;
}


/* ------------------------------ Choose ------------------------------------ */

Sex.prototype.choose = function( params, obj ) {
	if( obj.idx === this.current ) return false;
	if( 0 <= this.current && this.inputs[ this.current ] ) {
		this.inputs[ this.current ].setClassName( 'active', false );
	}

	this.setClassName( 'notsetted', false );
	obj.setClassName( 'active', true );
	this.current = obj.idx;
	this.set( this.dataList[ obj.idx ].value, this.dataList[ obj.idx ].name );
}

/* --------------------------- Toggle Hover --------------------------------- */

Sex.prototype.toggleHover = function( params, obj ) {
	obj.hover = !obj.hover;
	obj.setClassName( 'hover', obj.hover );
}

/* -------------------------------------------------------------------------- */
/* ------------------------------ Person ------------------------------------ */
/* -------------------------------------------------------------------------- */

Person = function( age, target ) {
	Person.superClass.apply( this, new Array() );

	this.Id = 'Person';
	this.age = age;
	this.hover = false;

	this.element = this.createNode( 'div', { 'class': 'person' }, target );
	this.inner = this.createNode( 'div', { 'class': 'png' }, this.element );

	this.addHandler( this.element, 'mouseover', this.notify, 'ToggleHover' );
	this.addHandler( this.element, 'mouseout', this.notify, 'ToggleHover' );
	this.addHandler( this.element, 'click', this.notify, 'PersonClicked' );

	return this;
}
Person.inheritsFrom( HTMLGlif );