// parameters
var param_wsId = "od6";
var param_ssKey = "pVabH0j6EqpO9qbXwzAuCGA";
var param_gigtitle = "gigtitle";
var param_gigvenue = "gigvenue";
var param_gigdate = "gigdate";
var param_time = "gigtime";
var param_gigaddress = "gigaddress";
var param_gigtown = "gigtown";
var param_gigregion = "gigregion";
var param_gigcountry = "gigcountry";
var param_giglink = "giglink";

// use the loaded data to generate gigs
function LoadGigs(json) {
	// loop through all rows
	for (var i = 0; i < json.feed.entry.length; i++) {
		// get feed
		var entry = json.feed.entry[i];
		// create holder div
		var iwikgig = document.createElement("div");
		iwikgig.setAttribute("class", "gig");
		// and as usual we need a fucking fix for IE...
		iwikgig.setAttribute("className", "gig");
		// create time
		var iwiktime = document.createElement("span");
		iwiktime.setAttribute("class", "time");
		iwiktime.setAttribute("className", "time");
		iwiktime.appendChild(document.createTextNode(entry["gsx$"+param_time].$t));
		// add time to holder
		iwikgig.appendChild(iwiktime);
		
		// create date
		var iwikdate = document.createElement("span");
		iwikdate.setAttribute("class", "date");
		iwikdate.setAttribute("className", "date");
		iwikdate.appendChild(document.createTextNode(entry["gsx$"+param_gigdate].$t));
		// add date to holder
		iwikgig.appendChild(iwikdate);
		// add break
		iwikgig.appendChild(document.createElement("br"));
		
		// details
		var iwikdetails = document.createElement("div");
		iwikdetails.setAttribute("class", "details");
		iwikdetails.setAttribute("className", "details");
		var detailholder = document.createElement("h2");
		detailholder.appendChild(document.createTextNode(entry["gsx$"+param_gigvenue].$t));
		detailholder.appendChild(document.createTextNode(" "));
		detailholder.appendChild(document.createTextNode(entry["gsx$"+param_gigtitle].$t));
		iwikdetails.appendChild(detailholder);
		// add details to holder
		iwikgig.appendChild(iwikdetails);
		
		// and the address			
		var address = document.createElement("div");
		address.setAttribute("class", "address");
		address.setAttribute("className", "address");
		address.appendChild(document.createTextNode(entry["gsx$"+param_gigaddress].$t));
		address.appendChild(document.createTextNode(" "));
		address.appendChild(document.createTextNode(entry["gsx$"+param_gigtown].$t));
		address.appendChild(document.createElement("br"));
		address.appendChild(document.createTextNode(entry["gsx$"+param_gigregion].$t));
		
		// add address to holder
		iwikgig.appendChild(address);
		
		// get the main holder div on the website
		var maindiv = document.getElementById("left_text");
		// and add the whole thing in one go
		maindiv.appendChild(iwikgig);
	}
}

// load JSON feed
function LoadUpGigs() {
	var script = document.createElement('script');
	script.setAttribute('src', 'http://spreadsheets.google.com/feeds/list' + '/' + param_ssKey + '/' + param_wsId + '/public/values' + '?alt=json-in-script&callback=LoadGigs');
	script.setAttribute('id', 'jsonScript');
	script.setAttribute('type', 'text/javascript');
	document.documentElement.firstChild.appendChild(script);
}
