var RecaptchaOptions = {
	theme : 'clean'
}

$(document).ready( function( ) {
	var slides = document.getElementById("index-slides");
	if ( slides ) {
		var divs = slides.getElementsByTagName("div");
		var j = 0;
		var h = "";
		var img = ""
		for ( var i = 0; i < divs.length; i++ ) {
			if ( $(divs[i]).hasClass("row") ) {
				index.rows[j] = divs[i];
				img = divs[i].getElementsByTagName("img");
				index.imgs[i] = new Image();
				index.counter(1);
				index.rows[j].style.display = "none";
				if ( $(index.rows[j++]).hasClass("row-0000") != -1 ) {
					$(index.imgs[i]).load(function(){index.counter(-1);$(".row-0000").fadeIn(2000)});
				} else {
					$(index.imgs[i]).load(function(){index.counter(-1)});
				}
				index.imgs[i].src = img[0].src;
				h = ((h>img[0].height)?(h):(img[0].height));
			}
		}
	}
	var portfolioSlides = document.getElementById("portfolio-slides");
	if ( portfolioSlides ) {
		portfolio.init();
	}
	var whoWeAre = document.getElementById("bios");
	if ( whoWeAre ) {
		bios.init();
	}
	var rec = document.getElementById("recognition");
	if ( rec ) {
		recognition.init();
	}
	var empl = document.getElementById("employment");
	if ( empl ) {
		employment.init();
	}
	$("a").hover(function(){
			allpages.titleAttr = $(this).attr("title");
			$(this).attr("title","");
		},
		function(){
			$(this).attr("title",allpages.titleAttr);
		});
	$("img").hover(function(){
			allpages.altAttr = $(this).attr("alt");
			$(this).attr("alt","");
		},
		function(){
			$(this).attr("alt",allpages.altAttr);
		});
});

var allpages = {
	titleAttr : "",
	altAttr : ""
}

var employment = {
	init : function () {
		$("#employment").height($("#marquee").height());
		$("#employ_link").click(function(){
			$("#employment").fadeIn(1000);
			return false;
		});
		$("#closer a").click(function(){
			$("#employment").fadeOut(1000);
			return false;
		});
	}
}

var recognition = {
	init : function () {
		$("#sub_nav a").slice(0,1).click(function () {
			$("#recognition").fadeIn(1000);
			$("#awards").fadeOut(1000);
			$("#sub_nav a").slice(0,1).addClass("current");
			$("#sub_nav a").slice(1,2).removeClass();
			return false;
		});
		$("#sub_nav a").slice(1,2).click(function () {
			$("#awards").fadeIn(1000);
			$("#recognition").fadeOut(1000);
			$("#sub_nav a").slice(1,2).addClass("current");
			$("#sub_nav a").slice(0,1).removeClass();
			return false;
		});
	}
}

var bios = {
	lastBio : false,
	init : function ( ) {
		var marqueeH = $("#marquee").height();
		$("#bios").height(marqueeH);
		$(".bio").height(marqueeH);
		$("#staff a").each(function (i) {
			this.onclick = new Function( "return bios.showBio(" + i + ")" );
		});
		$(".closer").click(function(){
			$(".bio").slice(bios.lastBio,bios.lastBio+1).fadeOut(1000);
			bios.lastBio = false;
			return false;
		});
	},
	showBio : function ( i ) {
		if ( bios.lastBio !== false ) {
			$(".bio").slice(bios.lastBio,bios.lastBio+1).fadeOut(1000);
		}
		bios.lastBio = i;
		$(".bio").slice(i,i+1).fadeIn(1000);
		return false;
	}
}

var portfolio = {
	max_h : 0,
	max_p_h : 0,
	imgs : Array(),
	imgCount: 0,
	currentImg: 0,
	run : 1,
	runOnce : 0,
	marqueeTop : 0,
	init : function ( ) {
		portfolio.marqueeTop = ($("#marquee").offset().top - 8);
		$("#marquee div").slice(0,1).css("display","block");
		$("#marquee div").slice(1).css("display","none");
		var i = 0;
		$("#marquee img").each(function (i) {
				portfolio.imgCount++;
				portfolio.imgs[i] = new Image();
				$(portfolio.imgs[i]).load(function(){portfolio.counter(-1);});
				portfolio.imgs[i].src = this.src;
				portfolio.max_h = ( this.height > portfolio.max_h ) ? this.height : portfolio.max_h;
			}
		);
		$("#marquee p").each(function (i) {
				portfolio.max_p_h = ( this.height > portfolio.max_p_h ) ? this.height : portfolio.max_p_h;
			}
		);
		if ( $("#marquee").height() < ( portfolio.max_h + portfolio.max_p_h ) ) {
			$("#marquee").height(portfolio.max_h + portfolio.max_p_h);
		}
		if ( $("#marquee").height() < $("#portfolio-slides").height() ) {
			$("#marquee").height($("#portfolio-slides").height())
		}
		$("#thumbs a").each(function(i){
			this.onclick = new Function( "return portfolio.change(" + i + ")" );
		});
		$("#marquee a").each(function(i){
			this.onclick = new Function("this.title=allpages.titleAttr; return true;");
		});
	},
	change : function ( i ) {
		portfolio.run = 0;
		$("#marquee div").slice(portfolio.currentImg,portfolio.currentImg+1).fadeOut(1000);
		if ( ( $(window).scrollTop() > portfolio.marqueeTop ) ) {
			if ( ( $("#marquee").height() + portfolio.marqueeTop ) >= ( $("#marquee div").slice(i,i+1).height() + ($(window).scrollTop() ) ) ) {
				$("#marquee div").slice(i,i+1).css("top",$(window).scrollTop()-portfolio.marqueeTop);
			} else {
				$("#marquee div").slice(i,i+1).css("top", $("#marquee").height()-$("#marquee div").slice(i,i+1).height() );
			}
		} else {
			$("#marquee div").slice(i,i+1).css("top",0);
		}
		$("#marquee div").slice(i,i+1).fadeIn(1000);
		$("#thumbs div").slice(portfolio.currentImg,portfolio.currentImg+1).removeClass("current");
		$("#thumbs div").slice(i,i+1).addClass("current");
		portfolio.currentImg = i;
		return false;
	},
	counter : function ( n ) {
		portfolio.imgCount += n;
		if ( portfolio.imgCount == 0 && portfolio.runOnce == 0 ) {
			portfolio.runOnce = 1;
			setTimeout( "portfolio.slideShow()", 6000 );
			$("#marquee a").lightBox();
		}
	},
	slideShow : function ( ) {
		if ( portfolio.run == 1 ) {
			var last = portfolio.currentImg;
			if ( $("#marquee div").length-1 <= portfolio.currentImg ) {
				portfolio.currentImg = 0;
			} else {
				portfolio.currentImg++;
			}
			$("#marquee div").slice(last,last+1).fadeOut(1000);
			if ( ( $(window).scrollTop() > portfolio.marqueeTop ) ) {
				if ( ( $("#marquee").height() + portfolio.marqueeTop ) >= ( $("#marquee div").slice(portfolio.currentImg,portfolio.currentImg+1).height() + ($(window).scrollTop() ) ) ) {
					$("#marquee div").slice(portfolio.currentImg,portfolio.currentImg+1).css("top",$(window).scrollTop()-portfolio.marqueeTop);
				} else {
					$("#marquee div").slice(portfolio.currentImg,portfolio.currentImg+1).css("top", $("#marquee").height()-$("#marquee div").slice(portfolio.currentImg,portfolio.currentImg+1).height() );
				}
			} else {
				$("#marquee div").slice(portfolio.currentImg,portfolio.currentImg+1).css("top",0);
			}
			$("#marquee div").slice(portfolio.currentImg,portfolio.currentImg+1).fadeIn(1000);
			$("#thumbs div").slice(last,last+1).removeClass("current");
			$("#thumbs div").slice(portfolio.currentImg,portfolio.currentImg+1).addClass("current");
			setTimeout( "portfolio.slideShow()", 6000 );
		}
	}
}

var index = {
	rows : Array(),
	imgs : Array(),
	imgCount : 0,
	nextSlide : function ( i, t ) {
		if ( i >= index.rows.length ) {
			i = 0;
		}
		$(index.rows[((i==0)?(index.rows.length-1):(i-1))]).fadeOut(1000);
		$(index.rows[i]).fadeIn(2000);
		if ( t > 0) {
			setTimeout( "index.nextSlide(" + (++i) + "," + t + ")", t );
		}
	},
	counter : function ( n ) {
		index.imgCount = index.imgCount + n;
		if ( index.imgCount == 0 ) {
			$("#throbber").hide();
			setTimeout( "index.firstWord()", 3000 );
		}
	},
	firstWord : function ( ) {
		$("span.first").fadeIn(1000);
		setTimeout( "index.otherWords()", 2000 );
	},
	otherWords : function ( ) {
		$("span.second").fadeIn(1000);
		setTimeout( "index.startSlides( 0, 6000 )", 6000 );
	},
	startSlides : function ( ) {
		$(".text-overlay").fadeOut(1000);
		index.nextSlide( 1, 6000 );
	}
}


var contactForms = {
	contactCheck : function ( ) {
		var msg = "";
		var fname = document.getElementById("First_Name");
		var lname = document.getElementById("Last_Name");
		var email = document.getElementById("Your_Email");
		var phone = document.getElementById("Your_Phone");
		if ( fname.value == "" ) {
			msg += "Please enter your first name.\n";
		}
		if ( lname.value == "" ) {
			msg += "Please enter your last name.\n";
		}
		if ( email.value == "" ) {
			msg += "Please enter your email address.\n";
		}
		if ( phone.value == "" ) {
			msg += "Please enter your phone number.\n";
		}
		if ( msg ) {
			alert( msg );
			return false;
		}
		return true;
	}
}
