Array.prototype.findIndex = function(value){
	var ctr = "";
	for (var i=0; i < this.length; i++) {
		// use === to check for Matches. ie., identical (===), ;
		if (this[i] == value) {
			return i;
		}
	}
	return ctr;
};

function Gallery() {

	this.arrImages = Array();
	this.arrImagesNo = Array();
	this.currentImg = 0;
	this.noImages = 0;
	
	this.registerImage = function( strFile, intImageNo ) {
		this.arrImagesNo.push(intImageNo);
		this.arrImages[intImageNo] = strFile;
		this.noImages++;
	}

	this.switchGallery = function( intImageNo ) {

		// get image elements		
		objMainImg = document.getElementById('main_gallery_image');
		strNewImage = this.arrImages[intImageNo];
	
		// split new url with original filename on the end
		var arrTmp = objMainImg.src.split("\/l_");
	
		// change file to large copy
		arrTmp[arrTmp.length-1] = "l_"+strNewImage;
	
		// join source back together
		strTmp = arrTmp.join("/");

		// switch image
		objMainImg.src = strTmp;
		this.currentImg = this.arrImagesNo.findIndex(intImageNo);
		//this.currentImg = intImageNo;
		this.fixHeight();

	}

	this.prevImage = function() {


		if( this.currentImg == 0 ) this.currentImg = this.noImages;
		
		this.currentImg--;
		
		this.switchGallery( this.arrImagesNo[this.currentImg] );

	}

	this.nextImage = function() {
		if( this.currentImg == (this.noImages-1) ) {
			this.currentImg = 0;
		} else {
			this.currentImg++;
		}
		this.switchGallery( this.arrImagesNo[this.currentImg] );

	}
	
	this.fixHeight = function() {
	
		objBigImg = document.getElementById('main_gallery_image');
		
		intH = objBigImg.offsetHeight;

		objBigImg.style.top = "50%";
		objBigImg.style.marginTop = "-"+(intH/2)+"px";
		
	}

}

objGallery = new Gallery();

function submitContact( objRef ) {

	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	
	strName = objRef.name.value;
	strEmail = objRef.email.value;
	strPhone = objRef.phone.value;

	if( strName == '' ) {
		alert( "Please fill out your name." );
		return;
	}
	
	if( strEmail == '' && strPhone == '' ) {
		alert( "Please fill out either your e-mail address, or phone number." );
		return;
	}

	if(strPhone == '' && (reg.test(strEmail) == false)) {
   			
      	alert('Please supply a valid e-mail address.');
      	return;
      	
   	}
   	
   	objRef.submit();
    //return true;

}
