
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: ['48e3efa8ded0a.jpg','46fd287480f72.jpg','4a2171c072d50.jpg','4bc71bdf3be5a.jpg','4a215f19c77fd.jpg','48ebc4358512c.jpg','4bab5edd27c97.jpg','4ba929c32a9f6.jpg','48f664b005383.jpg','4900a70b1d0ac.jpg','471638ba00a62.jpg','46effd2815619.jpg','46f97a4fa318f.jpg','46f97a9d76c54.jpg','471521069a96f.jpg','470cf69fd7790.jpg','46dda42c86e8f.jpg','46f97d3862eae.jpg','46c1cc766e87a.jpg','4713e2c5d51b0.jpg','4714ddb063166.jpg','47e7e2309d42d.jpg','46efeeb1f0284.jpg','46fa7db0673b6.jpg','46fa8972bcb91.jpg','46f01546809fb.jpg','41ae288776136.jpg','47014522e0852.jpg','470500ae49e78.jpg','47040faf920e2.jpg','4a2165493f254.jpg','4baa12af3004e.jpg','47014cbd4d540.jpg'],
	CurrentImage:0,
	ImagePath:"img-projects/categories/",
	Thumbs: [],
	Projects: ['?project=Aboriginal-Student-Centre&id=96','?project=Mountain-Equipment-Co-op&id=15','?project=Churchil-Northern-Studies-Centre&id=186','?project=Manitoba-Hydro-Downtown-Offices&id=75','?project=Rivergreen-Ecovillage&id=187','?project=Qualico-Winnipeg&id=152','?project=Greenheart-Housing-Co-op&id=135','?project=U-of-W-Housing&id=151','?project=Swan-Valley-Credit-Union-&id=62','?project=Duck-Mountain-Solar-Washrooms&id=182','?project=U-of-W-Development-Plan&id=93','?project=Entegra-Credit-Union-&id=78','?project=Eco-4-Horace&id=73','?project=Eco-Village-Condominiums&id=7','?project=ec:0&id=66','?project=Winnipeg-Airport-Authority&id=166','?project=Sioux-Lookout-Elementary-School&id=14','?project=Wahbung-Abinoonjiiag&id=4','?project=Roseau-Children’s-Centre&id=8','?project=Northern-Sustainable-House&id=12','?project=Weston-Firehall-Redevelopment&id=150','?project=Maskwa-Community-Building&id=10','?project=Westminster-Community-Square&id=88','?project=Mishkeegogamang-School&id=27','?project=Parish-Hall-Condominiums&id=154','?project=Dryden-Elementary-School&id=6','?project=Manitoba-Children\'s-Museum&id=3','?project=MB-Hydro-Customer-Facility&id=167','?project=Kestepnan-Village-Housing&id=169','?project=Norway-House-Community-Centre&id=28','?project=OPCN-Community-Health-Facility&id=188','?project=West-End-Cultral-Centre&id=65','?project=Earl-Grey-School-Roof-Restoration&id=160'	],
	ProjectTitles: ['Aboriginal Student Centre','Mountain Equipment Co-op','Churchil Northern Studies Centre','Manitoba Hydro Downtown Offices','Rivergreen Ecovillage','Qualico Winnipeg','Greenheart Housing Co-op','U of W Housing','Swan Valley Credit Union ','Duck Mountain Solar Washrooms','U of W Development Plan','Entegra Credit Union ','Eco 4 Horace','Eco Village Condominiums','ec:0','Winnipeg Airport Authority','Sioux Lookout Elementary School','Wahbung Abinoonjiiag','Roseau Children’s Centre','Northern Sustainable House','Weston Firehall Redevelopment','Maskwa Community Building','Westminster Community Square','Mishkeegogamang School','Parish Hall Condominiums','Dryden Elementary School','Manitoba Children\'s Museum','MB Hydro Customer Facility','Kestepnan Village Housing','Norway House Community Centre','OPCN Community Health Facility','West End Cultral Centre','Earl Grey School Roof Restoration'	],
	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('Sustainable  Architecture');*/