
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: ['4baa804b93f1e.jpg','4baa12af3004e.jpg','4baa43886545d.jpg','46efea161b965.jpg','46efeb53834c1.jpg','46f97a9d76c54.jpg','4706a2071629f.jpg','46efe83e12a9f.jpg','46fd7553c9c4a.jpg','48ff976f97ea9.jpg','4714ddb063166.jpg','4706a0d1b052a.jpg','471643504007a.jpg','46efe8c142caf.jpg','4703ecc497709.jpg','470d01a0643b1.jpg','46e5781385da5.jpg','46e572e3b7ef5.jpg','4ba929c32a9f6.jpg','46efeeb1f0284.jpg','46efec6a5d8aa.jpg','471638ba00a62.jpg','4714e15466251.jpg','47040faf920e2.jpg','4703e4eac0fdd.jpg','41ae288776136.jpg','4703e4b82b481.jpg','4701530325806.jpg'],
	CurrentImage:0,
	ImagePath:"img-projects/categories/",
	Thumbs: [],
	Projects: ['?project=UWSA-Daycare&id=179','?project=West-End-Cultral-Centre&id=65','?project=River-Avenue-Daycare&id=156','?project=Manitoba-Theatre-For-Young-People&id=36','?project=Red-River-Community-Centre&id=63','?project=Eco-Village-Condominiums&id=7','?project=Lake-of-the-Woods-Museum&id=35','?project=Crossways-Community-Centre&id=31','?project=Ignance-Regional-Travel-Centre&id=55','?project=Unitarian-Church-Redevelopment&id=38','?project=Weston-Firehall-Redevelopment&id=150','?project=Church-of-the-Open-Door&id=81','?project=U-of-W-Spence-St.-Redevelopment&id=87','?project=Fraserwood-Community-Hall&id=32','?project=Kenora-Public-Library&id=34','?project=Manitoba-Development-Centre&id=83','?project=Ross-House-Museum&id=110','?project=Grey-Nuns-Museum&id=21','?project=U-of-W-Housing&id=151','?project=Westminster-Community-Square&id=88','?project=Habitat-for-Humanity-in-Pt-Douglas&id=82','?project=U-of-W-Development-Plan&id=93','?project=Wilson-House-Redevelopment&id=147','?project=Norway-House-Community-Centre&id=28','?project=Powerhouse-Youth-Village&id=176','?project=Manitoba-Children\'s-Museum&id=3','?project=MacDonald-Youth-Services&id=174','?project=North-YMCA-Community-Centre&id=155'	],
	ProjectTitles: ['UWSA Daycare','West End Cultral Centre','River Avenue Daycare','Manitoba Theatre For Young People','Red River Community Centre','Eco Village Condominiums','Lake of the Woods Museum','Crossways Community Centre','Ignance Regional Travel Centre','Unitarian Church Redevelopment','Weston Firehall Redevelopment','Church of the Open Door','U of W Spence St. Redevelopment','Fraserwood Community Hall','Kenora Public Library','Manitoba Development Centre','Ross House Museum','Grey Nuns Museum','U of W Housing','Westminster Community Square','Habitat for Humanity in Pt Douglas','U of W Development Plan','Wilson House Redevelopment','Norway House Community Centre','Powerhouse Youth Village','Manitoba Children\'s Museum','MacDonald Youth Services','North YMCA Community Centre'	],
	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('Community Building');*/