function clearText(element){
	if(element.value == 'Name' || element.value == 'email@example.com') element.value = '';	
}
function rand( min, max ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Leslie Hoare
    // *     example 1: rand(1, 1);
    // *     returns 1: 1
 
    if( max ) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    } else {
        return Math.floor(Math.random() * (min + 1));
    }
}
function Gallery() {

	this.arrImages = Array();
	this.currentImg = 0;
	this.noImages = 0;
	
	this.registerImage = function( strFile, 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 = intImageNo;
		this.fixHeight();

	}

	this.prevImage = function() {


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

	}

	this.nextImage = function() {

		if( this.currentImg == (this.noImages-1) ) {
			this.currentImg = 0;
		} else {
			this.currentImg++;
		}
		
		this.switchGallery( this.currentImg );

	}
	
	this.fixHeight = function() {
	
		objBigImg = document.getElementById('main_gallery_image');
		
		intH = objBigImg.offsetHeight;
		
		//objBigImg.style.top = "50%";
		objBigImg.style.marginTop = "-"+(intH/2)+"px";
		
		//alert(objBigImg.offsetHeight+' fixed: '+objBigImg.style.marginTop);
	}

}

objGallery = new Gallery();


function submitContact( objRef ) {
	
	strRef = ( typeof( objRef ) != 'object' ) ? objRef : objRef.id;
	objRef = ( typeof( objRef ) != 'object' ) ? document.getElementById(objRef) : 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;
      	
   	}
   	
   	
	setTimeout("doSubmit('"+strRef+"');", 50);

}

function doSubmit( ref ) {
	document.getElementById(ref).submit();
}
function checkSignup( objRef ) {
	name = objRef.name.value;
	email = objRef.email.value;
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	
	if( name == '' || name == 'Your Name' || email == '' || email == 'Your Email' ) {
		alert( "Please fill out your name and e-mail address" );
		return false;
	}


	if(reg.test(email) == false) {
   			
      	alert('Please supply a valid e-mail address.');
      	return false;
      	
   	}
   	
	strRef = ( typeof( objRef ) != 'object' ) ? objRef : objRef.id;
	setTimeout("doSubmit('"+strRef+"');", 50);
}

function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}

