if((typeof Viktor.NewsLoader) == "undefined") Viktor.NewsLoader = {};
Viktor.NewsLoader.Model = function(){
	var that = this;
	Viktor.service.addListner("LOAD_FEED", function(type){
		that.load(type);
	});
	Viktor.service.addListner("LOAD_PAGE", function(type){
		that.loadPage(type);
	});
}

Viktor.NewsLoader.Model.prototype = {
	load : function(type, feed){
		var news_type = type;
		var feed_url = type == "news" ? "?cat=" + Viktor.SWE_NEWS_CAT + "&feed=json" : "?cat=" + Viktor.PRESS_CAT + "&feed=json";
		if(type == 'texts'){
			feed_url = '?cat=6&feed=json';
		}
	
		$.ajax({
			url: Viktor.SITE_URL + feed_url,
			success: function(r){
				Viktor.service.sendEvent("LOAD_FEED_RESPONSE", {type : news_type, response : r});
			},
			error : function(){
				//alert('error');
			}
		});
	},
	loadPage : function(page)
	{
		
			var urlToLoad = page == "contact" ? Viktor.CONTACT_URL : Viktor.CV;
			$.ajax({
				url: urlToLoad,
				success : function(r){
					Viktor.service.sendEvent("SET_PAGE_CONTENT", {content: r.page.content, pageName:page});
				},
				error : function(){
					//fukked upp
				}
			})
	}
}

