
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: ['46fa75a0b7dae.jpg','4714ddb063166.jpg','46e57512b467a.jpg','46e56c623ccac.jpg','4706a76f8cb4c.jpg','46dec519a63f0.jpg','47014ee957cb7.jpg','47014cbd4d540.jpg','4714d390b67ba.jpg','46e5781385da5.jpg','46e56fba73615.jpg','46fa7197eb524.jpg','4714e0d091dfd.jpg','46fd72df952d6.jpg','46fa7434362c8.jpg','46e572e3b7ef5.jpg','46fa75443c5e7.jpg','4714dfb6975bd.jpg','4703e5e2f3d7b.jpg','4714e15466251.jpg','4703e56bd87b1.jpg'],
	CurrentImage:0,
	ImagePath:"img-projects/categories/",
	Thumbs: [],
	Projects: ['?project=Bank-Of-Hamilton&id=18','?project=Weston-Firehall-Redevelopment&id=150','?project=McCormick\'s-Factory-Apartments&id=109','?project=Marshall-Wells-Warehouse&id=23','?project=Inglis-Grain-Elevators&id=22','?project=140-Bannatyne&id=101','?project=Verendrye-School-Roof-Restoration&id=161','?project=Earl-Grey-School-Roof-Restoration&id=160','?project=Crocus-Investment-Fund-Offices&id=20','?project=Ross-House-Museum&id=110','?project=Granite-Curling-Club&id=107','?project=Metropolitan-Theatre-Restoration&id=24','?project=Criterion-Hotel&id=105','?project=141-Bannatyne-Building&id=16','?project=Atlas-Brush-Warehouse&id=102','?project=Grey-Nuns-Museum&id=21','?project=Charles-Cathedral-Housing-Co-op&id=19','?project=Bedford-Building&id=103','?project=Pantages-Playhouse-Theatre&id=175','?project=Wilson-House-Redevelopment&id=147','?project=Metropolitan-Casino&id=178'	],
	ProjectTitles: ['Bank Of Hamilton','Weston Firehall Redevelopment','McCormick\'s Factory Apartments','Marshall Wells Warehouse','Inglis Grain Elevators','140 Bannatyne','Verendrye School Roof Restoration','Earl Grey School Roof Restoration','Crocus Investment Fund Offices','Ross House Museum','Granite Curling Club','Metropolitan Theatre Restoration','Criterion Hotel','141 Bannatyne Building','Atlas Brush Warehouse','Grey Nuns Museum','Charles Cathedral Housing Co-op','Bedford Building','Pantages Playhouse Theatre','Wilson House Redevelopment','Metropolitan Casino'	],
	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('Heritage Restoration');*/