// JavaScript Document

// WORK POST FUNCTIONS
function openThumbs(){
	var h = (108 * thumbRows) + ((thumbRows-1) * 20);
	$("#work-post-thumbs").animate({ 
        height: h +"px"
      }, 1000 );
}

function closeThumbs(){
	$("#work-post-thumbs").animate({ 
        height: "108px"
      }, 1000 );
}


function FlashInterface($swfObjectName){
	this.swfName 			= $swfObjectName;
	this.swf 				= this.getSwf(this.swfName);
	this.currentImage		= 0;
	this.previousImage 		= -1;
}

FlashInterface.prototype.imageClick = function($id){
	if(this.currentImage != $id){
		this.previousImage = this.currentImage;
		this.currentImage = $id;
		if(this.swf.imageClick){
			this.swf.imageClick($id);
		}
	}
}

FlashInterface.prototype.resizePlayer = function ($height){
	this.swf.style.height = $height + 'px';
	var div = document.getElementById("flash-holder");
	div.style.height = $height + 'px';
}

FlashInterface.prototype.flashUpdate = function ($imageIndex){
	
	if(this.currentImage != $imageIndex){
		this.previousImage = this.currentImage;
		this.currentImage = $imageIndex;
	}
	//alert("flashUpdate currentImage: " + this.currentImage + " previous: " + this.previousImage);
	$("#thumb-" + this.currentImage).css("background","#F60");
	$("#thumb-" + this.previousImage).css("background","#FFF");
}

FlashInterface.prototype.getSwf = function(id) {
	
	var obj;
	if (navigator.appName.indexOf("Microsoft") != -1)
		obj = window[id];
	 else 
		obj = document[id];
	
	if(obj == undefined)
		return null;
	 else 
		return obj;
}    


// CONTACT FUNCTIONS

function validateContactForm() {
	
	var name = $("#contactName").val();
	var email = $("#contactEmail").val();
	var txt = $("#contactText").val();
	var message = "";
	if (!checkEmailValidation(email) || email.length == 0) message += "Please enter a valid email address.<br />";
	if(name == "") message += "Please enter a your name.<br />";
	if(txt == "") message += "Please enter a message.<br />";
	if(message.length > 0){
		var errorSpan = $("#error");
		if(errorSpan) errorSpan.remove();
		$("#send-button").before("<span class=\"error\" id=\"error\">" + message + "<br /><br /></span>");
		return false;
	} else {
		return true;
	}
}

function checkEmailValidation(e) {
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

	for(i=0; i < e.length ;i++){
		if(ok.indexOf(e.charAt(i))<0){ 
			return (false);
		}	
	} 
	
	if (document.images) {
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) {
			return (-1);		
		} 
	}
}

