var max = 12;
var category_q_num = 4;
var count = 0;
var correct_num = 0;
var all_q_data;
var q_data;
Array.prototype.shuffle = function() {
var i = this.length;
while(i){
var j = Math.floor(Math.random()*i);
var t = this[--i];
this[i] = this[j];
this[j] = t;
}
return this;
}
function initialize(){
count = 0;
correct_num = 0;
all_q_data = new Array();
q_data = new Array();
tmp_q_data = new Array();
$.each(LinkData.getWorks(), function(workKey, workValue) {
$.each(LinkData.getFiles(workValue), function(fileKey, fileValue) {
$.each(LinkData.getSubjects(workValue, fileValue), function(subjKey, subjValue) {
var tmp_data = {}
tmp_data["id"] = subjValue;
$.each(LinkData.getProperties(workValue, fileValue), function(propKey, propValue) {
$.each(LinkData.getObjects(workValue, fileValue, subjValue, propValue), function(objKey, objValue) {
if(propValue == "http://linkdata.org/property/rdf1s560i#question"){
tmp_data["q"] = objValue;
}else if(propValue == "http://linkdata.org/property/rdf1s560i#choice1"){
tmp_data["c1"] = objValue;
}else if(propValue == "http://linkdata.org/property/rdf1s560i#choice2"){
tmp_data["c2"] = objValue;
}else if(propValue == "http://linkdata.org/property/rdf1s560i#choice3"){
tmp_data["c3"] = objValue;
}else if(propValue == "http://linkdata.org/property/rdf1s560i#choice4"){
tmp_data["c4"] = objValue;
}else if(propValue == "http://linkdata.org/property/rdf1s560i#answer"){
tmp_data["a"] = objValue;
}else if(propValue == "http://linkdata.org/property/rdf1s560i#category"){
tmp_data["category"] = objValue;
}else if(propValue == "http://linkdata.org/property/rdf1s560i#kaisetsu"){
tmp_data["detail"] = objValue;
}
});
});
tmp_q_data.push(tmp_data);
});
});
});
all_q_data = tmp_q_data;
var data_h = new Array();
var data_c = new Array();
var data_l = new Array();
all_q_data.forEach(function(e, i, a){
if(e.category == "歴史"){
data_h.push(e);
}else if (e.category == "文化・スポーツ"){
data_c.push(e);
}else if (e.category == "生活"){
data_l.push(e);
}
});
var selected_h = random(data_h, category_q_num);
var selected_c = random(data_c, category_q_num);
var selected_l = random(data_l, category_q_num);
[].push.apply(q_data, selected_h);
[].push.apply(q_data, selected_c);
[].push.apply(q_data, selected_l);
q_data = q_data.shuffle();
$("#contents").empty();
var intro = "<div id='introduction'><H1>姫路検定</H1><H3>あなたの姫路力をチェック!</H3><div><div>下のボタンを押して<br/>検定をはじめましょう。</div><div class='button'><input type='submit' value='スタート' onclick='next();'/></div></div></div>";
$("#contents").append(intro);
}
function next(){
$("#contents").empty();
if(count < max){
count++;
var tmp_q = q_data[count-1];
var q = $("<div id='question'>");
var c = $("<h1>第<span id='count'>"+count+"</span>問</h1>");
var h3 = $("<h3>"+tmp_q.q+"</h3>");
var choices = $("<div id='choices'/>");
var choice = [$("<div><input type='radio' name='answer' value='1'>"+tmp_q.c1+"</div>"),$("<div><input type='radio' name='answer' value='2'>"+tmp_q.c2+"</div>"),$("<div><input type='radio' name='answer' value='3'>"+tmp_q.c3+"</div>"),$("<div><input type='radio' name='answer' value='4'>"+tmp_q.c4+"</div>")];