var storage = localStorage;
class my_storage{
			
	//データ書き込み
	WriteData(item,vale){
		var res = this.ReadData(item);
		//データリスト設定
		if(res == null){
			var res2 = this.ReadData("datacount");
			if((res2 == null)&&(res2==0)){
				res2 = 1;
			}else{
				res2++;
			}
			storage.setItem(res2,item);
			storage.setItem("datacount",res2);
		}
		storage.setItem(item,vale);
		
		return res2;
		
	}
	
	//設定データ書き込み
	AddData(item,vale){
		storage.setItem(item,vale);		
	}
	
	//設定データ書き込み
	WriteSettingData(item,vale){
		storage.setItem(item,vale);		
	}
	
	//データ読み込み
	ReadData(item){
		var res = null;
		res = storage.getItem(item);
		//Undefined対応
		if(res == "undefined"){
			res = null;
		}
		return res;
	}
	
	//データ削除
	DeleteData(item){
		//データ数取得
		var data_count = parseInt(this.ReadData("datacount"));
		//データ数修正
		var del_sw = false;
		var delete_success = false;
		for(var loop=1;loop<=data_count;loop++){
			var get_item_data = this.ReadData(loop);
			if(get_item_data == item){
				storage.removeItem(loop);
				storage.removeItem(item);
				var setting_data =  item.replace('_title','_setting');
				storage.removeItem(setting_data);
				del_sw = true;
				delete_success = true;
			}
			if(del_sw){
				var next_data = parseInt(loop+1);
				if(next_data<=(data_count+1)){
					get_item_data = this.ReadData(next_data);
					if(get_item_data!=null){
						var bodyData = this.ReadData(get_item_data);
						var setting_data_name =  get_item_data.replace('_title','_setting');
						var setting_data = this.ReadData(setting_data_name);
						if(next_data == data_count){
							storage.removeItem(next_data);
							storage.removeItem(get_item_data);
							storage.removeItem(setting_data_name);
							del_sw = false;
						}
						storage.setItem(loop,get_item_data);
						storage.setItem(get_item_data,bodyData);
						storage.setItem(setting_data_name,setting_data);
						
					}
				}
			}
		}
		//ちゃんと消せれたら
		if(delete_success){
			storage.setItem("datacount",data_count-1);
			storage.removeItem("select_data");
		}
	}
	
	//データ一覧取得
	GetList(novel_delete = 0){
		var data_count = this.ReadData("datacount");
		var return_data; 
		if((data_count != null)&&(data_count > 0)){
			data_count = parseInt(data_count);
			return_data = new Array(data_count);
			var count = 0;
			for(var loop=1;loop<=data_count;loop++){
				var get_title = this.ReadData(loop);
				var get_novel = this.ReadData(get_title);
				get_title = get_title.substring(0,get_title.indexOf("_title"));
				if(novel_delete != 1){
					return_data[count++] = '<input type="button" class="button button_novel_list" id="'+loop+'" value="'+get_title+'"/>';
				}else{
					return_data[count++] = '<input type="button" class="button button_novel_list" id="'+loop+'" value="'+get_title+'"...削除/>';
				}
			}
		}else{
			return Array("まだ作品はありません。");
		}
		
		return return_data;
	}
}
storage_func = new my_storage;