
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: ['46fd287480f72.jpg','492ef69d8dcce.jpg','4bc71bdf3be5a.jpg','48ebc4358512c.jpg','48f664b005383.jpg','46effd2815619.jpg','48ffa19f1eb5d.jpg','4714cc37b9654.jpg','4714d390b67ba.jpg','46effa4f9d2d3.jpg','46eff952dbe3b.jpg','46effbd0b8757.jpg','46effc5259d22.jpg','46fd2d7c03d94.jpg','46fa75a0b7dae.jpg','46dec519a63f0.jpg'],
	CurrentImage:0,
	ImagePath:"img-projects/categories/",
	Thumbs: [],
	Projects: ['?project=Mountain-Equipment-Co-op&id=15','?project=National-Screen-Institute&id=183','?project=Manitoba-Hydro-Downtown-Offices&id=75','?project=Qualico-Winnipeg&id=152','?project=Swan-Valley-Credit-Union-&id=62','?project=Entegra-Credit-Union-&id=78','?project=SOMA-Cafe&id=181','?project=A-Channel-Television-Studios&id=49','?project=Crocus-Investment-Fund-Offices&id=20','?project=McNally-Robinson-Bookstores&id=51','?project=Holy-Spirit-Credit-Union&id=50','?project=South-Interlake-Credit-Union&id=52','?project=UFCW-Union-Office&id=53','?project=MB-Conservatory-of-Music-&-Arts&id=69','?project=Bank-Of-Hamilton&id=18','?project=140-Bannatyne&id=101'	],
	ProjectTitles: ['Mountain Equipment Co-op','National Screen Institute','Manitoba Hydro Downtown Offices','Qualico Winnipeg','Swan Valley Credit Union ','Entegra Credit Union ','SOMA Cafe','A Channel Television Studios','Crocus Investment Fund Offices','McNally Robinson Bookstores','Holy Spirit Credit Union','South Interlake Credit Union','UFCW Union Office','MB Conservatory of Music & Arts','Bank Of Hamilton','140 Bannatyne'	],
	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('Commercial Architecture');*/