
//******** Preload Nav Link Hover States ***********************************************************************

////////// Preloads Images Funtion
/*	$directory is the absolute path to the images.	$imagesA is an
	array literal: ['img1','img2',...]. The image names are extensionless.
*/
/*function preload($directory, $imagesA){	
	for(n=0; n<$imagesA.length; n++){
		(new Image()).src = $directory + $imagesA[n] + '.jpg';
		return 1;
		}
	}

preload('/images/', ['_about_hover', '_services_hover', '_portfolio_hover', '_contact_hover']);*/

	function preload_plus_beta() { 
		/**/$dir = '/images/';
		
		$a = (new Image());
		$a.src = $dir+'_about_hover.jpg';

		$b = (new Image());
		$b.src = $dir+'_services_hover.jpg';

		$c = (new Image());
		$c.src = $dir+'_portfolio_hover.jpg';

		$d = (new Image());
		$d.src = $dir+'_contact_hover.jpg';

		
		$i1 = (new Image());
		$i1.src = $dir+'icon_apps.jpg';

		$i2 = (new Image());
		$i2.src = $dir+'icon_contact.jpg';

		$i3 = (new Image());
		$i3.src = $dir+'icon_print.jpg';

		$i4 = (new Image());
		$i4.src = $dir+'icon_programming.jpg';
		
		$i5 = (new Image());
		$i5.src = $dir+'icon_registration.jpg';

		$i6 = (new Image());
		$i6.src = $dir+'icon_webdesign.jpg';

		$i7 = (new Image());
		$i7.src = $dir+'icon_wbstandards.jpg';


		$bo = (new Image());
		$bo.src = $dir+'bullet_orange.jpg';

		$bg = (new Image());
		$bg.src = $dir+'bullet_grey.jpg';

	}


//******** Portfolio Screenshot Functions ***********************************************************************

////////// Set active/inactive colors for thumb borders and set site names.
var $aColr = '#c8c8c8';
var $iColr = '#8d8d8d';
var $sites = ['healthbasic', 'eclecticboogie', 'sigmatutoring', 'mirandas', 'schwartz', 'fpizza'];


////////// Preload screenshots
function preScreenshots() {
	var $drctry = '';

	for($u=0; $u<$sites.length; $u++){
		for($v=2; $v<=4; $v++){
			(new Image()).src = $drctry + $sites[$u] + $v +'.jpg';
	}	}	}


////////// Generic rollover function for image borders.
function imgBorderRollover($ivar,$in,$out){
	if($ivar){
		function HOV(){$ivar.style.borderColor = $in}
		function OUT(){$ivar.style.borderColor = $out}
		$ivar.onmouseover = HOV;
		$ivar.onmouseout = OUT;
	}	}


////////// Sets thumbnail hover states on thumbs 2,3,4 of each site.
        // (Needed because IE does not support non-<a> tag hover states).
		// First thumb is styled to static state with css.
function setRollovers(){
	for($p=0; $p<$sites.length; $p++){
		for($k=2; $k<=4; $k++){
			if($thumbs = document.getElementById($sites[$p]+$k)) {
				imgBorderRollover($thumbs.firstChild, $aColr, $iColr);
	}	}	}	}


////////// Sets active/inactive img border hover states and replaces main screenshot.
function rotate($site,$num) {

	var $a = document.getElementById($site+$num);
	$a.removeAttribute('href');  // Disbles hover 'hand' effect.
	imgBorderRollover($a.firstChild,$iColr,$iColr);  // Fixes border to 'inactive' color.
	$a.firstChild.style.borderColor = $iColr;  // Imediately resets active border to 'inactive' color.
											   // Otherwise hover 'lingers'.
	////////// 'Enables' rest of thumbs.
	for ($n=1; $n<=4; $n++){
		if ($n != $num) {
			var $b = document.getElementById($site+$n);
			$b.setAttribute('href','#');
			$b.firstChild.style.borderColor = $iColr;  // Resets border colors to inactive.
			imgBorderRollover($b.firstChild,$aColr,$iColr);
		}	}

	////////// Image Replacement Function (Stripped Down Generic Version)
	function img_replace($imgId, $rplcmnt){     // $rplcmnt must contain full absolute path to image
		$image  = document.getElementById($imgId);
		$image.src = $rplcmnt; return false;
		}
	img_replace($site+'_screenshot', $site+$num+'.jpg');
	}


//******** Print Sample Enlarge Script ***********************************************************************\

function enlarge($img, $width, $height) {
	$hyte = document.documentElement.clientHeight;

		// This element must be created becase IE6 does not support
		// the neccessary setAttributes. innerHTML must be used instead.
	$enlarg = document.createElement('div');
	$enlarg.setAttribute('id', 'enlarge');
	$enlarg.innerHTML = '<div id="mask" style="height: '+$hyte+'px;"></div>'+
						'<div id="image_container" style="width:'+$width+'px; height:'+$height+'px;'+
								'margin-top: -'+($height/2)+'px; margin-left:-'+($width/2)+'px;">'+
						'<a href="#" onclick="erase(); return false;" title="click to close"><img src="'+$img+'.jpg" /></a></div>';
	document.body.appendChild($enlarg);
}

function erase() {
	$enlarge = document.getElementById('enlarge');
	document.body.removeChild($enlarge);
	return false;
}

function rsze() {
	$hyte = document.documentElement.clientHeight;
	$mask = document.getElementById('mask');
	$mask.style.height = $hyte;
}

window.onresize = rsze;


//******** Contact Form Validation *****************************************************************************

////////// Generic Form Validation
function validate(){

		function check(){
		for (i=0; i<document.forms[0].elements.length; i++){
			if(!document.forms[0].elements[i].value){
				alert('please fill in all fields.');
				return false;
				}
			}
		return true
		}
	document.forms[0].onsubmit = check;
	}



//***************************************************************************************************************

function set() {
	if (document.getElementById('portfolio')){
		setRollovers();
		preScreenshots();
		}
	

	if (document.getElementById('contact')){
		validate();
		}

	preload_plus_beta();
	}


window.onload = set;