////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	// prepareExternalLinks()
	//
	//
	//
function prepareExternalLinks() {
	var links = document.getElementsByTagName("a");
	for(var i=0; i<links.length; i++) {
		var rel = links[i].getAttribute("rel");
		if(rel == "external") {
			links[i].setAttribute("target", "_blank");
		}
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	//removeConfirmations()
	//fadeElem(element)
	//
	//
function removeConfirmations() {
	var paras = document.getElementsByTagName("p");
	for(var i=0; i<paras.length; i++){
		if(paras[i].className == "confirm"){
			var feedback = paras[i];
			setTimeout(function() {new Effect.Fade(feedback);}, 4000);
		}
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	// hightLightPage()
	//
	//
	//
function highLightPage(elemId) {
	if(!document.getElementsByTagName) return false;
	if(!document.getElementById) return false;
	if(!document.getElementById(elemId)) return false;
	var nav = document.getElementById(elemId);
	var links = nav.getElementsByTagName("a");
	
	for(var i=0; i<links.length; i++) {
		if(links[i].getAttribute("href")) {
			var linkurl = links[i].getAttribute("href").toLowerCase();
			var currenturl = window.location.href.toLowerCase();
			if(currenturl.indexOf(linkurl) != -1) {
				addClass(links[i], 'here');
			}	
		}
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	// addClass()
	//
	//
	//
function addClass(element, value) {
	if(!element.className) {
		element.className = value;	
	}else{
		newClassName = element.className;
		newClassName+= " ";
		newClassName+= value;
		element.className = newClassName;
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	//smartInputs()
	//
	//
	//
function smartInputs() {
	var form = document.getElementById('infoForm');
	if(!form) return false;
	
	var errorClass;

	for(var i=0; i < form.elements.length; i++) {
		var element = form.elements[i];
		if (element.type == 'submit') continue;
		if (!element.defaultValue) continue;
		element.onfocus = function() {
			if(this.type == 'text') {
				if(this.value == this.defaultValue && this.value.indexOf("*") != -1) {
					this.value = "";
				}else if(this.value == this.defaultValue && this.className == 'optional'){
						this.value = "";
						}
			}else{
				if(this.value == this.defaultValue && this.className == 'optional') {
					this.value = "";
				}
			}
			if(this.className != '' && this.className != 'optional') {
				errorClass = this.className;
				this.className = '';
			}
		}
		element.onblur = function() {
			if(this.value == "") {
				this.value = this.defaultValue;
				if(this.className != 'optional') {
					this.className = errorClass;
				}
			}
		}
	}
}

function smartIndividualInput(theField) {
	var searchField = document.getElementById(theField);
	if(!searchField) return false;
	var defaultColor;
	var focusColor = "#505050";
	searchField.onfocus = function() {
		defaultColor = this.style.color;
		this.style.color = focusColor;
		if(this.value == this.defaultValue) {
			this.value = "";
		}
	}
	searchField.onblur = function() {
		this.style.color = defaultColor;
		if(this.value == "") {
			this.value = this.defaultValue;
		}
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	//displayLoading()
	//
	//
	//
function displayLoading(element) {
	var button = document.getElementById(element);
	button.setAttribute("value", "Sending...");
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	//prepareAjaxForms()
	//
	//
	//
function prepareAjaxForms() {
	if(document.getElementById('contactForm')) {
		var contactForm = document.getElementById('contactForm');
		var xhr = new Hijax();
		xhr.setContainer(contactForm);
		xhr.setUrl("contactForm.php");
		xhr.setCanvas(contactForm.parentNode);
		xhr.setLoading(function() {
			displayLoading("sendBtn");
		});
		xhr.setCallback(function() {
			prepareAjaxForms();
			removeConfirmations();
		});
		xhr.captureData();
	}
	
	if(document.getElementById('infoForm')) {
		var infoForm = document.getElementById('infoForm');
		var xhr = new Hijax();
		xhr.setContainer(infoForm);
		xhr.setUrl("quickContactForm.php");
		xhr.setCanvas(infoForm.parentNode);
		xhr.setLoading(function() {
			displayLoading("quickSubmitBtn");
		});
		xhr.setCallback(function() {
			prepareAjaxForms();
			removeConfirmations();
			smartInputs();
		});
		xhr.captureData();
	}
	
	if(document.getElementById('commentForm')) {
		var commentForm = document.getElementById('commentForm');
		var xhr = new Hijax();
		xhr.setContainer(commentForm);
		xhr.setUrl("blogCommentForm.php");
		xhr.setCanvas(commentForm.parentNode);
		xhr.setLoading(function() {
			displayLoading("sendBtn");
		});
		xhr.setCallback(function() {
			prepareAjaxForms();
			removeConfirmations();
		});
		xhr.captureData();
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	//writeFlashContent()
	//
	//
	//
function writeFlashContent(swfPath, embedId, version, backgroundColor, containerId, swfWidth, swfHeight, argName, argValue) {
	if(!document.getElementById) return false;

	var swfPath = swfPath;
	var embedId = embedId;
	var version = version;
	var backgroundColor = backgroundColor;
	var containerId = containerId;
	var swfWidth = swfWidth;
	var swfHeight = swfHeight;

	if(!document.getElementById(containerId)) return false;

	var swfContainer = document.getElementById(containerId);

	var so = new SWFObject(swfPath, embedId, swfWidth, swfHeight, version, backgroundColor);
	so.addParam("scale", "noscale");
	so.addParam("menu","false");
	so.addParam("salign", "tl");
	if(backgroundColor == 'transparent') {
		so.addParam("wmode", "transparent");
	}
	if(argName && argValue) {
		so.addVariable(argName, argValue);
	}
	so.write(swfContainer);	
}

////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	// fadeElem()
	//
	//
function fadeElem(element, speed, start, end) {
	 new Effect.Opacity(element, {duration:speed, from:start, to:end});
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	// topDrawer()
	//
	//
function topDrawer() {
	$('top_drawer').style.display = 'none';
	$('topDrawerContent').style.opacity = '0.0';
	
	$('top_drawer_handle').onclick = function() {
		if(this.className == '') {
			this.className = 'arrowUp';
			var startAlpha = 0.0;
			var endAlpha = 1;
		}else{
			this.className = '';
			var startAlpha = 1;
			var endAlpha = 0.0;
		}
		
		new Effect.toggle('top_drawer', 'slide', { 
            duration: 0.2, 
            queue: 'end', 
            afterFinish: (function(){ fadeElem('topDrawerContent', 0.5, startAlpha, endAlpha); }) 
        });
		
		return false;
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	//addLoadEvent()
	//
	//
	//
function addLoadEvent(func) {
	var oldonload = window.onload;
	if(typeof window.onload != 'function') {
		window.onload = func;
	}else{
		window.onload = function() {
			oldonload();
			func();
		}
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	//call functions on page load with addLoadEvent
	//
	//
	//
addLoadEvent(function(){
	prepareExternalLinks();
	writeFlashContent('http://www.digicraftproductions.com/swf/homeDemo.swf', 'demoReelSwf', '9.0.115', '#FFFFFF', 'demoReel', '596', '216');
	//lightboxCaptionLinks();
	smartInputs();
	smartIndividualInput('search');
	smartIndividualInput('updatesEmail');
	highLightPage('navMain');
	highLightPage('navSub');
	prepareAjaxForms();
});
