
var LinkedImageDisplay = null,
	ImageDisplay = null;
	
function DrawPageGallery() {
	if(Page){
		if(oImg=Page.GetImage(0)){
			if(!oImg.getLink())
				if(!isProjectCategory)
					document.write("<div id=\"dynamic-image-display-container\"><img id=\""+Page.UID+"\" src=\""+oImg.getPath()+"\" alt=\"\"></div>");
				else{
					var szO="<div id=\"dynamic-image-display-container\">\
					<table cellpadding=0 cellspacing=0 border=0 id=\"projthumbs\">\
					<tr>";
					var disped=0;
					for(i=1;i<=PerPage;i++){
						szO += "<td align=left valign=top class=\"tiledproject\"><img id=\""+(Page.UID+i)+"\" src=\"\" alt=\"\"><br /><span class=\"projectcaption\" id=\"spn"+(Page.UID+i)+"\"> </span></td>";
						disped++;
						if(disped==3){
							disped=0;
							szO += "</tr><tr>";
						}
					}
					szO += "</tr></table></div>";
					document.write(szO);
				}
			else
				if(!isProjectCategory)
					document.write("<div id=\"dynamic-image-display-container\"><a href=\""+oImg.getLink()+"\" id=\""+Page.LID+"\"><img border=\"0\" id=\""+Page.UID+"\" src=\""+oImg.getPath()+"\" alt=\"\"></a></div>");
				else{
					var szO="<div id=\"dynamic-image-display-container\">\
					<table cellpadding=0 cellspacing=0 border=0 id=\"projthumbs\">\
					<tr>";
					var disped=0;
					for(i=1;i<=PerPage;i++){
						szO += "<td align=left valign=top class=\"tiledproject\"><a href=\"\" id=\""+(Page.LID+i)+"\"><img border=\"0\" id=\""+(Page.UID+i)+"\" src=\"\" alt=\"\"><br /><span class=\"projectcaption\" id=\"spn"+(Page.UID+i)+"\"> </span></a></td>";
						disped++;
						if(disped==3){
							disped=0;
							szO += "</tr><tr>";
						}
					}
					szO += "</tr></table></div>";
					document.write(szO);
				}
			/*done!*/
			if(Page.Images.length>1){
			  if(isProjectCategory)
			    document.write("<br clear=\"all\">");
				document.write(Page.DrawNavigation());
				if(isProjectCategory)
					__sPageImg(0);
			}
		}else document.write("Gallery coming soon...<br /><br /><br />");
	}
}

var __oSimgBtn=null;

function __sImg(i,ib)
{
	if(oImg = findObj(Page.UID))
	{
		if(newImage = Page.GetImage(i))
		{
			oImg.src=newImage.getPath();
			
			if(newImage.getLink())
			{
				oImgLnk=findObj(Page.LID);
				if(oImgLnk && oImgLnk.href)
					oImgLnk.href = newImage.getLink();
			}
			
			Page.CurrentImage = i;
		}
	}	
}

function __sPageImg(i,ib)
{
	/* i = page start. 0 : 0-3, 4: 4-8, */

	if(!Page)return;
	
	Page.CurrentPage = Math.floor(i / PerPage) % ((Page.Images.length*PerPage)-1);
	
	var xSel=0;
	
	for(j = i-1; j <= i+PerPage; j++)
	{
		if(oImg = findObj(Page.UID+xSel))
		{
			if(newImage = Page.GetImage(j))
			{
				oImg.src = newImage.getPath();
				oImg.style.display = '';
				//alert(newImage.getPath());
				if(newImage.getLink())
				{
					oImgLnk = findObj(Page.LID+xSel);
					if(oImgLnk)
						oImgLnk.href = newImage.getLink();
				}
				
				oSpan=findObj("spn"+Page.UID+xSel);
				
				if(oSpan)
					oSpan.innerHTML=newImage.getTitle();
			}
			else
			{
				oImg.src="";
				oImg.style.display='none';
				//alert(newImage.getPath());
				oImgLnk=findObj(Page.LID+xSel);
				if(oImgLnk)
					oImgLnk.href = "";
				oSpan=findObj("spn"+Page.UID+xSel);
				if(oSpan)
					oSpan.innerHTML="";
			}
		}	
		xSel++;
	}
}
var Page = {
	UID: "cImg",
	LID: "cImgLnk",
	Images: ['46f292c98dfb3.jpg','46f29ad354a73.jpg','46fa8972bcb91.jpg','4bab5edd27c97.jpg','48ff9cf36a156.jpg','47040d552552e.jpg','4ba929c32a9f6.jpg','46f97a4fa318f.jpg','470500ae49e78.jpg','4703ad389436d.jpg','46fa88cd60720.jpg','492efa3daf9b9.jpg','46efe18361331.jpg','46f97a9d76c54.jpg','4703ef572ee9e.jpg','4714df1b558b1.jpg','4714e1f086c4c.jpg','46efda2c9a306.jpg','46fa7434362c8.jpg','46efe455d7c70.jpg','46e57512b467a.jpg','4714ddb063166.jpg','46fa75443c5e7.jpg','4713e2c5d51b0.jpg','470bcb2a21c8f.jpg','4a215f19c77fd.jpg'],
	CurrentImage:0,
	ImagePath:"img-projects/categories/",
	Thumbs: [],
	Projects: ['?project=Place-Joseph-Royal-Condominiums&id=60','?project=Flora-Place-Housing&id=133','?project=Parish-Hall-Condominiums&id=154','?project=Greenheart-Housing-Co-op&id=135','?project=Pulse-on-River-Condominiums&id=142','?project=Ship-Street-Condominiums&id=47','?project=U-of-W-Housing&id=151','?project=Eco-4-Horace&id=73','?project=Kestepnan-Village-Housing&id=169','?project=Brandt-Reid-Residence&id=132','?project=Thompson-Senior-Housing&id=143','?project=Renaissance-Station-Condominiums&id=61','?project=Thompson-Residence&id=48','?project=Eco-Village-Condominiums&id=7','?project=Logan-and-Ellen-Housing&id=170','?project=Central-Park-Co-op&id=44','?project=Artemis-Housing&id=130','?project=North-Logan-Housing&id=138','?project=Atlas-Brush-Warehouse&id=102','?project=Native-Women\'s-Transition-Centre&id=136','?project=McCormick\'s-Factory-Apartments&id=109','?project=Weston-Firehall-Redevelopment&id=150','?project=Charles-Cathedral-Housing-Co-op&id=19','?project=Northern-Sustainable-House&id=12','?project=Fred-Douglas-Housing&id=134','?project=Rivergreen-Ecovillage&id=187'	],
	ProjectTitles: ['Place Joseph Royal Condominiums','Flora Place Housing','Parish Hall Condominiums','Greenheart Housing Co-op','Pulse on River Condominiums','Ship Street Condominiums','U of W Housing','Eco 4 Horace','Kestepnan Village Housing','Brandt Reid Residence','Thompson Senior Housing','Renaissance Station Condominiums','Thompson Residence','Eco Village Condominiums','Logan and Ellen Housing','Central Park Co-op','Artemis Housing','North Logan Housing','Atlas Brush Warehouse','Native Women\'s Transition Centre','McCormick\'s Factory Apartments','Weston Firehall Redevelopment','Charles Cathedral Housing Co-op','Northern Sustainable House','Fred Douglas Housing','Rivergreen Ecovillage'	],
	PageCount: 0,
	CurrentPage: 0,
	GetImage:function(i){
		if(this.Images[i])
			if(this.Projects.length>=i && this.Projects[i])
				return PageImage(this.Images[i],this.ImagePath,this.Projects[i],this.ProjectTitles[i]);
			else
				return PageImage(this.Images[i],this.ImagePath,false);
		return false;
	},
	DrawNavigation:function(){
		var sz="";
		if(isProject)
		{
			for(var i=0;i<this.Images.length;i++){
				sz += "<li class=\"image-button-"+(this.CurrentImage==i?"on":"off")+"\" id=\"ibtn"+i+"\" onClick=\"__sImg("+i+",this)\"><img src=\"/img-projects/categories/"+this.Thumbs[i]+"\"></li>";
			}
			sz = "<ol>"+sz+"</ol>";
    }
		else 
		{
			var leftover = this.Images.length % PerPage;
			this.PageCount = Math.ceil(this.Images.length / PerPage);
      sz += '<div id="nav-btns"><a id="prev-page" href="#"><img class="nav-btn"  src="img/left.gif"></a><a id="next-page" href="#"><img class="nav-btn" src="img/right.gif"></a></div>';
		}
		return sz?"<div id=\"image-button-container\">"+sz+"</div>":"";
	}
};
function PageImage(s,p,l,t){
	var oImg = {
		name: s,
		path:[p+"__"+s,p+s],
		getThumbPath:function(){return this.path[0];},
		getPath:function(){return this.path[1];},
		getLink:function(){return l;},
		getTitle:function(){return t;}
	};
	return oImg;
}



function findObj(theObj, theDoc){
	var p, i, foundObj;
	if(!theDoc) theDoc = document;
	if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)  {
		theDoc = parent.frames[theObj.substring(p+1)].document;
		theObj = theObj.substring(0,p);
	}
	if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
		for (i=0; !foundObj && i < theDoc.forms.length; i++) 
	foundObj = theDoc.forms[i][theObj];
	for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
		foundObj = findObj(theObj,theDoc.layers[i].document);
	if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
	return foundObj;
}

var PerPage = 6,
	isProjectCategory = true,  /* for project cat page...*/
	CurrentPage = 0,
	CurrentImage = 0,
	isProject = false;

/*document.write('Residential Architecture');*/