var ObjHandler = new Class
(
	{
		xml: "",
		objs: new Object(),
		plugins: new Object(),
		options: "",
		defcontent: "",
		
		initialize: function()
		{
			
			this.init();
		},
	
		
		
		init: function()
		{	
				var jsonRequest = new Request({url: "pages.php", onSuccess: function(e){
				
					
					this.storeXML(e);
				}.bind(this)});
				
				
				jsonRequest.send();

		},
		
		
		storeXML: function(e){
			this.xml =  xml2json.parser(e); //$.xml2json(e);
			 this.createMenus();
		 	 this.createObjs();
		 	 if(this.xml.main.options)
		 	 this.options = this.xml.main.options;
		},
		
		createMenus: function(){
			
			 var search = this.xml.main.menus.ajaxmenu;				
 
 				 if(jQuery(search).length == 1)
 				 search[0] = search;
 				 	
 				 jQuery(search).each(function(e){
 				
 				 
 					 this.objs[search[e].name] = new AjaxMenu(search[e]);
 				 
 					 
 				}.bind(this))
		
		},
		
		createObjs: function(){
			
				 
				
				 
				 
				 
				 
				 var search = this.xml.main.contents.cont;
				  				
 
 				 if(jQuery(search).length == 1)
 				 search[0] = search;
 				 	
 				 jQuery(search).each(function(e){
 					 
 					

 					 switch( search[e].typ ){
 					 	
 					 	
 					 	case 'StaticContent':
 					 		 this.objs[search[e].name] = new StaticContent(search[e]);
 					 	break;
 					 	case 'StaticPage':
 					 		 this.objs[search[e].name] = new StaticPage(search[e]);
 					 	break;
 					 	case 'Blog':
 					 		 this.objs[search[e].name] = new BlogContent(search[e]);
 					 	break;
 					 	
 					 	default:
 					 		if(console)
 					 		console.log('ERR - Objekthandler kenn typen des objs nicht - '+search[e].typ )	
 					 
 					 
 					 
 					 }
 				 	 
 					
 				 
 					 if(search[e].def == "1" && window.location.hash == ""){
 					 //	this.objs[search[e].name].load(true)
 					 	this.defcontent = search[e].name;
 					 	 
 				 	 }
 			  
 				 
 				}.bind(this))
 				
 				
			
			
			
		
		},
		
		LoadContent: function(params){
			
			
			
			if(params.go == "" || params.go == undefined)
			params.go = this.defcontent;
			
			 for(var i in this.objs){
 				
 				 	 
 					 if(i==params.go)
 					 {
 					 	
 					 	

 					 	this.objs[i].load(params) 
 				 	 }
 			  
 				 
 				}
		}
		
		
	}
)
