
function getElementWithArguments(tag, keys, values, content) {
	var newElement = document.createElement(tag);
	keys.forEach(function(element, index, array) {
		newElement.setAttribute(element, values[index]);
	});
	if( content == null )
		return newElement;
	newElement.innerHTML = content;
	return newElement;
}

function _downloadGaleria(id) {
	var oReq = new window.XMLHttpRequest({mozAnon: true, mozSystem: true});
	var url = 'https://api.storageroomapp.com/accounts/5127b2ad0f660245fa00106c/collections/5130f6b00f66024373001fff/entries.json?auth_token=iazyariHhoxQnisc4UyX&id_contenido=' + id;
	oReq.open("GET", url, true);
	oReq.ontimeout = function () {
		alert('Verifica tu conexión a Internet');
	}
	oReq.onerror = function (e) {
		alert('Algo anda mal :\'(\nIntentalo más tarde.');
	}
	oReq.onload = function(e) {
		try {
			var root = JSON.parse(this.responseText).array.resources;
			root.forEach(function(element, index, collection){
				var title = getElementWithArguments('div', ['class'], ['img-previa'], 
					'<a href="foto.html?id=' + element.imagen['@url'] + '">' +
					'	<img src="' + element.img_preview['@url'] + '" />' +
					'</a>');
				document.getElementById('div-main').appendChild(title);
			});
		}catch(e) {
			console.log('parsing error :\'(');
		}
	}
	oReq.send();
}

function _openBannerInBrowser(URL) {
	var activity = new MozActivity({
		name: "view",
		data: {
			type: "url",
			url: URL
		}
	});
	activity.onsuccess = function() {
		console.log("url opened succesfully :P");
	};
	activity.onerror = function() {
		console.log(this.error);
	};
}