/* (C) 2007 Bas Denissen & Michael Willems */

var myrules = {
	'a.autoajax' : {
		'click':
			function () {
				if ( href = this.getAttribute ( 'href' ) ) {
					if ( target = this.getAttribute ( 'target' ) ) {
						this.onclick = function () { return false; };
						
						addReq ( target, href );

						return false;
					}
				}
				
				return true;
			}
	},

	'form.autoajax' : {
		'submit':
			function () {
				if ( target = this.getAttribute ( "target" ) ) {
					if ( action = this.getAttribute ( "action" ) ) {
						jQuery(this).ajaxSubmit ( {
							target: this.target,
							url: this.action,
							success: Behaviour.apply
						} );
						return false;
					}
				}
				return true;
			}
	},
	
	'a.autowant': {
		'click':
			function () {
				if ( href = this.getAttribute ( 'href' ) ) {
					if ( target = this.getAttribute ( 'target' ) ) {
						this.onclick = function () { return false; };

						addReq ( target, href );
						addReq ( 'mywanttabcount', 'a_mywanttabcount.php' );
						
						return false;
					}
				}
				
				return true;
			}
	},
	
	'a.autohave': {
		'click': function () {
			if ( href = this.getAttribute ( 'href' ) ) {
				if ( target = this.getAttribute ( 'target' ) ) {
					this.onclick = function () { return false; };

					addReq ( target, href );
					addReq ( 'myhavetabcount', 'a_myhavetabcount.php' );
					
					return false;
				}
			}
			
			return true;
		}
	}
};

jQuery( function () {
	jQuery.behaviour.register ( myrules );
	
	jQuery("div.autoajax").each ( function ( i ) {
		if ( src = this.getAttribute ( 'src' ) ) {
			if ( id = this.getAttribute ( 'id' ) ) {
				addReq ( id, src );
			}
		}
	} );
} );