var IMGS_URL = new Array();
var IMGS_TITLE = new Array();
var IMGS_DESC = new Array();
var ivcimg = -1;

function loadImgURL(a) {

	var type = typeof(a);

	switch(type){

		case 'object':
		IMGS_URL = IMGS_URL.concat(a);
		break;

		case 'string':
		IMGS_URL.push(a);
		break;

		default:
		break;

	}

}


function loadImgTitle(a) {

	var type = typeof(a);

	switch(type){

		case 'object':
		IMGS_TITLE = IMGS_TITLE.concat(a);
		break;

		case 'string':
		IMGS_TITLE.push(a);
		break;

		default:
		break;

	}

}


function loadImgDesc(a) {

	var type = typeof(a);

	switch(type){

		case 'object':
		IMGS_DESC = IMGS_DESC.concat(a);
		break;

		case 'string':
		IMGS_DESC.push(a);
		break;

		default:
		break;

	}

}


function buildImgViewer(id) {

	//-- Do not build the viewer if image URLs have not been loaded

	if(IMGS_URL.length == 0) return;


	//-- Build the image viewer in the requested element

	var ivobj = document.getElementById(id);
	var ihtml = "";


	ihtml += "<div id=\"container\">";

	ihtml += "<div id=\"title\"></div>";
	ihtml += "<div id=\"img\" onClick=\"imgViewerChange('" + id + "', 1);\"></div>";
	if(IMGS_URL.length > 1) ihtml += "<div id=\"img-viewer-instructions\">Click on the image to see more</div>";
	ihtml += "<div id=\"desc\"></div>";

	ihtml += "</div>";

	ivobj.innerHTML = ihtml;

	imgViewerChange(id, 1);

}

function imgViewerChange(id, dir) {

	var ivobj = document.getElementById(id);
	ivcimg += dir;
	if(ivcimg >= IMGS_URL.length) ivcimg = 0;
	if(ivcimg <= -1) ivcimg = IMGS_URL.length - 1;


	//-- Remove the instructions

	if(ivcimg == 1)	document.getElementById('img-viewer-instructions').style.display = 'none';


	//-- Set the image to the new image

	for(var i=0; i<ivobj.childNodes[0].childNodes.length; i++){

		if(ivobj.childNodes[0].childNodes[i].id == 'img'){

			ivobj.childNodes[0].childNodes[i].innerHTML = "<img src=\"" + IMGS_URL[ivcimg] + "\">";
			break;

		}

	}


	//-- Set the title to the new title

	for(var i=0; i<ivobj.childNodes[0].childNodes.length; i++){

		if(ivobj.childNodes[0].childNodes[i].id == 'title'){

			ivobj.childNodes[0].childNodes[i].innerHTML = IMGS_TITLE[ivcimg];
			break;

		}

	}


	//-- Set the description to the new description

	for(var i=0; i<ivobj.childNodes[0].childNodes.length; i++){

		if(ivobj.childNodes[0].childNodes[i].id == 'desc'){

			ivobj.childNodes[0].childNodes[i].innerHTML = IMGS_DESC[ivcimg];
			break;

		}

	}

}



