
// This is extracted from cubicles.js and contains ONLY what's needed for the videos section.

preloadImages();

// Load just the navs.
function preloadImages() {
	if (document.images) {
		var bg					= new Image();
		var cubicles			= new Image();
		var office_furniture	= new Image();
		var about_us			= new Image();
		var our_process			= new Image();
		var green_office		= new Image();
		var blog				= new Image();
		var contact_us			= new Image();
		var imgObj = new Array (bg,cubicles,office_furniture,about_us,our_process,green_office,blog,contact_us);
		var imgs = new Array ('/images/DaSliva.jpg','/images/cubicles-nav.jpg','/images/office-furniture-nav.jpg','/images/about-us-nav.jpg','/images/our-process-nav.jpg','/images/green-office-nav.jpg','/images/blog-nav.jpg','/images/contact-us-nav.jpg');
		var imgName;
		for (i=0;i<imgs.length;i++) {
			imgName = imgs[i];
			imgObj[i].src=imgName;
		}
	}
}

// Uses SWFObject to load main page video, 03-30-10
// Be sure to include swfobject.js FIRST in source code.

window.onload=function() { 
	loadVideo(); 
	attachBehaviors();
};

function loadVideo() {

	var vids = {
		'intro-video':	'\/about\/videos\/flv\/intro.flv',
		'ch2-video':	'\/about\/videos\/flv\/ch2.flv',
		'ch3-video':	'\/about\/videos\/flv\/ch3.flv',
		'ch4-video':	'\/about\/videos\/flv\/ch4.flv',
		'ch5-video':	'\/about\/videos\/flv\/ch5.flv',
		'ch6-video':	'\/about\/videos\/flv\/ch6.flv',
		'ch7-video':	'\/about\/videos\/flv\/ch7.flv',
		'ch8-video':	'\/about\/videos\/flv\/ch8.flv'
	};
	var imgs = {
		'intro-video':		'\/about\/videos\/images\/intro-video-intro.gif',
		'ch2-video':		'\/about\/videos\/images\/ch2-intro.gif',
		'ch3-video':		'\/about\/videos\/images\/ch3-intro.gif',
		'ch4-video':		'\/about\/videos\/images\/ch4-intro.gif',
		'ch5-video':		'\/about\/videos\/images\/ch5-intro.gif',
		'ch6-video':		'\/about\/videos\/images\/ch6-intro.gif',
		'ch7-video':		'\/about\/videos\/images\/ch7-intro.gif',
		'ch8-video':		'\/about\/videos\/images\/ch8-intro.gif'
	};
	var w = 400;
	var h = 320;
	for (key in vids) {
		if (document.getElementById(key)) {
			var sdvideo = new SWFObject('\/about\/videos\/player.swf', 'z-vid', w, h, '9', '#ffffff'); 
			sdvideo.addParam("wmode", "transparent");
			sdvideo.addParam("menu", "false");
			sdvideo.addVariable("file", vids[key]);
			sdvideo.addVariable("size", "false");
			sdvideo.addVariable("aplay", "false");
			sdvideo.addVariable("autorew", "false");
			// Only IE needs these two
			sdvideo.addVariable("width", w);
			sdvideo.addVariable("height", h);
			sdvideo.addVariable("image", imgs[key]);
			sdvideo.addVariable("title", "");
			sdvideo.write(key);
		}
	}
}

function attachBehaviors() {
	var minFields = Array ('cname','cphone','cemail');
	for (i=0;i<minFields.length;i++) {
		if (document.getElementById(minFields[i])) {
			document.getElementById(minFields[i]).onfocus=function() { clearText(this); }
			document.getElementById(minFields[i]).onblur=function() { replaceText(this); }
		}
	}
	if (document.getElementById('Mail_ActionPage_FormResponse')) {
		document.getElementById('Mail_ActionPage_FormResponse').onsubmit= function() { return validateSmallForm(this); }
	}
}

// the main page form is different than the mini's and contact form, but at this point only email is required for both
function validateSmallForm(form) {
	if (form.email) {
		var regex = /.*\@.*[.].*/;
		if (regex.test(form.email.value)) { return true; }
		else { 
			alert('Please enter a valid email address\n in the form account-name@example.com.');
			return false;
		}
	}
	return true;
}

// These two were loaded ABOVE the main page contact form. As of this mod,
// not sure if they apply to any other pages.
function check_cdfs(form) { return true; }
function doSubmit() {
	if (check_cdfs(document.survey)) {
		var day = newDate();
		var id=day.getTime();
		open('',id,'resizable,scrollbars,width=300,height=150');
		return true;
	}
	else { return false; }
}

// For mini forms which have no visible labels
function clearText(thefield) {  
	if (thefield.defaultValue==thefield.value) { thefield.value = ""; }
}
function replaceText(thefield) {
	if (thefield.value=="") { thefield.value = thefield.defaultValue; }
}

