var pm = {
	style: {},
	lifestyle: {},
	contact: {
		init: function() {
			this.calendar = new Calendar( 0, null, this.onSelect, this.onClose );
			this.calendar.setDateFormat('%m/%d/%Y');
			this.calendar.create();
			
			this.activeField = null;
			
			Event.observe( 'Move_In_Date', 'focus', this.showCalendar );
			Event.observe( 'Visit_Date', 'focus', this.showCalendar );
		},

		onSelect: function ( calendar, date ) {
			pm.contact.activeField.value = date;
			if ( calendar.dateClicked ) {
				calendar.callCloseHandler();
			}
		},
		
		onClose: function( calendar ) {
			calendar.hide();
		},

		showCalendar: function( event ) {
			pm.contact.calendar.showAtElement( this );
			pm.contact.activeField = this;
		}
	
	}
};

pm.bullets = function( container, flex ) {
			
			this.container = container;
			this.flex = flex;
			this.timers = new Array();
			this.states = new Array();
			//var activeBullet;
			//var timer;
}


pm.bullets.prototype = {
				
	'start' : function() {
		/*
		if ( this.timer == null ) {
			this.timer = setTimeout( this.nextBullet.bind(this), 3000 );
		}
		*/
	},
	
	'focusBullet' : function( bullet ) {
		bullet = $(bullet);
		if ( !this.states[bullet.id] ) {
			this.states[bullet.id] = true;
			//this.blurBullets();
			//this.activeBullet = bullet;
			document.getElementById(this.flex).focusBullet( bullet.id );
			bullet.addClassName('selected');
			Effect.BlindDown( 'shade' + bullet.id, { duration: .5, queue: { position: 'end', scope: bullet.id } } );
		}
	},

	'blurBullet' : function( bullet ) {
			bullet = $(bullet);
			if ( this.states[bullet.id] ) {
				this.states[bullet.id] = null;
				document.getElementById(this.flex).blurBullets( bullet.id );
				bullet.removeClassName('selected');
				Effect.BlindUp( 'shade' + bullet.id, { duration: .5, queue: { position: 'end', scope: bullet.id } } );
			}
	},
	
	/*
	'next' : function() {
		
		this.blurBullets();
		if ( this.timer != null ) {
			clearTimeout( this.timer );
		}
		this.timer = setTimeout( this.nextBullet.bind(this), 1000 );
		
	},
	
	'nextBullet' : function() {
		var next;
		
		if ( this.activeBullet == null ) {
			next = $(this.container).firstChild;
		} else {
			next = this.activeBullet;
		}
		
		do {
			var next = next.nextSibling;
			if ( next == null ) {
				next = $(this.container).firstChild;
			}
		} while ( next.id == null );
		
		this.focusBullet( next );

		if ( this.timer != null ) {
			clearTimeout( this.timer );
		}
		this.timer = setTimeout( this.next.bind(this), 5000 );
		
	},
	*/
	
	'mouseOver' : function( id ) {
		if ( this.timers[id] != null ) {
			clearTimeout( this.timers[id] );
		}
		this.timers[id] = setTimeout( this.mouseOverDelay.bind( this, id ), 250 );
	},
	
	'mouseOverDelay' : function( id ) {
		this.focusBullet( id );
		//this.timer = setTimeout( this.nextBullet.bind(this), 10000 );
		
	},
	
	'mouseOut' : function( id ) {
		if ( this.timers[id] != null ) {
			clearTimeout( this.timers[id] );
		}
		this.timers[id] = setTimeout( this.mouseOutDelay.bind( this, id ), 250 );
	},
	
	'mouseOutDelay' : function( id ) {
		this.blurBullet( id );
	}
	
}


pm.lifestyle.bullets = new pm.bullets( 'container', 'flex' );

pm.styleBullets = new pm.bullets( 'container', 'styleGallery' );