// JavaScript Document

////// DEFINE GLOBALS
var targ;

var width;
		
var height;

var flag;

var myvis;

var newWidth = 0;

// WHENEVER USER CLICKS ON STAGE
document.onclick = checkEvent;
 
// CHECK TO SEE WHAT HAS BEEN CLICKED
function checkEvent(e) {

////// CHECK THE EVENT.TARGET

if (!e) { var e = window.event; }
	
if (e.srcElement) { targ = e.srcElement;} else if (e.target) { targ = e.target; }
	
if (targ.nodeType == 3) { targ = targ.parentNode; } // defeat Safari bug
	
		if ( targ.className == "image" ) { // ONLY HAPPENS IF YOU CLICK ON AN OBJECT 
											// WITH THE image CLASS
			
					width = targ.width  * 5 ; // THIS DEPENDS ON THE PROPORTION OF THE THUMBNAIL
						
					height = targ.height * 5 ; // CHANGE THIS NUMBER IF YOU WANT BIGGER
						
					desc = targ.alt; 	// CONTENTS OF THE ALT PROPERTY IN THE IMG TAG
										// USED TO STORE THE DESCRIPTION OF THE IMAGE
										
					src = targ.title; 	// CONTENTS OF THE NAME  PROPERTY IN THE IMG TAG
										// USED TO STORE THE SRC OF THE NEW IMAGE TO BE LOADED
					
					flag = true;		// IS THE BIG IMAGE BEING DISPLAYED OR NOT?
				
		controlDisplay(flag); 	// THIS IS WHAT HANDLES EVERYTHING AFTER THE USER HAS CLICKED ON 				
								// A THUMBNAIL DECLARING THE VALUE OF flag
		}

		if ( targ.className == "close" ) {	
		
			width = 10;
			
			height = 10;
			
			desc = " ";
			
			src = "img/transparent.gif";
			
			flag = false;
		
		controlDisplay(flag); 	// THIS IS WHAT HANDLES EVERYTHING AFTER THE USER HAS CLICKED ON 				
								// A THUMBNAIL DECLARING THE VALUE OF flag
		}

}

function updateSrc(desc, src) {

	document.getElementById('imagedisplay').src = src;
	
	document.getElementById('description').innerHTML = desc;
	
}

function updateVisibility(flag) {

	if (flag) { myvis = "visible"; } else { myvis = "hidden"; }

	document.getElementById('background').style.visibility = myvis;
		
	document.getElementById('container').style.visibility = myvis;

}


function controlDisplay(flag) {

	if ( flag == true ) {
					
					testIntervalId = setInterval ( "checkPlus()", 0.05 );
	}
	else {
					
					testIntervalId = setInterval ( "checkMinus()", 0.05 );
	}

}


	
function checkPlus() {

		updateVisibility(flag);
	
		var r = width/height;
			
		newWidth += 30; // GROWTH  SPEED
		
		newHeight = Math.round(newWidth / r);
	
		document.getElementById('background').style.opacity = newWidth / width / 4;
	
		transformDisplay(newWidth, newHeight);
	
	if (newHeight >= (height-10) && newWidth >= (width-10)) {
	
		clearInterval ( testIntervalId );
		
		newWidth = width;
		newHeight = height;
		
		updateSrc(desc, src);
		
	}

}

function checkMinus() {

		var r = width/height;
		
		newWidth -= 100;
		
		newHeight = Math.round(newWidth / r);
		
	transformDisplay(newWidth, newHeight);
		
	if (newWidth < 10) {
	
		clearInterval ( testIntervalId );
		
		newWidth = 0;
					
		flag = false;
					
		updateSrc(desc, src);
		
		updateVisibility(flag);
	
	}

}

function transformDisplay(newWidth, newHeight) {

		
		document.getElementById("display").style.opacity = newWidth / width;
		document.getElementById("imagedisplay").style.opacity = newWidth / width;
		document.getElementById("imagedisplay").style.width = newWidth + "px";
		document.getElementById("imagedisplay").style.height = newHeight + "px";


}

/////////////////////////////////////

function validate() {

var at = document.getElementById("correo").value.indexOf("@");

var dot = document.getElementById("correo").value.indexOf(".");

var sp = document.getElementById("correo").value.indexOf(" ");

var nameId=document.getElementById("name").value;

var emailId=document.getElementById("correo").value;

var subjectId=document.getElementById("subject").value;

var bodyId=document.getElementById("body").value;

flag = "true";

if (nameId.length<3) {
 alert("Please enter your name");
 flag="false";
 }
 
if (emailId.length<5) {
 alert("Please enter a valid email");
 flag="false";
 }
 
if (at==-1)  {
 alert("You forgot the @ in your email");
 flag="false";
 }
 
 if (dot==-1)  {
 alert("You forgot the . in your email");
 flag="false";
 }

 if (sp>-1)  {
 alert("You cannot have spaces in your email");
 flag="false";
 }
 
if (subjectId.length<3) {
 alert("Please enter a subject");
 flag="false";
 }
 
if (bodyId.length<3) {
 alert("Please enter a message");
 flag="false";
 }

if (flag=="false") {
 return false;
 } else {
 return true;
 }

}

