var _clientContainer = document.getElementById("clientContainer");
var i = 0;
var _prevObj = null;


document.getElementById("jsonLinkContainer").style.display = "block";

function generateClientList(strIndustry,strRegion,obj) {


	obj.className = "activeJSONLink";

	
	if(_prevObj != null && _prevObj != obj) {
		_prevObj.className = "";
	}

	_clientContainer.innerHTML = "";


	showLoader();	
	
	if(typeof _clientArray != 'undefined' && _clientArray != null) {
		
		
		
		for (i = 0; i < _clientArray.length; i++) {
		
			if(strRegion != null && strRegion == _clientArray[i].region) {
				createClient(i);
				
			} else if(strRegion != null && _clientArray[i].region == "global") {
				createClient(i);
			} else if(strIndustry != null && _clientArray[i].industry.indexOf(strIndustry) > -1) {
				createClient(i);
			} else if(strIndustry == null && strRegion == null) {
				createClient(i);
			}

		}		
		
	} else {
		alert("Error reading xml");
	}
	
	hideLoader();
	
	_prevObj = obj;
}

function showLoader() {
	document.getElementById("ajaxLoader").style.display = "block";
}

function hideLoader() {
	document.getElementById("ajaxLoader").style.display = "none";
}

function createClient(int) {
	//create containing div for each client
	var _containerDiv = document.createElement("div");
	_containerDiv.className = "clientItem";


	//create link around image
	    var _clientLink = document.createElement("a");
	    _clientLink.href = _clientArray[int].url;
         _clientLink.target = "_blank";

    	
			//create image
			var _clientImage = document.createElement("img");
			_clientImage.src = _clientArray[int].image;
			_clientImage.alt = _clientArray[int].title;
			_clientImage.title = _clientArray[int].title;

			//add image to link, link to container

			if (_clientLink != "") {
			    _clientLink.appendChild(_clientImage);
			    _containerDiv.appendChild(_clientLink);
			}
			else {
			    _containerDiv.appendChild(_clientImage);
			}
	
	//create title span
	var _titleSpan = document.createElement("span");
	_titleSpan.innerHTML = _clientArray[int].title;
	_titleSpan.className = "titleSpan";
	_containerDiv.appendChild(_titleSpan);
	
	//create country span
	var _countrySpan = document.createElement("span");
	_countrySpan.innerHTML = _clientArray[int].country;
	_containerDiv.appendChild(_countrySpan);
	
	//add containing div to overall page
	_clientContainer.appendChild(_containerDiv);
}

generateClientList(null,null,document.getElementById('viewAllLink'));