var RecaptchaOptions = {
	theme : 'clean'
}

$(document).ready( function( ) {
	var homeSlides = document.getElementById("index-photos");
	if ( homeSlides ) {
		home.init();
	}

	var portfolioSlides = document.getElementById("portfolio-photos");
	if ( portfolioSlides ) {
		portfolio.init();
	}

	var pressSlides = document.getElementById("press-photos");
	if ( pressSlides ) {
		press.init();
	}

	$("a").hover(function(){
			allpages.titleAttr = $(this).attr("title");
			$(this).attr("title","");
		},
		function(){
			$(this).attr("title",allpages.titleAttr);
		});
});

var allpages = {
	titleAttr : ""
}

var home = {
	s0 : 0,
	s4 : 1,
	s04 : 1,
	s2 : 0,
	s1 : 0,
	s3 : 1,
	s13 : 1,
	img0 : new Array(),
	img1 : new Array(),
	img2 : new Array(),
	count : 0,
	hasRun : false,
	duration : 1500,
	interval : 3000,
	init : function ( ) {
		$("div.s0 img").each( function (i) {
			home.count++;
			home.img0[i] = new Image();
			home.img0[i].src = this.src;
			$(home.img0[i]).load(function(){home.counter();})
			.each(function(){
				if(this.complete || (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6)) 
				$(this).trigger("load");
				});
		});
		$("div.s1 img").each( function (i) {
			home.count++;
			home.img1[i] = new Image();
			home.img1[i].src = this.src;
			$(home.img1[i]).load(function(){home.counter();})
			.each(function(){
				if(this.complete || (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6)) 
				$(this).trigger("load");
				});
		});
		$("div.s2 img").each( function (i) {
			home.count++;
			home.img2[i] = new Image();
			home.img2[i].src = this.src;
			$(home.img2[i]).load(function(){home.counter();})
			.each(function(){
				if(this.complete || (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6)) 
				$(this).trigger("load");
				});
		});
	},
	counter : function ( ) {
		home.count--;
		if ( home.count >= 0 && !home.hasRun ) {
			home.hasRun = true;
			setTimeout( "home.slidesSmall()", home.interval );
			setTimeout( "home.slidesMedium()", home.interval*2 );
			setTimeout( "home.slidesLarge()", home.interval*3 );
		}
		return false;
	},
	slidesSmall : function ( ) {
		if ( home.s04 + 1 >= $("div.s0 img").length ) {
			home.s04 = 0;
		} else {
			home.s04++;
		}
		$("div.s0 img.p" + home.s04).fadeIn(home.duration);
		$("div.s0 img.p" + home.s0).fadeOut(home.duration);
		home.s0 = home.s04;
		if ( home.s04 + 1 >= $("div.s0 img").length ) {
			home.s04 = 0;
		} else {
			home.s04++;
		}
		$("div.s4 img.p" + home.s04).fadeIn(home.duration);
		$("div.s4 img.p" + home.s4).fadeOut(home.duration);
		home.s4 = home.s04;
		setTimeout( "home.slidesSmall()", home.interval*3 );
	},
	slidesMedium : function ( ) {
		if ( home.s13 + 1 >= $("div.s1 img").length ) {
			home.s13 = 0;
		} else {
			home.s13++;
		}
		$("div.s1 img.p" + home.s13).fadeIn(home.duration);
		$("div.s1 img.p" + home.s1).fadeOut(home.duration);
		home.s1 = home.s13;
		if ( home.s13 + 1 >= $("div.s1 img").length ) {
			home.s13 = 0;
		} else {
			home.s13++;
		}
		$("div.s3 img.p" + home.s13).fadeIn(home.duration);
		$("div.s3 img.p" + home.s3).fadeOut(home.duration);
		home.s3 = home.s13;
		setTimeout( "home.slidesMedium()", home.interval*3 );
	},
	slidesLarge : function ( ) {
		if ( home.s2 + 1 >= $("div.s2 img").length ) {
			var nexts2 = 0;
		} else {
			var nexts2 = home.s2 + 1;
		}
		$("div.s2 img.p" + nexts2).fadeIn(home.duration);
		$("div.s2 img.p" + home.s2).fadeOut(home.duration);
		home.s2 = nexts2;
		setTimeout( "home.slidesLarge()", home.interval*3 );
	}
}

var press = {
	lastImage : 0,
	thumbPos : 0,
	init : function () {
		$("#thumbs .n0").addClass("current");
		$("#thumbs a").each(function( i ) {
			this.onclick = new Function ( "return press.show(" + i + ");" );
		});
		$(".prev").click(function(){
			$("#thumbs div").animate({
				left : "+=658px"
			}, 1000, "swing" );
			press.thumbPos += 658;
			$(".next").fadeIn(200);
			if ( press.thumbPos >= 0 ) {
				$(".prev").fadeOut(200);
			}
			return false;
		});
		$(".next").click(function(){
			$("#thumbs div").animate({
				left : "-=658px"
			}, 1000, "swing" );
			press.thumbPos -= 658;
			$(".prev").fadeIn(200);
			var thumbDiv = document.getElementById("thumbs");
			var thumbs = thumbDiv.getElementsByTagName("a");
			if ( ( (thumbs.length * 94) + press.thumbPos ) <= 658 ) {
				$(".next").fadeOut(200);
			}
			return false;
		});
		$(".prev").hide();
	},
	show : function ( i ) {
		var photos = document.getElementById('press-photos');
		var divs = photos.getElementsByTagName('div');
		var thumbs = document.getElementById('thumbs');
		var links = thumbs.getElementsByTagName('a');
		$(divs[i]).fadeIn(1000);
		if ( press.lastImage != i ) {
			$(divs[press.lastImage]).fadeOut(1000);
			$(links[press.lastImage]).removeClass("current");
			$(links[i]).addClass("current");
		}
		press.lastImage = i;
		return false;
	}
}

var portfolio = {
	lastImage : 0,
	thumbPos : 0,
	init : function () {
		$("#thumbs .n0").addClass("current");
		$("#thumbs a").each(function( i ) {
			this.onclick = new Function ( "return portfolio.show(" + i + ");" );
		});
		$(".prev").click(function(){
			$("#thumbs div").animate({
				left : "+=658px"
			}, 1000, "swing" );
			portfolio.thumbPos += 658;
			$(".next").fadeIn(200);
			if ( portfolio.thumbPos >= 0 ) {
				$(".prev").fadeOut(200);
			}
			return false;
		});
		$(".next").click(function(){
			$("#thumbs div").animate({
				left : "-=658px"
			}, 1000, "swing" );
			portfolio.thumbPos -= 658;
			$(".prev").fadeIn(200);
			var thumbDiv = document.getElementById("thumbs");
			var thumbs = thumbDiv.getElementsByTagName("a");
			if ( ( (thumbs.length * 94) + portfolio.thumbPos ) <= 658 ) {
				$(".next").fadeOut(200);
			}
			return false;
		});
		$(".prev").hide();
	},
	show : function ( i ) {
		var photos = document.getElementById('portfolio-photos');
		var divs = photos.getElementsByTagName('div');
		var thumbs = document.getElementById('thumbs');
		var links = thumbs.getElementsByTagName('a');
		$(divs[i]).fadeIn(1000);
		if ( i != portfolio.lastImage ) {
			$(divs[portfolio.lastImage]).fadeOut(1000);
		}
		$(links[portfolio.lastImage]).removeClass("current");
		$(links[i]).addClass("current");
		portfolio.lastImage = i;
		return false;
	}
}

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;
	}
}
