var aCaseStudies = [
	['Caffe Nero', 'caffenero.html', ['RA'], 'We are retained by Caffe Nero as acquisition agents to advise on their expansion and strategic growth within the eastern Greater London region.']
	,['Oxygen Ladieswear', 'oxygenladieswear.html', ['RA','PS'], 'As sole advisors to Oxygen; operators of a chain of Ladies fashion stores, we are well placed to support their expansion plans and proactively research and highlight potential opportunities.']
	,['Penwood Investments Ltd', 'penwood.html', ['RA','AM','PM'], 'Acting on behalf of international property firm, Penwood Investments Ltd, we have represented them across a number of services most notably Retail Agency and Portfolio and Asset Management.']
	,['Cottrills Jewellers', 'cottrillsjewellers.html', ['RA','IC','CS','PS'], 'Cottrills are a well established retail operation in the North West. Hordern Ryan provide advice on a range of aspects of Cottrills&rsquo; operational portfolio.']
	,['Spot Property', 'spotproperty.html', ['AM','RA'], 'We undertake a Retail Agency and Asset Management role for this property company. This involves marketing any empty space and liaising with potential tenants as well as overall advice on tenant mix and Asset Management strategy.']
	,['Credit Suisse Asset Management', 'creditsuisse.html', ['AM'], 'Acting on behalf of Credit Suisse Asset Management we were asked to advise on the potential for redevelopment of a substantial holding in the West End of London.']
	,['Chrifin Ltd', 'chrifin.html', ['RA','PS','PM','AM','IC'], 'Chrifin Ltd is a private Irish client where we provide the complete property service from Portfolio Management and Investment Consultancy to Asset Management and Professional advice.']
	,['Greenhills Asset Management', 'greenhills.html', ['AM','RA'], 'Greenhills are another valued property company client where we act as their specialist Asset Management and Retail Agent on project specific instructions.']
	,['EPIC', 'epic.html', ['IC','CS'], 'Acting on behalf of EPIC, an international real-estate investment and asset management company, we have provided a number of our services in addressing their property needs.']
	,['Sony', 'sony.html', ['RA','PS','CS'], 'Acting on behalf of one of Sony Centre&rsquo;s South East franchises, we provided a comprehensive Retail Agency and Corporate Consultancy Service to support their ongoing business operations.']
	,['Charlotte Sharman (Foundation) Primary School', 'charlottesharman.html', ['AM'], 'We were appointed by the school to act on their behalf in negotiations with the Local Authority over a parcel of land required to facilitate the development of a Child Day Care Centre.']
	,['Linden Try Homes', 'lindentry.html', ['IC'], 'We have advised a diverse range of clients on a number of investment transactions.']
	,['Atlantic Pacific Capital Ltd', 'atlantic.html', ['CS'], 'Atlantic Pacific Capital appointed Hordern Ryan to advise on their occupational requirements as they sought new head office premises.']
	,['Signature / Strada Restaurants', 'strada.html', ['RA'], 'We advised and represented Strada Restaurants on the acquisition of their outlet in Wilmslow.']
	,['SPPARC Architecture', 'spparc.html', ['CS'], 'Providing our Corporate Service we have worked closely with SPPARC Architecture in addressing their property matters, allowing them to concentrate on their business operations.']
	,['F &amp; C REIT Asset Management', 'fcreit.html', ['RA','AM','PM'], 'We are advising this company on various agency and asset management initiatives on three properties in Swindon and Derby.']
];

var aServiceKeywords = new Array();
	// translate display codes into keywords that the database can recognise
	aServiceKeywords['RA'] = 'retailagency';
	aServiceKeywords['AM'] = 'assetmanagement';
	aServiceKeywords['IC'] = 'investmentconsultancy';
	aServiceKeywords['PM'] = 'portfoliomanagement';
	aServiceKeywords['CS'] = 'corporate';
	aServiceKeywords['PS'] = 'professional';



function readQS() {
	// parse querystring variables into object array
	var args = new Object();
	var query = location.search.substring(1);	
	var pairs = query.split("&");
	for(var i = 0; i < pairs.length; i++) {
		var pos = pairs[i].indexOf('=');
		if (pos == -1) continue;
		var argname = pairs[i].substring(0,pos);
		var value = pairs[i].substring(pos+1);
		args[argname] = unescape(value);
	}
	return args;
}


function getCurrentFileName(){
	// return filename of current page
	var url = window.location.pathname;
	return url.substring(url.lastIndexOf('/')+1);
}


function nextPrevCaseStudy(){
	// return HTML 'next' and 'previous' links based on current filename
	var sThisFile = getCurrentFileName();
	var iCount = aCaseStudies.length;
	for (var i = 0; i < iCount; i++){
		aCaseStudy = aCaseStudies[i];
		sFile = aCaseStudy[1];
		if (sFile == sThisFile){
			aPreviousCaseStudy = (i > 0) ? 	aCaseStudies[i-1] : aCaseStudies[iCount-1];
			sPreviousFile = aPreviousCaseStudy[1];
			aNextCaseStudy = (i < (iCount-1)) ? aCaseStudies[i+1] : aCaseStudies[0];
			sNextFile = aNextCaseStudy[1];
		}
	}
	var sHTML = '<p style="margin-top:20px;"><a class="small" href="/casestudies/' + sPreviousFile + '" title="Previous case study">&laquo; Previous case study</a>&nbsp;|&nbsp;<a class="small" href="/casestudies/' + sNextFile + '" title="Next case study">Next case study &raquo;</a></p>';
	return sHTML;
}


function drawSnippetContainer(sTopMargin){
	// returns a HTML snippet box populated with service keywords for the current case study
	// the snippet boxes will be populated on page load (see page_init.js)
	var sThisFile = getCurrentFileName();
	var sKeywordsList = "";
	for (var i = 0; i < aCaseStudies.length; i++){
		aCaseStudy = aCaseStudies[i];
		sFile = aCaseStudy[1];
		if (sFile == sThisFile){
			aServices = aCaseStudy[2];
			for (var j = 0; j < aServices.length; j++){
				sService = aServices[j];
				sKeywordsList += ' ' + aServiceKeywords[sService];
			}
		}
	}
	var sHTML = '<div class="inset' + sKeywordsList +'" style="margin-top:' + sTopMargin + ';"></div>'
	return sHTML;
}


function numberedLinksList(iTotalPages, iCurrentPage){
	// return HTML list of numbered page links
	var sHTML = '<ul class="paging">';
	for (var i = 1; i <= iTotalPages; i++ ){
		if (i == iCurrentPage){
			sHTML += '<li>' + i + '</li>';
		}else{
			sHTML += '<li><a href="casestudies.html?page=' + i + '">' + i + '</a></li>';
		}
	}
	sHTML += '</ul>';
	return sHTML;
}


function caseStudyList(iCurrentPage, iTotalRecs, aCaseStudies){
	
	// return display HTML for selected case study records based on current page
	
	var iStartRec = 0;
	var aCaseStudy, sName, sFile, aServices, sIntro, sHTML
	
	// set start rec from page num
	if (iCurrentPage > 1){
		iCurrentPage--; // page 2 is actually (1*recsPerPage)
		iStartRec = iCurrentPage * iRecsPerPage;
	}
	
	// set end rec from start rec
	var iEndRec = iStartRec + iRecsPerPage;
	if (iEndRec > iTotalRecs) { iEndRec = iTotalRecs}

	
	// create HTML
	sHTML = "";
	for ( var i = iStartRec; i <= iEndRec; i++ ){
		aCaseStudy = aCaseStudies[i];
		sName = aCaseStudy[0];
		sFile = aCaseStudy[1];
		aServices = aCaseStudy[2];
		sIntro = aCaseStudy[3];
		
		sHTML += '<h3><a href="/casestudies/' + sFile + '" title="' + sName + '">' + sName + '</a></h3>';
		for ( var j = 0; j < aServices.length; j++ ){
			sService = aServices[j];
			sHTML += '<div class="serviceicon ' + sService.toLowerCase() + '"><a class="' + sService.toLowerCase() + '" href="/services/'+aServiceKeywords[sService]+'.html">' + sService + '</a><div>&nbsp;</div></div>';
		}
		sHTML += '<br style="clear:both;"/>';
		sHTML += '<p>' + sIntro + '</p>';
		sHTML += '<a class="readmore" href="/casestudies/' + sFile + '" title="Read more">Read more &raquo;</a>';
	}
	
	return sHTML;
}
