
NS.Package('NS.Site.Menu');
/**
 * @vesrion 1.1.2
 * menu is based on the te genereared menu lists
 * and the menu css frame 
 * 
 											button and bottom onder de button 				(default "bottom") 
 * @option[ajax] 			(Object)		de ajax jquery object integrateed in the menu	
 											set false to turn of
 * @option[ajax][type] 		(String)		type of "method" 								default "POST"
 * @option[ajax][dataType]	(String) 		type data 										default "json"
 * @option[ajax][url] 		(String)		the content request handler						default "request/handler.php"
 * @option[ajax][target] 	(String)		the target 	of the content 						default "#content"
 * @option[ajax][imgLoader] (String)		the image to view by the loading prosses		default "images/ajax-loader2.gif"
 * @option[ajax][success] 	(Function)		method callback method execute when 
 											finished request
 * @option[breadcrumb]			(String)		true or false to update the breadcrunb	 		default "true"
 * @option[breadcrumb][target]	(String)		the target selector of the breadcrunb holder	default ".breadcrumb"
 * @option[breadcrumb][prefix]	(String)		prefix string for te breadgrumb menu
 */


NS.Site.Menu = function(options){
	
	var _option = {};
	var _method = {
		
		// ---
		init : function(opt){

			return {
				ajax : (opt.ajax === false)? false : {
					type 		: opt.ajax.type 		|| 'POST',
					dataType 	: opt.ajax.dataType 	|| 'json',
					url  		: opt.ajax.url  		|| 'request/handler.php',
					target	 	: opt.ajax.target       || '#content',
					imgLoader   : opt.ajax.imgLoader    || 'images/loader.gif',
					success 	: opt.ajax.success      || false
				},
				breadcrumb	: (opt.breadcrumb == undefined)? false : {
					prefix : opt.breadcrumb.prefix || '<span>U bevindt zich hier: </span>',
					target : (!opt.breadcrumb || !opt.breadcrumb.target)? '.breadcrumb' : opt.breadcrumb.target
				} 			
			}
		},
		
		// --- request handler --- 
		request : function(button){
			$.ajax({
			  type			: _option.ajax.type,
			  url			: _option.ajax.url,
			  data			: NS.UT.Tools.getUrlVars(window.location.search +'&'+button.attr('href').substr(1)) ,
			  dataType		: _option.ajax.dataType,
			  beforeSend 	: function(){
			  	$(_option.ajax.content).html('');
			  	// set loader
			  	NS.UT.Tools.loader({
		  			target 	: _option.ajax.target,
					cssClass : 'pageLoader',
					text	: 'de pagina wordt geladen...',
					src     :  _option.ajax.imgLoader
			  	});
			  },
			  success		: function(data){
			  		// set content
			   		$(_option.ajax.target).html( data.text );
			   		// collback
			    	if( _option.ajax.success){
			    	 	_option.ajax.success(data);
			    	}
			    	if(_option.breadcrumb){	    		
			    		$(_option.breadcrumb.target).html( _option.breadcrumb.prefix + data.breadcrumb);
			    	}
			  }
			});			
		}
	};
	// --------- initialization ---------
	_option = _method.init(options);
	
	return {
		request : _method.request
	};
};


