document.getElementsByClassName = function(cl) {
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = this.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i++) {
		var classes = elem[i].className;
		if (myclass.test(classes)) retnode.push(elem[i]);
	}
	return retnode;
};

function GalleryConnection(dataClassName) {
	this.relData = [];
	this.initialized = false;	
	this.initConnection = initConnection;
	this.grabData = grabData;
	this.sendData = sendData;
}

function grabData(dataClassName) {
	var el = document.getElementsByClassName(dataClassName);
	var chn, i;
	for (i=0; i<el.length; i++) {
		chn = el[i].childNodes;
		if (chn.length == 1) this.relData.push(chn[0].nodeValue);
	}
}

function initConnection(url, target, dataHolder) {
	var d = document;
	var theBody = d.getElementById(dataHolder);
	this.myForm = d.createElement('form');
	this.myInput = d.createElement('input');
	this.myInput2 = d.createElement('input');
	this.myInput.style.display = 'none';
	this.myInput.type = 'text';
	this.myInput.name = 'imgdata';
	this.myInput.value = this.relData.join(',');
	this.myInput2.style.display = 'none';
	this.myInput2.type = 'text';
	this.myInput2.name = 'imgdata2';
	this.myForm.action = url;
	this.myForm.method = 'post';
	this.myForm.target = target;
	this.myForm.appendChild(this.myInput);
	this.myForm.appendChild(this.myInput2);
	theBody.appendChild(this.myForm);
	this.initialized = true;
}

function sendData(additionalData) {
	if (!this.initialized) window.alert('Vyčkejte prosím do načtení celé stránky.');
	this.myInput2.value = additionalData;
	this.myForm.submit(); 
}
