var currentimg = "";
var dl = {imagelinks: {}};

function onStatus(id) {
	new Ajax.Updater('status'+id, 'partials/_status.php?id='+id, {method:'get'});
}

function onStatusBack(id) {
	new Ajax.Updater('status'+id, 'partials/_status.php?id='+id+'&action=back', {method:'get'});
}

function changeImage(number, id, total) {
	for(i = 1; i<total+1; i++) {
		element = document.getElementById("imagelink" + id + "_" + i);
		element.style.color = "#999";	
	}
	
	el = document.getElementById(currentimg);
	el.style.color = "#000";
	
	imagelink = dl['imagelinks']['image' + id][number - 1]
	
	new Ajax.Updater('image'+id, 'partials/_imagelink.php?id='+id+'&link='+imagelink, {method:'get'});
	//el = document.getElementById('image' + id)
	//el.src = dl['imagelinks']['image' + id][number - 1];
}

function nextImage(id, total) {
	currentnumber = dl['imagelinks']['currentnumber' + id];
	
	for(i = 1; i<total+1; i++) {
		element = document.getElementById("imagelink" + id + "_" + i);
		element.style.color = "#999";	
	}
	
	if(currentnumber != total) {
		currentimg = dl['imagelinks']['imagelink' + id][currentnumber];
	} else {
		currentimg = dl['imagelinks']['imagelink' + id][0];
	}
	
	el = document.getElementById(currentimg);
	el.style.color = "#000";
	
	if(currentnumber != total) {
		currentnumber = currentnumber + 1;
	} else {
		currentnumber = 1;
	}
	
	imagelink = dl['imagelinks']['image' + id][currentnumber - 1];
	new Ajax.Updater('image'+id, 'partials/_imagelink.php?id='+id+'&link='+imagelink, {method:'get'});
	
	//el = document.getElementById('image' + id)
	//el.src = dl['imagelinks']['image' + id][currentnumber - 1];
	
	dl['imagelinks']['currentnumber' + id] = currentnumber;
}

function previousImage(id, total) {
	currentnumber = dl['imagelinks']['currentnumber' + id];
	
	for(i = 1; i<total+1; i++) {
		element = document.getElementById("imagelink" + id + "_" + i);
		element.style.color = "#999";	
	}
	
	if(currentnumber != 1) {
		currentimg = dl['imagelinks']['imagelink' + id][currentnumber-2];
	} else {
		currentimg = dl['imagelinks']['imagelink' + id][total-1];
	}
	
	el = document.getElementById(currentimg);
	el.style.color = "#000";
	
	if(currentnumber != 1) {
		currentnumber = currentnumber - 1;
	} else {
		currentnumber = total;
	}
	
	imagelink = dl['imagelinks']['image' + id][currentnumber - 1];
	new Ajax.Updater('image'+id, 'partials/_imagelink.php?id='+id+'&link='+imagelink, {method:'get'});
	
	//el = document.getElementById("image" + id)
	//el.src = dl['imagelinks']['image' + id][currentnumber - 1];
	
	dl['imagelinks']['currentnumber' + id] = currentnumber;
}

function createArray(id, total, number) {
	dl['imagelinks']['imagelink' + id] = new Array;
	
	for(i=1; i<total + 1; i++) {
		dl['imagelinks']['imagelink' + id][i-1] =  "imagelink" + id + "_" + i;
	}
	
	if(number != null) {
		currentimg = dl['imagelinks']['imagelink' + id][number-1];
		dl['imagelinks']['currentnumber' + id] = number;
	}
}

function setLinks(array, id, current) {
	dl['imagelinks']['image' + id] = new Array;
	dl['imagelinks']['currentnumber' + id] = new Number;
	dl['imagelinks']['currentnumber' + id] = current;
	
	for(i = 0; i < array.length; i++) {
		dl['imagelinks']['image' + id][i] = array[i];
	}
}