// initialise the arrays
/* Array of galleries holding the images and their dimensions*/

var showTitles=false;
var galleryPage="gallery.htm";
var browsePage="browse_gallery.htm";
var imageDir="g3_images";
var homePage="index.htm";
var galleries=new Array();

function Picture(width,height,title,description,type) {
    this.width=width;
    this.height=height;
    this.title=title;
    this.description=description;
    this.type=type;
    this.path=ignoreSpaces(this.title)+this.type;
    
    this.thumbHeight = 100;
    var ratio = this.width/this.height;
    this.thumbWidth = this.thumbHeight*ratio;
}

function Gallery(name,description){
	this.name=name;
	this.description=description;
	this.pictures = new Array(arguments.length-2);
 	for(i=0;i<arguments.length-2;i++){  
   		this.pictures[i] = arguments[i+2];
 	}

	this.getPictureIndex = function(name){
		for(var imgcount=0;imgcount<this.pictures.length;imgcount++){
                	if(name==this.pictures[imgcount].title){
                        	return imgcount;
                	}
        	}
		return 0;	
	};

	this.getPicture = function(name){
		return this.pictures[this.getPictureIndex(name)];
	};
	
	this.getURL = function(pic){
		return browsePage+"?gallery="+this.name+"&name="+pic.title;
	};

	this.getAdjacentURL = function(picName,offset){
		var index = this.getPictureIndex(picName) + offset;
		var loc="";
		if(index>=0 && index<this.pictures.length) 
			loc = this.getURL(this.pictures[index]);

		else loc = ""+galleryPage+"?name="+this.name;
		
		return loc;
	};
	
	this.getNextURL=function(name){
		return this.getAdjacentURL(name,1);
	};

	this.getPreviousURL=function(name){
		return this.getAdjacentURL(name,-1);
	};
}

galleries["Vector"] = new Gallery("Vector","Images drawn in Xara",
new Picture(824,821, "Wolf","",".jpg"),
new Picture(1052,800, "2001","",".jpg"),
new Picture(800,550, "Open the Doors","",".png"),
new Picture(738,768, "Detective","",".jpg"),
new Picture(699,768, "Player","",".jpg"),
new Picture(552,768, "Driver","",".jpg"),
new Picture(1024,583, "Dining Room","",".jpg"),
new Picture(1141,557, "Living","",".jpg"),
new Picture(1217,721, "Swimming Pool","",".JPG"),
new Picture(1024,870, "Lake","",".jpg"),
new Picture(1024,725, "Whitehall","",".jpg"),
new Picture(640,407, "Room 01","",".jpg"),
new Picture(861,788, "Room 02","",".jpg"),
new Picture(1101,755, "Room 03","",".jpg"),
new Picture(1150,683, "Sea View","",".jpg"),
new Picture(960,721, "Train","",".jpg"),
new Picture(960,827, "Boat","All drawn in Xara.",".jpg"),
new Picture(2565,524, "Living space","Line art in Xara. Scroll to see more >",".jpg"),
new Picture(1024,845, "Pool Game","",".jpg"),
new Picture(1024,769, "Mountain","Mount Rundle, Banff, Alberta",".jpg"),
new Picture(1169,850, "Portland","",".jpg"),
new Picture(700,992, "Bauer","",".jpg")
);
 
galleries["Paint"] = new Gallery("Paint","Digital Painting",
new Picture(514,600, "Spacebaby","",".jpg"),
new Picture(600,459, "Cityscape","",".png"),
new Picture(600,559, "Couch","",".JPG"),
new Picture(850,526, "Fence","",".jpg"),
new Picture(600,640, "Caine","",".png"),
new Picture(1024,500, "Dave","",".JPG"),
new Picture(543,768, "Duck in the Sun","",".JPG"),
new Picture(1500,700, "Female Buzzard","",".jpg"),
new Picture(800,600, "Gull","",".png"),
new Picture(1050,1036, "Magpie","",".jpg"),
new Picture(600,482, "Welsh Dragon","",".jpg"),
new Picture(960,960, "Town","",".jpg")
);
 
galleries["Sketchbook"] = new Gallery("Sketchbook","",
new Picture(620,574, "Beth","",".JPG"),
new Picture(588,455, "Dan","",".gif"),
new Picture(459,376, "Smoker","",".JPG"),
new Picture(1024,500, "Dude","",".JPG"),
new Picture(600,352, "Jacuzzi","",".jpg"),
new Picture(598,600, "Underwater","",".png"),
new Picture(600,450, "Shark","",".jpg"),
new Picture(600,548, "Patio","",".jpg"),
new Picture(600,450, "Blinding","",".JPG"),
new Picture(670,503, "Street","",".jpg"),
new Picture(600,334, "Train Interior","",".jpg")
);




//function to remove spaces to get image names
function ignoreSpaces(string) {
	string=string.replace(" ","_");
	string=string.replace(" ","_");
        string=string.replace(" ","_");
	return string;
}


//function to get the query which is passed to the present url
function getSearchAsArray() {
   // Browser-sniffing variables.
   var minNav3 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 3);
   var minIE4 = (navigator.appName.indexOf("Microsoft") >= 0 && parseInt(navigator.appVersion) >= 4);
   var minDOM = minNav3 || minIE4   // Baseline DOM required  for this function

   // Initialize array to be returned.
   var results = new Array();
  if (minDOM) {
      // Unescape and strip away leading question mark.
      var input = unescape(location.search.substring(1));
      if (input) {
         // Divide long string into array of name/value pairs.
         var srchArray = input.split("&");
         var tempArray = new Array();
         for (i = 0; i < srchArray.length; i++) {
            // Divide each name/value pair temporarily into a two-entry array.
            tempArray = srchArray[i].split("=");
            // Use temp array values as index identifier and value.
            results[tempArray[0]] = tempArray[1];
         }
      }
   }
   return results
}

function imageTable(gallery){
      	var pics = gallery.pictures;
	var cols=7;
	var index=0;
	for(var i=0;index<pics.length;i++){
		document.writeln("<table cellpadding=3 cellspacing=0><tr>");
		for(var c=0;(c<cols && index<pics.length);index++,c++){
                	filename=pics[index].title;
			document.writeln("<td align=\"left\" valign=\"top\" height=\"100\" >");
                	document.writeln("<a href=\""+browsePage+"?"
                                	+"gallery="+escape(gallery.name)
					+"&name="+escape(filename)+"\""
				+" name=\""+escape(filename)+"\""
				+ ">");
                	document.writeln("<image src=\""+imageDir+"/"+ignoreSpaces(pics[index].title)+"_small"+pics[index].type+"\""
				+" border=\"0\" height=\""+pics[index].thumbHeight+"\""
				+" alt=\""+filename+"\""
				+" id=\""+filename+"\""	
				+">");
                	document.writeln("</a>");
                	document.writeln("</td>");
             }
	       document.writeln("</tr></table>");
	}
}


function scrollToElement(el_id){
	//for NS/Mozilla/FireFox
	scrollTo(document.getElementById(el_id).x,document.getElementById(el_id).y);
	//for MSIEx
	document.getElementById(el_id).scrollIntoView();
}
