// scripts for the Design by Angi Website

// CONSTANTS
var requiredFields = new Array("Your Name", "Email Address");
var imagesToPreload = new Array("images/arrow-left-ro.png", "images/arrow-right-ro.png", "send-ro.jpg", "shadowbox/close.png", "shadowbox/next.png", "shadowbox/pause.png", "shadowbox/play.png", "shadowbox/previous.png", "shadowbox/loading.gif", "creative_portfolio/calendar_girls_folio.jpg", "creative_portfolio/camino_downunder_folio.jpg", "creative_portfolio/care_super_folio.jpg", "creative_portfolio/david_campese_folio.jpg", "creative_portfolio/dirty_thirties_folio.jpg", "creative_portfolio/eyemuffs_folio.jpg", "creative_portfolio/floral_frenzy_folio.jpg", "creative_portfolio/fork_spoon_folio.jpg", "creative_portfolio/heart_foundation_folio.jpg", "creative_portfolio/hollywood_hammertime_folio.jpg", "creative_portfolio/ing_integra_super_folio.jpg", "creative_portfolio/logos_folio.jpg", "creative_portfolio/outsource_planning_folio.jpg", "creative_portfolio/paris_medispa_folio.jpg", "creative_portfolio/peter_doyle_folio.jpg", "creative_portfolio/prolux_electrical_folio.jpg", "creative_portfolio/red_cross_folio.jpg", "creative_portfolio/running_bare_folio.jpg", "creative_portfolio/spoil_folio.jpg", "creative_portfolio/superheroes_inc_folio.jpg", "creative_portfolio/surreal_jewellery_folio.jpg", "creative_portfolio/sydney_party_bus_folio.jpg", "creative_portfolio/transcendant_folio.jpg", "creative_portfolio/wirrilla_wine_folio.jpg");
var preloadedImages = new Array();

function preloadImages() {
	for (i=0; i<imagesToPreload.length; i++) {
		var tempImg = new Image;
		tempImg.src = imagesToPreload[i];
		preloadedImages.push(tempImg);
	}
}

// SCRIPTS FOR THE EMAIL FORM

function changeClass(elementID, newClass) {
	document.getElementById(elementID).className = newClass;
}


function checkRequiredFields(formIndex, fieldList) {
	/* the formIndex variable is a reference to which form is being checked (based on the form's position in the
	 * source page).  In most cases this will be 0, meaning that the first form on the page is the one being checked
	 * FieldList is used to identify which set of required fields to check for
	 */

	var missingFields = new Array(); // contains the names for any required fields that are still empty
	var completedFields = new Array();

	for (i=0; i<document.forms[formIndex].elements.length; i++) {
		
		if ((document.forms[formIndex].elements[i].type=="text")||(document.forms[formIndex].elements[i].type=="textarea")) {
			if ((document.forms[formIndex].elements[i].value!=null)&&(document.forms[formIndex].elements[i].value!=""))
			completedFields.push(document.forms[formIndex].elements[i].name);
		}
		if (document.forms[formIndex].elements[i].type=="radio") {
			if (document.forms[formIndex].elements[i].checked==true)
			completedFields.push(document.forms[formIndex].elements[i].name);
		}
		if (document.forms[formIndex].elements[i].type=="select-one") {
			if (document.forms[formIndex].elements[i].selectedIndex!=0)
			completedFields.push(document.forms[formIndex].elements[i].name);
		}		
	}
	
	// Use the list of completed fields to determine which required fields are missing
	if (completedFields.length==0) missingFields = requiredFields; // if nothing is filled in all are missing
	else {
		for (i=0; i<requiredFields.length; i++) {
			for (j=0; j<completedFields.length; j++) {
				if (requiredFields[i]==completedFields[j]) break;
				else if (j>=completedFields.length-1) missingFields.push(requiredFields[i])
			}
		}
	}
	
	// Build the neat list of missing fields and return it if required
	if (missingFields.length==0) { // all required fields are completed
		return true;
	}
	else {
		var responseMessage = "Please complete the following required fields:\n"
		for (i=0; i<missingFields.length; i++) {
			responseMessage = responseMessage + "- " + missingFields[i] + "\n";
		}
		alert(responseMessage);
		return false;
	}
}

// SCRIPTS FOR THE GALLERY

// increments for the sliding gallery pages, to determine how quickly to move pages
var distanceIncrement=0;
var timeIncrement=5;	

// vairables for tracking movement
var currentLocation=0;
var targetLocation=0;
var currentPage = 1;
var incrementer;

function gotoPage(page) {
	// if a new page has been selected, go to that page
	
	if (page!=currentPage) {
		switch (page) {
			case '1' :  document.getElementById('page1').style.textDecoration = "underline";
						document.getElementById('page2').style.textDecoration = "none";
						targetLocation = 0; // set the movement variables appropriately
						distanceIncrement = 25;
						curentLocation = -901;
						currentPage = 1;
			break;
			case '2' :  document.getElementById('page2').style.textDecoration = "underline";
						document.getElementById('page1').style.textDecoration = "none";
						targetLocation = -911; // set the movement variables appropriately
						distanceIncrement = -25;
						currentLocation = 0;
						currentPage = 2;
			break;
		}

		incrementer = setInterval("moveIt()",timeIncrement); // set an interval to effect the animation
	}
}

function moveIt() {
	if (((currentLocation<targetLocation)&&(distanceIncrement>0))||((currentLocation>targetLocation)&&(distanceIncrement<0))) {
		// if the movement is not yet complete, move the target div
		document.getElementById('portfolioOne').style.left = currentLocation + "px";
		document.getElementById('portfolioTwo').style.left = (currentLocation+911) + "px";
		currentLocation = currentLocation + distanceIncrement;
	}
	else {
		// ensure the div is in exactly the right place, and terminate the interval
		document.getElementById('portfolioOne').style.left = targetLocation + "px";
		document.getElementById('portfolioTwo').style.left = (targetLocation+911) + "px";	
		clearInterval(incrementer);
	}
}

function mouseOverArrow(itemId) {
	
	if ((itemId == "arrow-left")&&(currentPage!=1)) {
		document.getElementById(itemId).src = "images/arrow-left-ro.png";
		cursorToHand();
	}
	if ((itemId == "arrow-right")&&(currentPage!=2)) {
		document.getElementById(itemId).src = "images/arrow-right-ro.png";
		cursorToHand();
	}
}

function mouseOutArrow(itemId) {

	switch (itemId) {
		case 'arrow-left' :  document.getElementById(itemId).src = "images/arrow-left.png"; break;
		case 'arrow-right' :  document.getElementById(itemId).src = "images/arrow-right.png"; break;
	}
	cursorNotHand();
}

function cursorToHand() {
	document.body.style.cursor = "pointer"; // for Mozilla etc.
	document.body.style.cursor = "hand";	// for IE
}

function cursorNotHand() {
	document.body.style.cursor = "auto"; 	
}
function addBold(itemId) {
	document.getElementById(itemId).style.fontWeight = "bold";
}

function removeBold(itemId) {	
	document.getElementById(itemId).style.fontWeight = "normal";
}

function addBorder(imageId) {
	document.getElementById(imageId).style.border = "solid 2px #cccccc";
}
function removeBorder(imageId) {
	document.getElementById(imageId).style.border = "solid 2px #3d3d3d";
}

