/**
 * ajaXing-jQuery-PlugIn 
 * @author Florian Weidensdorfer
 * @copyright 2009
 */
 
(function() {
	
	var ajaxing = new Object;
	
	// Settings/Defaults
	
	ajaxing.defaults = {
		event : 'click',
		click : false,
		selector: '*',
		target: 'body',
		base : false,
		location : false,
		interval : false
	}
	
	ajaxing.debug = true;

	// Methods
	
	ajaxing.methods = {
		
		ajaxing : function(options) {

			if(!$(this).size()){
				$.ajaxing.log('Error: No matched element/s for your ajaXing selector " '+$(this).selector+' ".');
				return false;
			}
			
			var ver = jQuery.fn.jquery.split('.');
			if(ver[0] <= 1 && ver[1] <= 2 && ver[2] < 6){
				$.ajaxing.log('Error: Your jQuery version is old. Version 1.2.6 or newer is required.');
				return false;
			}
			
			return this.each(function() {
				var options = $.extend({},ajaxing.defaults, options);
				options = $.ajaxing.settings(options);
				$.ajaxing.log(options);
			} );

	    }
  
	};
  
	jQuery.each(ajaxing.methods, function(key) {
    	jQuery.fn[key] = this;
 	} );

	// Functions
	
	ajaxing.functions = {
		
		settings : function(options) {
							
			if ($('base').length) {
				options.base = $('base').attr('href');
				if (options.base.lastIndexOf('/')==options.base.length-1) options.base = options.base.substr(0,options.base.length-1);
			} else {
				options.base = 'http://' + location.host + '/';
			}
			
			options.location = ( location.hash.indexOf('#')==0 ? location.hash.replace('#','').split('#') : location.hash.split('#') );
			if (options.location[0].charAt(0)=='/') {
				options.location = { 
					href : options.location[0],
			 		hash : options.location[1]
		 		};
			} else {
				options.location = { 
					options : location.href.replace(options.base,'').split('#')[0],
			 		options : options.location[0]
		 		};
		 		location.hash = options.location.href;
			}
	
			return options;
	
	    },
	    
	    log : function(data) {
	    	
    		if(ajaxing.debug) {
				if(window.console) {
			 		console.debug(data);
				} else {
			 		alert(data);
	 			}
			}
	    	
	    }
  
	};
  
  	jQuery.ajaxing = new Object;
	jQuery.each(ajaxing.functions, function(key) {
    	jQuery.ajaxing[key] = this;
 	} );
  
})();
